2 extend ActiveSupport::Concern
7 # return the URL to use for authentication
8 def auth_url(provider, uid, referer = nil)
9 params = { :provider => provider }
11 params[:openid_url] = uid if provider == "openid"
14 params[:origin] = request.path
16 params[:origin] = "#{request.path}?referer=#{CGI.escape(referer)}"
17 params[:referer] = referer
24 # process a successful login
25 def successful_login(user, referer = nil)
26 session[:user] = user.id
27 session[:fingerprint] = user.fingerprint
28 session_expires_after 28.days if session[:remember_me]
30 target = referer || session[:referer] || url_for(:controller => :site, :action => :index)
32 # The user is logged in, so decide where to send them:
34 # - If they haven't seen the contributor terms, send them there.
35 # - If they have a block on them, show them that.
36 # - If they were referred to the login, send them back there.
37 # - Otherwise, send them to the home page.
39 redirect_to :controller => :users, :action => :terms, :referer => target
40 elsif user.blocked_on_view
41 redirect_to user.blocked_on_view, :referer => target
46 session.delete(:remember_me)
47 session.delete(:referer)
51 # process a failed login
52 def failed_login(message, username = nil)
53 flash[:error] = message
55 redirect_to :controller => "sessions", :action => "new", :referer => session[:referer],
56 :username => username, :remember_me => session[:remember_me]
58 session.delete(:remember_me)
59 session.delete(:referer)
64 def unconfirmed_login(user)
65 session[:token] = user.tokens.create.token
67 redirect_to :controller => "confirmations", :action => "confirm", :display_name => user.display_name
69 session.delete(:remember_me)
70 session.delete(:referer)
75 def disable_terms_redirect
76 # this is necessary otherwise going to the user terms page, when
77 # having not agreed already would cause an infinite redirect loop.
78 # it's .now so that this doesn't propagate to other pages.
79 flash.now[:skip_terms] = true