tabletop-companion/app/controllers/sessions_controller.rb

34 lines
826 B
Ruby
Raw Normal View History

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],
)
2024-06-19 15:42:15 +00:00
if Current.user && Current.user.verified?
2024-04-21 14:01:10 +00:00
session[:user_id] = Current.user.id
flash[:notice] = t(".success", name: Current.user.first_name)
redirect_to :root
2024-06-19 15:42:15 +00:00
elsif !Current.user.verified?
flash[:alert] = t(".not_verified")
render :new, status: :unprocessable_entity
2024-04-21 14:01:10 +00:00
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