summaryrefslogtreecommitdiff
path: root/app/controllers/admin/sessions_controller.rb
blob: 1f946e4199579d8ad8c55ed3b6d99457c27e9fcc (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
# frozen_string_literal: true

class Admin::SessionsController < ApplicationController
  include InternalRedirect

  before_action :user_is_admin!

  def new
    # Renders a form in which the admin can enter their password
  end

  def create
    if current_user_mode.enable_admin_mode!(password: params[:password])
      redirect_location = stored_location_for(:redirect) || admin_root_path
      redirect_to safe_redirect_path(redirect_location)
    else
      flash.now[:alert] = _('Invalid Login or password')
      render :new
    end
  end

  def destroy
    current_user_mode.disable_admin_mode!

    redirect_to root_path, status: :found, notice: _('Admin mode disabled')
  end

  private

  def user_is_admin!
    render_404 unless current_user&.admin?
  end
end