FEATURE: Check email availability in signup form (#12328)

* FEATURE: Check email availability on focus out

* FIX: Properly debounce username availability
This commit is contained in:
Bianca Nenciu
2021-03-22 17:46:03 +02:00
committed by GitHub
parent 4fb2d397a4
commit ec7415ff49
8 changed files with 156 additions and 69 deletions

View File

@ -34,6 +34,7 @@ class UsersController < ApplicationController
# once that happens you can't log in with social
skip_before_action :verify_authenticity_token, only: [:create]
skip_before_action :redirect_to_login_if_required, only: [:check_username,
:check_email,
:create,
:account_created,
:activate_account,
@ -522,6 +523,24 @@ class UsersController < ApplicationController
render json: checker.check_username(username, email)
end
def check_email
RateLimiter.new(nil, "check-email-#{request.remote_ip}", 10, 1.minute).performed!
if SiteSetting.hide_email_address_taken?
return render json: success_json
end
user_email = UserEmail.new(email: params[:email])
if user_email.valid?
render json: success_json
else
render json: failed_json.merge(errors: user_email.errors.full_messages)
end
rescue RateLimiter::LimitExceeded
render json: success_json
end
def user_from_params_or_current_user
params[:for_user_id] ? User.find(params[:for_user_id]) : current_user
end