1 class SessionsController < ApplicationController
6 before_action :disable_terms_redirect, :only => [:destroy]
7 before_action :require_cookies, :only => [:new]
9 authorize_resource :class => false
12 append_content_security_policy_directives(
16 session[:referer] = safe_referer(params[:referer]) if params[:referer]
20 session[:remember_me] ||= params[:remember_me]
21 session[:referer] = safe_referer(params[:referer]) if params[:referer]
22 password_authentication(params[:username], params[:password])
26 @title = t "sessions.destroy.title"
30 token = UserToken.find_by(:token => session[:token])
32 session.delete(:token)
35 session_expires_automatically
37 redirect_to safe_referer(params[:referer])
39 redirect_to :controller => "site", :action => "index"
47 # handle password authentication
48 def password_authentication(username, password)
49 if (user = User.authenticate(:username => username, :password => password))
50 successful_login(user)
51 elsif (user = User.authenticate(:username => username, :password => password, :pending => true))
52 unconfirmed_login(user)
53 elsif User.authenticate(:username => username, :password => password, :suspended => true)
54 failed_login t("sessions.new.account is suspended", :webmaster => "mailto:#{Settings.support_email}").html_safe, username
56 failed_login t("sessions.new.auth failure"), username