filter_parameter_logging :password, :pass_crypt, :pass_crypt_confirmation
- cache_sweeper :user_sweeper, :only => [:account, :set_status, :delete]
+ cache_sweeper :user_sweeper, :only => [:account, :set_status, :delete], :unless => STATUS == :database_offline
def terms
- @title = t 'user.new.title'
- @legale = params[:legale] || OSM.IPToCountry(request.remote_ip) || APP_CONFIG['default_legale']
+ @legale = params[:legale] || OSM.IPToCountry(request.remote_ip) || DEFAULT_LEGALE
@text = OSM.legal_text_for_country(@legale)
if request.xhr?
render :update do |page|
- page.replace_html "contributorTerms", :partial => "terms"
+ page.replace_html "contributorTerms", :partial => "terms", :locals => { :has_decline => params[:has_decline] }
+ end
+ elsif using_open_id?
+ # The redirect from the OpenID provider reenters here
+ # again and we need to pass the parameters through to
+ # the open_id_authentication function
+ @user = session.delete(:new_user)
+
+ openid_verify(nil, @user) do |user|
+ end
+
+ if @user.openid_url.nil? or @user.invalid?
+ render :action => 'new'
+ else
+ render :action => 'terms'
end
- elsif params[:user]
+ else
session[:referer] = params[:referer]
- @user = User.new(params[:user])
+ @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)
@user.pass_crypt_confirmation = @user.pass_crypt
end
- if @user.valid?
- if params[:user][:openid_url].nil? or
- params[:user][:openid_url].empty?
- # No OpenID so just move on to the terms
- render :action => 'terms'
- else
+ if @user
+ if @user.invalid?
+ # Something is wrong, so rerender the form
+ render :action => :new
+ elsif @user.terms_agreed?
+ # Already agreed to terms, so just show settings
+ redirect_to :action => :account, :display_name => @user.display_name
+ elsif params[:user] and params[:user][:openid_url]
# Verify OpenID before moving on
session[:new_user] = @user
openid_verify(params[:user][:openid_url], @user)
end
else
- # Something is wrong, so rerender the form
- render :action => 'new'
- end
- elsif using_open_id?
- # The redirect from the OpenID provider reenters here
- # again and we need to pass the parameters through to
- # the open_id_authentication function
- @user = session.delete(:new_user)
-
- openid_verify(nil, @user) do |user|
- end
-
- if @user.openid_url.nil? or @user.invalid?
- render :action => 'new'
- else
- render :action => 'terms'
+ # Not logged in, so redirect to the login page
+ redirect_to :action => :login, :referer => request.request_uri
end
end
end
render :action => 'new'
elsif params[:decline]
redirect_to t('user.terms.declined')
+ elsif @user
+ if !@user.terms_agreed?
+ @user.consider_pd = params[:user][:consider_pd]
+ @user.terms_agreed = Time.now.getutc
+ if @user.save
+ flash[:notice] = t 'user.new.terms accepted'
+ end
+ end
+
+ redirect_to :action => :account, :display_name => @user.display_name
else
@user = User.new(params[: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
else
password_authentication(params[:username], params[:password])
end
- else
- @title = t 'user.login.title'
+ elsif flash[:notice].nil?
+ flash.now[:notice] = t 'user.login.notice'
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)
- failed_login t('user.login.account suspended')
+ webmaster = link_to t('user.login.webmaster'), "mailto:webmaster@openstreetmap.org"
+ failed_login t('user.login.account suspended', :webmaster => webmaster)
else
failed_login t('user.login.auth failure')
end
# 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.
# 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')
- when "active", "confirmed" then successful_login(user)
- when "suspended" then failed_login t('user.login.account suspended')
- else failed_login t('user.login.auth failure')
+ when "pending" then
+ failed_login t('user.login.account not active')
+ when "active", "confirmed" then
+ successful_login(user)
+ when "suspended" then
+ webmaster = link_to t('user.login.webmaster'), "mailto:webmaster@openstreetmap.org"
+ failed_login t('user.login.account suspended', :webmaster => webmaster)
+ else
+ failed_login t('user.login.auth failure')
end
else
# 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.
- 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')