summaryrefslogtreecommitdiff
path: root/app/controllers/sessions_controller.rb
blob: 3dc076b1577c3d46c1a4aa850ca36899ad2a99da (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
29
30
31
32
33
34
35
36
37
38
39
class SessionsController < ApplicationController
  allow_unauthenticated_access only: %i[ new create accept_cookies gift_nico ]
  rate_limit to: 10, within: 3.minutes, only: :create, with: -> { redirect_to new_session_url, alert: "Try again later." }

  def new
  end

  def create
    if user = User.authenticate_by(params.permit(:email_address, :password))
      start_new_session_for user
      if user.admin
        session[:admin] = true
      end
      redirect_to after_authentication_url
    else
      redirect_to new_session_path, alert: "Try another email address or password."
    end
  end

  def destroy
    terminate_session
    redirect_to new_session_path
  end

  def dismiss_banner
    session[:dismissed_banner] = true
    redirect_to root_path
  end

  def accept_cookies
    session[:dismissed_banner] = true
    redirect_to root_path
  end

  def gift_nico
    session[:dismissed_banner] = true
    redirect_to root_path
  end
end
Copyright 2019--2025 Marius PETER