summaryrefslogtreecommitdiff
path: root/app/controllers/sessions_controller.rb
blob: 19978bd2fd21a996a03101897deb738c746da81b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class SessionsController < ApplicationController
  skip_before_action :ensure_valid_session, only: [:new, :create]
  layout 'public'

  def initialize(login_command = resolve(:login_command))
    @login_command = login_command
    super()
  end

  def new
  end

  def create
    if user_session = @login_command.run(self)
      cookies.signed[:raphael] = user_session
      redirect_to root_path(anchor: '')
    else
      flash[:error] = I18n.translate(:invalid_credentials)
      render :new
    end
  end

  def destroy
    reset_session
    cookies.delete(:raphael)
    redirect_to new_session_path
  end
end