更改:验证返回status以及万能验证码

This commit is contained in:
yystopf 2022-10-21 14:31:32 +08:00
parent e9b23d6577
commit 9ee4c85b7c
2 changed files with 10 additions and 10 deletions

View File

@ -15,6 +15,5 @@ class Api::V1::ProjectsController < Api::V1::BaseController
def blame def blame
@result_object = Api::V1::Projects::BlameService.call(@project, params[:sha], params[:filepath], current_user&.gitea_token) @result_object = Api::V1::Projects::BlameService.call(@project, params[:sha], params[:filepath], current_user&.gitea_token)
puts @result_object
end end
end end

View File

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