Class: Tramway::Auth::Web::SessionsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/tramway/auth/web/sessions_controller.rb

Instance Method Summary collapse

Methods included from Tramway::AuthManagement

#authenticate_user!, #current_user, #sign_in, #sign_out, #signed_in?

Methods inherited from ApplicationController

#application

Instance Method Details

#createObject



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/tramway/auth/web/sessions_controller.rb', line 8

def create
  @session_form = ::Tramway::Auth::SessionForm.new params[:model].constantize.active.find_by email: params[:user][:email]
  if @session_form.model.present?
    if @session_form.validate params[:user]
       @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(params[:model].constantize)
  end
end

#destroyObject



22
23
24
25
26
# File 'app/controllers/tramway/auth/web/sessions_controller.rb', line 22

def destroy
  root_path = ::Tramway::Auth.root_path_for(current_user.class)
  sign_out params[:model]
  redirect_to params[:redirect] || root_path
end