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

- old
+ new

@@ -3,33 +3,29 @@ module Tramway::Auth module Web class SessionsController < ::Tramway::Auth::Web::ApplicationController before_action :redirect_if_signed_in, except: :destroy - def new - @application = Tramway::Core.application&.model_class&.first || Tramway::Core.application - @session_form = ::Tramway::Auth::SessionForm.new ::Tramway::User::User.new - end - def create - @session_form = ::Tramway::Auth::SessionForm.new ::Tramway::User::User.active.find_or_initialize_by email: params[:user][:email] + @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 ::Tramway::Auth.root_path + redirect_to [params[:success_redirect], '?', { flash: :success_user_sign_in }.to_query].join || ::Tramway::Auth.root_path_for(@session_form.model.class) else - render :new + redirect_to [params[:error_redirect], '?', { flash: :error_user_sign_in }.to_query].join || ::Tramway::Auth.root_path_for(@session_form.model.class) end end def destroy - sign_out - redirect_to ::Tramway::Auth.root_path + root_path = ::Tramway::Auth.root_path_for(current_user.class) + sign_out params[:model] + redirect_to params[:redirect] || root_path end private def redirect_if_signed_in - redirect_to ::Tramway::Auth.root_path if signed_in? && request.env['PATH_INFO'] != ::Tramway::Auth.root_path + 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) end end end end