2022-01-22 18:17:44 +01:00
|
|
|
class SessionsController < ApplicationController
|
2022-01-26 18:43:30 +01:00
|
|
|
layout "anonymous"
|
|
|
|
|
2022-01-25 23:31:08 +01:00
|
|
|
before_action :redirect_if_authenticated, only: [:create, :new]
|
|
|
|
before_action :authenticate_user!, only: [:destroy]
|
|
|
|
|
|
|
|
def create
|
|
|
|
@user = User.authenticate_by(email: params[:user][:email].downcase, password: params[:user][:password])
|
|
|
|
if @user
|
|
|
|
if @user.unconfirmed?
|
|
|
|
redirect_to new_confirmation_path, alert: "Incorrect email or password."
|
2022-01-22 18:17:44 +01:00
|
|
|
else
|
2022-01-25 23:31:08 +01:00
|
|
|
after_login_path = session[:user_return_to] || root_path
|
|
|
|
login @user
|
|
|
|
remember(@user) if params[:user][:remember_me] == "1"
|
|
|
|
redirect_to after_login_path, notice: "Signed in."
|
2022-01-22 18:17:44 +01:00
|
|
|
end
|
2022-01-25 23:31:08 +01:00
|
|
|
else
|
|
|
|
flash.now[:alert] = "Incorrect email or password."
|
|
|
|
render :new, status: :unprocessable_entity
|
2022-01-22 18:17:44 +01:00
|
|
|
end
|
|
|
|
end
|
2022-01-25 23:31:08 +01:00
|
|
|
|
|
|
|
def destroy
|
|
|
|
forget(current_user)
|
|
|
|
logout
|
|
|
|
redirect_to root_path, notice: "Signed out."
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
end
|
2023-02-26 15:09:08 +01:00
|
|
|
end
|