diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index ed322ba..782c5c9 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -1,4 +1,8 @@ class UserController < ApplicationController + + @@invite_salt = 'Gouranga gives a fuck?!' + @@email_regex = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/ + def login @hide_player = 1 unless params[:email].nil? or params[:password].nil? @@ -28,7 +32,7 @@ class UserController < ApplicationController @hide_player = 1 data = Invite.where(:email => params[:invite_email], :code => params[:invite_code]).first unless data.nil? - if params[:email].match(/\A[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}\z/).nil? or + if params[:email].match(@@email_regex).nil? or params[:password].length < 6 or params[:password] != params[:password_c] redirect_to '/' @@ -63,4 +67,26 @@ class UserController < ApplicationController render :json => 'wtf?' end end + + def invite + @data = User.collection.find({session_key: Digest::SHA256.hexdigest(request.session['session_id'])}).first + unless @data.nil? + if @data.invites > 0 + pp 1 + if request.request_method == 'POST' + unless params[:email].nil? + if params[:email].match(@@email_regex) + Invite.collection.insert({email: params[:email], code: Digest::SHA256.hexdigest(params[:email] << @@invite_salt), referer: @data._id}) + @data.invites -= 1 + User.collection.update({_id: @data._id}, @data.attributes) + @ok = true + end + end + end + pp 2 + else + render :json => 'wtf?' + end + end + end end diff --git a/app/views/user/invite.erb b/app/views/user/invite.erb new file mode 100644 index 0000000..2ad90a3 --- /dev/null +++ b/app/views/user/invite.erb @@ -0,0 +1,23 @@ +