- required = [:nickname, :email, "http://axschema.org/namePerson/friendly", "http://axschema.org/contact/email"]
- end
-
- # Start the authentication
- authenticate_with_open_id(openid_expand_url(openid_url), :method => :get, :required => required) do |result, identity_url, sreg, ax|
- if result.successful?
- # We need to use the openid url passed back from the OpenID provider
- # rather than the one supplied by the user, as these can be different.
- #
- # For example, you can simply enter yahoo.com in the login box rather
- # than a user specific url. Only once it comes back from the provider
- # provider do we know the unique address for the user.
- if user = User.find_by_openid_url(identity_url)
- case user.status
- when "pending" then
- unconfirmed_login(user)
- when "active", "confirmed" then
- successful_login(user)
- when "suspended" then
- failed_login t('user.login.account is suspended', :webmaster => "mailto:webmaster@openstreetmap.org")
- else
- failed_login t('user.login.auth failure')
- end
- else
- # Guard against not getting any extension data
- sreg = {} if sreg.nil?
- ax = {} if ax.nil?
-
- # We don't have a user registered to this OpenID, so redirect
- # to the create account page with username and email filled
- # in if they have been given by the OpenID provider through
- # the simple registration protocol.
- nickname = sreg["nickname"] || ax["http://axschema.org/namePerson/friendly"].first
- email = sreg["email"] || ax["http://axschema.org/contact/email"].first
-
- redirect_to :controller => 'user', :action => 'new', :nickname => nickname, :email => email, :openid => identity_url
- end
- elsif result.missing?
- failed_login t('user.login.openid missing provider')
- elsif result.invalid?
- failed_login t('user.login.openid invalid')
- else
- failed_login t('user.login.auth failure')
- end
- end
- end
-
- ##
- # verify an OpenID URL
- def openid_verify(openid_url, user)
- user.openid_url = openid_url
-
- authenticate_with_open_id(openid_expand_url(openid_url), :method => :get, :required => [:email, "http://axschema.org/contact/email"]) do |result, identity_url, sreg, ax|
- if result.successful?
- # Do we trust the emails this provider returns?
- if openid_email_verified(identity_url)
- # Guard against not getting any extension data
- sreg = {} if sreg.nil?
- ax = {} if ax.nil?
-
- # Get the verified email
- verified_email = sreg["email"] || ax["http://axschema.org/contact/email"].first
- end
-
- # We need to use the openid url passed back from the OpenID provider
- # rather than the one supplied by the user, as these can be different.
- #
- # For example, you can simply enter yahoo.com in the login box rather
- # than a user specific url. Only once it comes back from the provider
- # provider do we know the unique address for the user.
- user.openid_url = identity_url
- yield user, verified_email
- elsif result.missing?
- flash.now[:error] = t 'user.login.openid missing provider'
- elsif result.invalid?
- flash.now[:error] = t 'user.login.openid invalid'
- else
- flash.now[:error] = t 'user.login.auth failure'
- end