- # 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
- failed_login t('user.login.account not active', :reconfirm => url_for(:action => 'confirm_resend', :display_name => user.display_name))
- 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 = Hash.new if sreg.nil?
- ax = Hash.new 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')
+ redirect_to :action => "account", :display_name => @user.display_name
+ elsif session[:new_user]
+ session[:new_user].openid_url = openid_url
+
+ if email == session[:new_user].email && openid_email_verified(email)
+ session[:new_user].status = "active"