X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/13289d404188bd397ee72852f66c415a2bb87066..7b01a8ae82873ecef35679b387a9d29a49c0a3b2:/app/controllers/user_controller.rb diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 07b4f5975..c9983cc85 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -166,9 +166,10 @@ class UserController < ApplicationController @user.preferred_editor = params[:user][:preferred_editor] end - @user.openid_url = nil if params[:user][:openid_url].empty? + @user.openid_url = nil if params[:user][:openid_url].blank? - if params[:user][:openid_url].length > 0 and + if params[:user][:openid_url] and + params[:user][:openid_url].length > 0 and params[:user][:openid_url] != @user.openid_url # If the OpenID has changed, we want to check that it is a # valid OpenID and one the user has control over before saving @@ -186,13 +187,6 @@ class UserController < ApplicationController 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 @@ -207,7 +201,15 @@ class UserController < ApplicationController @title = t 'user.lost_password.title' if params[:user] and params[:user][:email] - user = User.visible.where(:email => params[:user][:email]).first + user = User.visible.find_by_email(params[:user][:email]) + + if user.nil? + users = User.visible.where("LOWER(email) = LOWER(?)", params[:user][:email]) + + if users.count == 1 + user = users.first + end + end if user token = user.tokens.create @@ -657,16 +659,25 @@ private if user.save set_locale - if user.new_email.nil? or user.new_email.empty? + if user.new_email.blank? flash.now[:notice] = t 'user.account.flash update success' else - flash.now[:notice] = t 'user.account.flash update success confirm needed' + user.email = user.new_email + + if user.valid? + flash.now[:notice] = t 'user.account.flash update success confirm needed' - begin - Notifier.email_confirm(user, user.tokens.create).deliver - rescue - # Ignore errors sending email + begin + Notifier.email_confirm(user, user.tokens.create).deliver + rescue + # Ignore errors sending email + end + else + @user.errors.set(:new_email, @user.errors.get(:email)) + @user.errors.set(:email, []) end + + user.reset_email! end end end