@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)
if @user
if @user.invalid?
- # Something is wrong, so rerender the form
- render :action => :new
+ if @user.new_record?
+ # Something is wrong with a new user, so rerender the form
+ render :action => :new
+ else
+ # Error in existing user, so go to account settings
+ flash[:errors] = @user.errors
+ redirect_to :action => :account, :display_name => @user.display_name
+ end
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)
@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
openid_verify(nil, @user) do |user|
update_user(user)
end
+ else
+ if flash[:errors]
+ flash[:errors].each do |attr,msg|
+ attr = "new_email" if attr == "email" and !@user.new_email.nil?
+ @user.errors.add(attr,msg)
+ end
+ end
end
end
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') + "<br /><br />" + 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
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
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)
# 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.
# 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')