# encoding: utf-8
class Metro < Sinatra::Base
	get "/admin/add_client" do
		admin!
		
		@users = []
		User.all.each { |x| @users << x[:username]}

		haml :add_client
	end

	post "/admin/add_client" do
		admin!
		begin
			uid = User.first(username: params['user'])
			Client.create(user_id: uid[:id], vpn_address: params['vpn_address'], name: params['name'], vat: params['vat'], land_phone: params['land_phone'], mobile_phone: params['mobile_phone'], email: params['email'], address: params['address'], city: params['city'], country: params['country'], not_paid: params['not_paid'], created_at: Time.now, contract: params['contract'] )
			redirect '/admin'
		rescue => e
			p e.message
		end
	end
end
