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 append_content_security_policy_directives(
19 session[:referer] = safe_referer(params[:referer]) if params[:referer]
23 session[:remember_me] ||= params[:remember_me]
24 session[:referer] = safe_referer(params[:referer]) if params[:referer]
25 password_authentication(params[:username], params[:password])
29 @title = t "sessions.destroy.title"
33 token = UserToken.find_by(:token => session[:token])
35 session.delete(:token)
38 session_expires_automatically
40 redirect_to safe_referer(params[:referer])
42 redirect_to :controller => "site", :action => "index"
50 # handle password authentication
51 def password_authentication(username, password)
52 if (user = User.authenticate(:username => username, :password => password))
53 successful_login(user)
54 elsif (user = User.authenticate(:username => username, :password => password, :pending => true))
55 unconfirmed_login(user)
56 elsif User.authenticate(:username => username, :password => password, :suspended => true)
57 failed_login t("sessions.new.account is suspended", :webmaster => "mailto:#{Settings.support_email}").html_safe, username
59 failed_login t("sessions.new.auth failure"), username