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
14 allow_all_form_action :only => :new
17 referer = safe_referer(params[:referer]) if params[:referer]
19 parse_oauth_referer referer
23 session[:remember_me] ||= params[:remember_me]
25 referer = safe_referer(params[:referer]) if params[:referer]
27 password_authentication(params[:username].strip, params[:password], referer)
34 session.delete(:pending_user)
36 session_expires_automatically
38 referer = safe_referer(params[:referer]) if params[:referer]
40 redirect_to referer || { :controller => "site", :action => "index" }
47 # handle password authentication
48 def password_authentication(username, password, referer = nil)
49 if (user = User.authenticate(:username => username, :password => password))
50 successful_login(user, referer)
51 elsif (user = User.authenticate(:username => username, :password => password, :pending => true))
52 unconfirmed_login(user, referer)
53 elsif User.authenticate(:username => username, :password => password, :suspended => true)
54 failed_login({ :partial => "sessions/suspended_flash" }, username, referer)
56 failed_login(t("sessions.new.auth failure"), username, referer)