Class: Maquina::SessionsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/maquina/sessions_controller.rb

Instance Method Summary collapse

Methods included from Authenticate

#after_authentication_url, #authenticated?, #current_user, #require_authentication

Instance Method Details

#createObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/maquina/sessions_controller.rb', line 15

def create
  reset_session

  @user = Maquina::User.authenticate_by(email: params.dig(:email), password: params.dig(:password))

  if @user.present?
    active_session = start_new_session_for(@user)
    if active_session.present?
      return redirect_to(calculate_redirect_path(active_session), notice: t("flash.sessions.create.notice"), status: :see_other)
    end
  end

  @user = Maquina::User.new(email: params.dig(:email))
  flash.now.alert = t("flash.sessions.create.alert")
  render :new, status: :unprocessable_entity
end

#destroyObject



32
33
34
35
36
37
38
# File 'app/controllers/maquina/sessions_controller.rb', line 32

def destroy
  reset_session
  Maquina::Current.reset

  flash.notice = t("flash.sessions.destroy.notice")
  redirect_to main_app., status: :see_other
end

#newObject



11
12
13
# File 'app/controllers/maquina/sessions_controller.rb', line 11

def new
  @user = Maquina::User.new
end