* VRFS-88 api/login done

This commit is contained in:
Seth Call 2012-11-13 23:57:10 -06:00
parent 2d856351d7
commit 0d3334a3b0
3 changed files with 27 additions and 24 deletions

View File

@ -5,13 +5,14 @@ class SessionsController < ApplicationController
end
def create
user = User.find_by_email(params[:session][:email])
if user && user.authenticate(params[:session][:password])
sign_in user
redirect_back_or music_sessions_url
else
user = User.authenticate(params[:session][:email], params[:session][:password])
if user.nil?
flash.now[:error] = 'Invalid email/password combination'
render 'new'
else
sign_in user
redirect_back_or music_sessions_url
end
end

View File

@ -19,15 +19,17 @@ class UsersController < ApplicationController
def create
@user = User.new
# check recaptcha; if any errors seen, contribute it to the model
unless verify_recaptcha(:model => @user, :message => "recaptcha")
# let the template render errors on the user model
render 'new'
else
# sends email to email account for confirmation
@user = User.signup(params[:jam_ruby_user][:name],
return
end
@user = UserManager.new.signup(params[:jam_ruby_user][:name],
params[:jam_ruby_user][:email],
params[:jam_ruby_user][:password],
params[:jam_ruby_user][:password_confirmation],
@ -37,16 +39,14 @@ class UsersController < ApplicationController
params[:jam_ruby_user][:instruments],
ApplicationHelper.base_uri(request) + "/confirm")
# check for errors
if @user.errors.any?
# render any @user.errors on error
render 'new'
else
# if success, redirect to 'email_sent' page
flash[:success] = "Please check your email and confirm your signup"
redirect_to :email_sent
end
# check for errors
if @user.errors.any?
# render any @user.errors on error
render 'new'
else
# if success, redirect to 'email_sent' page
flash[:success] = "Please check your email and confirm your signup"
redirect_to :email_sent
end
end
@ -55,7 +55,7 @@ class UsersController < ApplicationController
end
def signup_confirm
@user = UserManager.signup_confirm(params[:signup_token])
@user = UserManager.new.signup_confirm(params[:signup_token])
unless @user.nil? || @user.errors.any?
sign_in @user

View File

@ -13,16 +13,18 @@ class UserManager < BaseManager
@user = User.new
# TODO: figure out why can't user verify_recaptcha here
# check recaptcha; if any errors seen, contribute it to the model
unless verify_recaptcha(:model => @user, :message => "recaptcha")
return @user # @user.errors.any? is true now
else
#unless verify_recaptcha(:model => @user, :message => "recaptcha")
# return @user # @user.errors.any? is true now
#else
# sends email to email account for confirmation
@user = User.signup(name, email, password, password_confirmation,
city, state, country, instruments, signup_confirm_url)
return @user
end
#end
end
def signup_confirm(signup_token)