2023-08-15 13:50:39 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class SessionsController < ApplicationController
|
|
|
|
def new; end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@user = User.find_by(username: params[:username])
|
|
|
|
|
|
|
|
if @user.present? && @user.authenticate(params[:password])
|
|
|
|
session[:user_id] = @user.id
|
|
|
|
redirect_to @user, notice: t(".logged_in")
|
|
|
|
else
|
2023-08-18 16:35:16 +00:00
|
|
|
redirect_to root_path, alert: t(".login_fail")
|
2023-08-15 13:50:39 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy_session
|
|
|
|
reset_session
|
|
|
|
redirect_to root_path, notice: t(".logged_out")
|
|
|
|
end
|
|
|
|
end
|