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] = openid_expand_url(uid) if provider == "openid"
14 params[:origin] = request.path
16 params[:origin] = "#{request.path}?referer=#{CGI.escape(referer)}"
17 params[:referer] = referer
24 # special case some common OpenID providers by applying heuristics to
25 # try and come up with the correct URL based on what the user entered
26 def openid_expand_url(openid_url)
29 elsif openid_url.match(%r{(.*)gmail.com(/?)$}) || openid_url.match(%r{(.*)googlemail.com(/?)$})
30 # Special case gmail.com as it is potentially a popular OpenID
31 # provider and, unlike yahoo.com, where it works automatically, Google
32 # have hidden their OpenID endpoint somewhere obscure this making it
33 # somewhat less user friendly.
34 "https://www.google.com/accounts/o8/id"
41 # process a successful login
42 def successful_login(user, referer = nil)
43 session[:user] = user.id
44 session[:fingerprint] = user.fingerprint
45 session_expires_after 28.days if session[:remember_me]
47 target = referer || session[:referer] || url_for(:controller => :site, :action => :index)
49 # The user is logged in, so decide where to send them:
51 # - If they haven't seen the contributor terms, send them there.
52 # - If they have a block on them, show them that.
53 # - If they were referred to the login, send them back there.
54 # - Otherwise, send them to the home page.
56 redirect_to :controller => :users, :action => :terms, :referer => target
57 elsif user.blocked_on_view
58 redirect_to user.blocked_on_view, :referer => target
63 session.delete(:remember_me)
64 session.delete(:referer)
68 # process a failed login
69 def failed_login(message, username = nil)
70 flash[:error] = message
72 redirect_to :action => "new", :referer => session[:referer],
73 :username => username, :remember_me => session[:remember_me]
75 session.delete(:remember_me)
76 session.delete(:referer)
81 def unconfirmed_login(user)
82 session[:token] = user.tokens.create.token
84 redirect_to :controller => "confirmations", :action => "confirm", :display_name => user.display_name
86 session.delete(:remember_me)
87 session.delete(:referer)
92 def disable_terms_redirect
93 # this is necessary otherwise going to the user terms page, when
94 # having not agreed already would cause an infinite redirect loop.
95 # it's .now so that this doesn't propagate to other pages.
96 flash.now[:skip_terms] = true