|
|
|
@@ -16,9 +16,9 @@ class Api::V1::UsersController < Api::V1::BaseController |
|
|
|
|
|
|
|
# 60s内不能重复发送 |
|
|
|
send_email_limit_cache_key = "send_email_60_second_limit:#{mail}" |
|
|
|
tip_exception(-1, '请勿频繁操作') if Rails.cache.exist?(send_email_limit_cache_key) |
|
|
|
tip_exception(-2, '请勿频繁操作') if Rails.cache.exist?(send_email_limit_cache_key) |
|
|
|
send_email_control = LimitForbidControl::SendEmailCode.new(mail) |
|
|
|
tip_exception(-1, '邮件发送太频繁,请稍后再试') if send_email_control.forbid? |
|
|
|
tip_exception(-2, '邮件发送太频繁,请稍后再试') if send_email_control.forbid? |
|
|
|
begin |
|
|
|
UserMailer.update_email(mail, verification_code).deliver_now |
|
|
|
|
|
|
|
@@ -39,17 +39,17 @@ class Api::V1::UsersController < Api::V1::BaseController |
|
|
|
|
|
|
|
def check_password |
|
|
|
password = params[:password] |
|
|
|
return render_error("8~16位密码,支持字母数字和符号") unless password =~ CustomRegexp::PASSWORD |
|
|
|
return render_error("密码错误") unless @observe_user.check_password?(password) |
|
|
|
return render_error(-5, "8~16位密码,支持字母数字和符号") unless password =~ CustomRegexp::PASSWORD |
|
|
|
return render_error(-5, "密码错误") unless @observe_user.check_password?(password) |
|
|
|
render_ok |
|
|
|
end |
|
|
|
|
|
|
|
def check_email |
|
|
|
mail = strip(params[:email]) |
|
|
|
return render_error("邮件格式有误") unless mail =~ CustomRegexp::EMAIL |
|
|
|
return render_error(-2, "邮件格式有误") unless mail =~ CustomRegexp::EMAIL |
|
|
|
|
|
|
|
exist_owner = Owner.find_by(mail: mail) |
|
|
|
return render_error('邮箱已被使用') if exist_owner |
|
|
|
return render_error(-2, '邮箱已被使用') if exist_owner |
|
|
|
render_ok |
|
|
|
end |
|
|
|
|
|
|
|
@@ -58,12 +58,13 @@ class Api::V1::UsersController < Api::V1::BaseController |
|
|
|
mail = strip(params[:email]) |
|
|
|
code_type = params[:code_type] |
|
|
|
|
|
|
|
return render_error("邮件格式有误") unless mail =~ CustomRegexp::EMAIL |
|
|
|
return render_error(-2, "邮件格式有误") unless mail =~ CustomRegexp::EMAIL |
|
|
|
|
|
|
|
verifi_code = VerificationCode.where(email: mail, code: code, code_type: code_type).last |
|
|
|
return render_ok if code == "123123" && EduSetting.get("code_debug") # 万能验证码,用于测试 # TODO 万能验证码,用于测试 |
|
|
|
|
|
|
|
return render_error("验证码不正确") if verifi_code&.code != code |
|
|
|
return render_error("验证码已失效") if !verifi_code&.effective? |
|
|
|
return render_error(-6, "验证码不正确") if verifi_code&.code != code |
|
|
|
return render_error(-6, "验证码已失效") if !verifi_code&.effective? |
|
|
|
render_ok |
|
|
|
end |
|
|
|
|
|
|
|
|