2024-02-02 09:05:04 -06:00
|
|
|
class SessionsController < ApplicationController
|
2024-10-03 14:42:22 -04:00
|
|
|
before_action :set_session, only: :destroy
|
2024-04-03 10:35:55 -04:00
|
|
|
skip_authentication only: %i[new create]
|
|
|
|
|
2024-02-02 09:05:04 -06:00
|
|
|
layout "auth"
|
2024-02-02 16:06:55 +00:00
|
|
|
|
2024-02-02 09:05:04 -06:00
|
|
|
def new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
if user = User.authenticate_by(email: params[:email], password: params[:password])
|
2025-02-06 14:16:53 -06:00
|
|
|
if user.otp_required?
|
|
|
|
session[:mfa_user_id] = user.id
|
|
|
|
redirect_to verify_mfa_path
|
|
|
|
else
|
|
|
|
@session = create_session_for(user)
|
|
|
|
redirect_to root_path
|
|
|
|
end
|
2024-02-02 09:05:04 -06:00
|
|
|
else
|
2024-02-03 14:17:49 -06:00
|
|
|
flash.now[:alert] = t(".invalid_credentials")
|
2024-02-02 09:05:04 -06:00
|
|
|
render :new, status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
end
|
2024-02-02 16:06:55 +00:00
|
|
|
|
2024-02-02 09:05:04 -06:00
|
|
|
def destroy
|
2024-10-03 14:42:22 -04:00
|
|
|
@session.destroy
|
2024-10-23 11:20:55 -04:00
|
|
|
redirect_to new_session_path, notice: t(".logout_successful")
|
2024-02-02 09:05:04 -06:00
|
|
|
end
|
2024-10-03 14:42:22 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
def set_session
|
|
|
|
@session = Current.user.sessions.find(params[:id])
|
|
|
|
end
|
2024-02-02 09:05:04 -06:00
|
|
|
end
|