X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/f70feedc6517b824c4201584d6298fd5790d85ba..c1b65d11fd71d3801f4f5e42a3c40dc872a766f9:/app/controllers/user_controller.rb diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 17f52fd40..1ac3b1ca5 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -46,7 +46,7 @@ class UserController < ApplicationController @title = t 'user.terms.title' @user = User.new(params[:user]) if params[:user] - if params[:user][:openid_url] and @user.pass_crypt.empty? + if params[:user] and params[:user][:openid_url] and @user.pass_crypt.empty? # We are creating an account with OpenID and no password # was specified so create a random one @user.pass_crypt = ActiveSupport::SecureRandom.base64(16) @@ -60,7 +60,7 @@ class UserController < ApplicationController elsif @user.terms_agreed? # Already agreed to terms, so just show settings redirect_to :action => :account, :display_name => @user.display_name - elsif params[:user][:openid_url] + elsif params[:user] and params[:user][:openid_url] # Verify OpenID before moving on session[:new_user] = @user openid_verify(params[:user][:openid_url], @user) @@ -100,7 +100,7 @@ class UserController < ApplicationController @user.terms_agreed = Time.now.getutc if @user.save - flash[:notice] = t 'user.new.flash create success message' + flash[:notice] = t 'user.new.flash create success message', :email => @user.email Notifier.deliver_signup_confirm(@user, @user.tokens.create(:referer => session.delete(:referer))) redirect_to :action => 'login' else @@ -258,30 +258,57 @@ class UserController < ApplicationController end def confirm - if params[:confirm_action] - token = UserToken.find_by_token(params[:confirm_string]) - if token and !token.user.active? - @user = token.user - @user.status = "active" - @user.email_valid = true - @user.save! - referer = token.referer - token.destroy - flash[:notice] = t 'user.confirm.success' - session[:user] = @user.id - unless referer.nil? - redirect_to referer + if request.post? + if token = UserToken.find_by_token(params[:confirm_string]) + if token.user.active? + flash[:error] = t('user.confirm.already active') + redirect_to :action => 'login' else - redirect_to :action => 'account', :display_name => @user.display_name + user = token.user + user.status = "active" + user.email_valid = true + user.save! + referer = token.referer + token.destroy + session[:user] = user.id + + unless referer.nil? + flash[:notice] = t('user.confirm.success') + redirect_to referer + else + flash[:notice] = t('user.confirm.success') + "

" + t('user.confirm.before you start') + redirect_to :action => 'account', :display_name => user.display_name + end end else - flash.now[:error] = t 'user.confirm.failure' + user = User.find_by_display_name(params[:display_name]) + + if user and user.active? + flash[:error] = t('user.confirm.already active') + elsif user + flash[:error] = t('user.confirm.unknown token') + t('user.confirm.reconfirm', :reconfirm => url_for(:action => 'confirm_resend', :display_name => params[:display_name])) + else + flash[:error] = t('user.confirm.unknown token') + end + + redirect_to :action => 'login' end end end + def confirm_resend + if user = User.find_by_display_name(params[:display_name]) + Notifier.deliver_signup_confirm(user, user.tokens.create) + flash[:notice] = t 'user.confirm_resend.success', :email => user.email + else + flash[:notice] = t 'user.confirm_resend.failure', :name => params[:display_name] + end + + redirect_to :action => 'login' + end + def confirm_email - if params[:confirm_action] + if request.post? token = UserToken.find_by_token(params[:confirm_string]) if token and token.user.new_email? @user = token.user @@ -297,7 +324,8 @@ class UserController < ApplicationController session[:user] = @user.id redirect_to :action => 'account', :display_name => @user.display_name else - flash.now[:error] = t 'user.confirm_email.failure' + flash[:error] = t 'user.confirm_email.failure' + redirect_to :action => 'account', :display_name => @user.display_name end end end @@ -411,8 +439,8 @@ private def password_authentication(username, password) if user = User.authenticate(:username => username, :password => password) successful_login(user) - elsif User.authenticate(:username => username, :password => password, :pending => true) - failed_login t('user.login.account not active') + elsif user = User.authenticate(:username => username, :password => password, :pending => true) + failed_login t('user.login.account not active', :reconfirm => url_for(:action => 'confirm_resend', :display_name => user.display_name)) elsif User.authenticate(:username => username, :password => password, :suspended => true) webmaster = link_to t('user.login.webmaster'), "mailto:webmaster@openstreetmap.org" failed_login t('user.login.account suspended', :webmaster => webmaster) @@ -427,13 +455,13 @@ private # If we don't appear to have a user for this URL then ask the # provider for some extra information to help with signup if openid_url and User.find_by_openid_url(openid_url) - optional = nil + required = nil else - optional = [:nickname, :email] + 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), :optional => optional) do |result, identity_url, registration| + authenticate_with_open_id(openid_expand_url(openid_url), :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. @@ -458,7 +486,9 @@ private # 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. - redirect_to :controller => 'user', :action => 'new', :nickname => registration['nickname'], :email => registration['email'], :openid => identity_url + nickname = sreg["nickname"] || ax["http://axschema.org/namePerson/friendly"] + email = sreg["email"] || ax["http://axschema.org/contact/email"] + 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')