Added authentication_zero

This commit is contained in:
2024-08-26 19:20:06 +02:00
parent 70606f6890
commit e23b41b950
48 changed files with 1047 additions and 73 deletions

View File

@@ -0,0 +1,32 @@
class SessionsController < ApplicationController
skip_before_action :authenticate_user!, 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