2024-05-26 10:45:10 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-04-21 14:01:10 +00:00
|
|
|
class SessionsController < ApplicationController
|
|
|
|
skip_before_action :authenticate, only: [ :new, :create ]
|
|
|
|
|
|
|
|
def new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
Current.user = User.authenticate_by(
|
|
|
|
username: params[:username],
|
|
|
|
password: params[:password],
|
|
|
|
)
|
|
|
|
if Current.user
|
|
|
|
session[:user_id] = Current.user.id
|
|
|
|
flash[:notice] = t(".success", name: Current.user.first_name)
|
|
|
|
redirect_to :root
|
|
|
|
else
|
|
|
|
flash[:alert] = t(".error")
|
|
|
|
render :new, status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
reset_session
|
|
|
|
Current.user = nil
|
|
|
|
flash[:notice] = t(".success")
|
|
|
|
redirect_to login_path
|
|
|
|
end
|
|
|
|
end
|