1 class SessionsController < ApplicationController
6 before_action :disable_terms_redirect, :only => [:destroy]
7 before_action :authorize_web
8 before_action :set_locale
9 before_action :check_database_readable
10 before_action :require_cookies, :only => [:new]
12 authorize_resource :class => false
15 override_content_security_policy_directives(:form_action => []) if Settings.csp_enforce || Settings.key?(:csp_report_url)
17 session[:referer] = safe_referer(params[:referer]) if params[:referer]
21 session[:remember_me] ||= params[:remember_me]
22 session[:referer] = safe_referer(params[:referer]) if params[:referer]
23 password_authentication(params[:username].strip, params[:password])
31 token = UserToken.find_by(:token => session[:token])
33 session.delete(:token)
37 session_expires_automatically
39 referer = safe_referer(params[:referer]) if params[:referer]
41 redirect_to referer || { :controller => "site", :action => "index" }
48 # handle password authentication
49 def password_authentication(username, password)
50 if (user = User.authenticate(:username => username, :password => password))
51 successful_login(user)
52 elsif (user = User.authenticate(:username => username, :password => password, :pending => true))
53 unconfirmed_login(user)
54 elsif User.authenticate(:username => username, :password => password, :suspended => true)
55 failed_login({ :partial => "sessions/suspended_flash" }, username)
57 failed_login t("sessions.new.auth failure"), username