class UserController < ApplicationController def login @hide_player = 1 unless params[:email].nil? or params[:password].nil? user_data = User.collection.find({email: params[:email], password: Digest::SHA256.hexdigest(params[:password])}).first unless user_data.nil? user_data['session_key'] = Digest::SHA256.hexdigest(request.session['session_id']) User.collection.update({_id: user_data._id}, user_data.attributes) redirect_to '/' else redirect_to '/login' end end end def register @hide_player = 1 data = Invite.where(:email => params[:email], :code => params[:code]).first unless data.nil? @code = data.code @email = data.email else redirect_to '/login' end end def complete @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 params[:password].length < 6 or params[:password] != params[:password_c] redirect_to '/' end User.collection.insert({ email: params[:email], password: Digest::SHA256.hexdigest(params[:password]), name: '', regdate: Time.now(), referer: data.referer, lastvisit: Time.now(), invites: 0 }) Invite.collection.remove({email: params[:invite_email], code: params[:invite_code]}) else redirect_to '/login' end end def update @data = User.collection.find({session_key: Digest::SHA256.hexdigest(request.session['session_id'])}).first unless @data.nil? else render :json => 'wtf?' end end end