Class: LeanCms::SessionsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/lean_cms/sessions_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/lean_cms/sessions_controller.rb', line 12

def create
  user_class = LeanCms.user_class.constantize

  if user = user_class.authenticate_by(params.permit(:email_address, :password))
    unless user.active?
      redirect_to lean_cms_new_session_path, alert: "Your account has been deactivated. Please contact an administrator."
      return
    end

    start_new_session_for user
    user.record_login!

    if user.must_change_password?
      magic_link = LeanCms::MagicLink.create_for_password_reset(user)
      redirect_to lean_cms_password_setup_path(token: magic_link.token), notice: "Please set a new password."
    else
      redirect_to after_authentication_url
    end
  else
    redirect_to lean_cms_new_session_path, alert: "Try another email address or password."
  end
end

#destroyObject



35
36
37
38
# File 'app/controllers/lean_cms/sessions_controller.rb', line 35

def destroy
  terminate_session
  redirect_to lean_cms_new_session_path, status: :see_other
end

#newObject



8
9
10
# File 'app/controllers/lean_cms/sessions_controller.rb', line 8

def new
  redirect_to after_authentication_url if authenticated?
end