app/controllers/tramway/auth/web/sessions_controller.rb in tramway-auth-2.0.1 vs app/controllers/tramway/auth/web/sessions_controller.rb in tramway-auth-2.0.2

- old
+ new

@@ -5,15 +5,19 @@ class SessionsController < ::Tramway::Auth::Web::ApplicationController before_action :redirect_if_signed_in, except: :destroy def create @session_form = ::Tramway::Auth::SessionForm.new params[:model].constantize.active.find_by email: params[:user][:email] - if @session_form.validate params[:user] - sign_in @session_form.model - redirect_to [params[:success_redirect], '?', { flash: :success_user_sign_in }.to_query].join || ::Tramway::Auth.root_path_for(@session_form.model.class) + if @session_form.model.present? + if @session_form.validate params[:user] + sign_in @session_form.model + redirect_to [params[:success_redirect], '?', { flash: :success_user_sign_in }.to_query].join || ::Tramway::Auth.root_path_for(@session_form.model.class) + else + redirect_to [params[:error_redirect], '?', { flash: :error_user_sign_in }.to_query].join || ::Tramway::Auth.root_path_for(@session_form.model.class) + end else - redirect_to [params[:error_redirect], '?', { flash: :error_user_sign_in }.to_query].join || ::Tramway::Auth.root_path_for(@session_form.model.class) + redirect_to [params[:error_redirect], '?', { flash: :error_user_sign_in }.to_query].join || ::Tramway::Auth.root_path_for(params[:model].constantize) end end def destroy root_path = ::Tramway::Auth.root_path_for(current_user.class) @@ -22,10 +26,12 @@ end private def redirect_if_signed_in - redirect_to ::Tramway::Auth.root_path_for(current_user.class) if params[:model].present? && signed_in?(params[:model].constantize) && request.env['PATH_INFO'] != ::Tramway::Auth.root_path_for(current_user.class) + if params[:model].present? && signed_in?(params[:model].constantize) && request.env['PATH_INFO'] != ::Tramway::Auth.root_path_for(current_user.class) + redirect_to ::Tramway::Auth.root_path_for(current_user.class) + end end end end end