- flash[:error] = t("users.auth_failure." + params[:message])
- redirect_to params[:origin] || login_url
- end
-
- private
-
- ##
- # handle password authentication
- def password_authentication(username, password)
- if user = User.authenticate(:username => username, :password => password)
- successful_login(user)
- elsif user = User.authenticate(:username => username, :password => password, :pending => true)
- unconfirmed_login(user)
- elsif User.authenticate(:username => username, :password => password, :suspended => true)
- failed_login t("users.login.account is suspended", :webmaster => "mailto:#{Settings.support_email}").html_safe, username
- else
- failed_login t("users.login.auth failure"), username
- end
- end
-
- ##
- # return the URL to use for authentication
- def auth_url(provider, uid, referer = nil)
- params = { :provider => provider }
-
- params[:openid_url] = openid_expand_url(uid) if provider == "openid"
-
- if referer.nil?
- params[:origin] = request.path
- else
- params[:origin] = request.path + "?referer=" + CGI.escape(referer)
- params[:referer] = referer
- end
-
- auth_path(params)
- end
-
- ##
- # special case some common OpenID providers by applying heuristics to
- # try and come up with the correct URL based on what the user entered
- def openid_expand_url(openid_url)
- if openid_url.nil?
- nil
- elsif openid_url.match(%r{(.*)gmail.com(/?)$}) || openid_url.match(%r{(.*)googlemail.com(/?)$})
- # Special case gmail.com as it is potentially a popular OpenID
- # provider and, unlike yahoo.com, where it works automatically, Google
- # have hidden their OpenID endpoint somewhere obscure this making it
- # somewhat less user friendly.
- "https://www.google.com/accounts/o8/id"
- else
- openid_url
- end
- end