Include autenticazione, progetti isolati, mail marketing HTML con SMTP, test A/B e editor WYSIWYG. Co-authored-by: Cursor <cursoragent@cursor.com>
44 lines
1.1 KiB
Ruby
44 lines
1.1 KiB
Ruby
class SessionsController < ApplicationController
|
|
skip_before_action :require_login, only: %i[new create]
|
|
skip_before_action :set_current_project, only: %i[new create], raise: false
|
|
|
|
def new
|
|
redirect_to after_login_path if logged_in?
|
|
end
|
|
|
|
def create
|
|
user = User.active.find_by(email: params[:email].to_s.downcase.strip)
|
|
|
|
if user&.authenticate(params[:password])
|
|
login_as(user)
|
|
redirect_to after_login_path, notice: "Bentornato, #{user.first_name}!"
|
|
else
|
|
flash.now[:alert] = "Email o password non validi."
|
|
render :new, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
logout
|
|
redirect_to login_path, notice: "Disconnesso correttamente."
|
|
end
|
|
|
|
private
|
|
|
|
def after_login_path
|
|
projects = if current_user.admin?
|
|
Project.active.ordered
|
|
else
|
|
current_user.accessible_projects
|
|
end
|
|
|
|
if projects.one?
|
|
project_root_path(project_code: projects.first.code)
|
|
elsif (code = session[:last_project_code]) && projects.exists?(code: code)
|
|
project_root_path(project_code: code)
|
|
else
|
|
root_path
|
|
end
|
|
end
|
|
end
|