diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 61f5c8078..4da64de94 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -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 diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 3841bbe2e..4666aee45 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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 diff --git a/lib/managers/user_manager.rb b/lib/managers/user_manager.rb index e84e22f40..97c034150 100644 --- a/lib/managers/user_manager.rb +++ b/lib/managers/user_manager.rb @@ -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)