Files
vms/app/controllers/sessions_controller.rb
David Böhm c4b96a43e4
Some checks are pending
CI / scan_ruby (push) Waiting to run
CI / scan_js (push) Waiting to run
CI / lint (push) Waiting to run
CI / test (push) Waiting to run
Installed authentication-zero
2024-08-17 21:18:23 +02:00

33 lines
886 B
Ruby

class SessionsController < ApplicationController
skip_before_action :authenticate, only: %i[ new create ]
before_action :set_session, only: :destroy
def index
@sessions = Current.user.sessions.order(created_at: :desc)
end
def new
end
def create
if user = User.authenticate_by(email: params[:email], password: params[:password])
@session = user.sessions.create!
cookies.signed.permanent[:session_token] = { value: @session.id, httponly: true }
redirect_to root_path, notice: "Signed in successfully"
else
redirect_to sign_in_path(email_hint: params[:email]), alert: "That email or password is incorrect"
end
end
def destroy
@session.destroy; redirect_to(sessions_path, notice: "That session has been logged out")
end
private
def set_session
@session = Current.user.sessions.find(params[:id])
end
end