From 4e244bed3ab8013bc583e52ab9165097515cfaef Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 24 Nov 2022 14:28:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=89=8B=E6=9C=BA=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E7=A0=81=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/users_controller.rb | 15 +++++++++++++++ app/controllers/application_controller.rb | 3 +-- config/routes/api.rb | 1 + 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v1/users_controller.rb b/app/controllers/api/v1/users_controller.rb index 6baed66f..11446533 100644 --- a/app/controllers/api/v1/users_controller.rb +++ b/app/controllers/api/v1/users_controller.rb @@ -70,6 +70,21 @@ class Api::V1::UsersController < Api::V1::BaseController render_ok end + def check_phone_verify_code + code = strip(params[:code]) + phone = strip(params[:phone]) + code_type = params[:code_type] + + return tip_exception(-2, "手机号格式有误") unless mail =~ CustomRegexp::PHONE + + verifi_code = VerificationCode.where(phone: phone, code: code, code_type: code_type).last + return render_ok if code == "123123" && EduSetting.get("code_debug") # 万能验证码,用于测试 # TODO 万能验证码,用于测试 + + return tip_exception(-6, "验证码不正确") if verifi_code&.code != code + return tip_exception(-6, "验证码已失效") if !verifi_code&.effective? + render_ok + end + def update_email @result_object = Api::V1::Users::UpdateEmailService.call(@observe_user, params, current_user.gitea_token) if @result_object diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 8a5bb654..b88849f5 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -79,8 +79,7 @@ class ApplicationController < ActionController::Base # 判断用户的邮箱或者手机是否可用 # params[:type] 1: 注册;2:忘记密码;3:绑定 def check_mail_and_phone_valid login, type - unless login =~ /^[a-zA-Z0-9]+([._\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/ || login =~ /^1\d{10}$/ || - login =~ /^[a-zA-Z0-9]+([._\\]*[a-zA-Z0-9])$/ + unless login =~ /^[a-zA-Z0-9]+([._\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/ || login =~ /^1\d{10}$/ tip_exception(-2, "请输入正确的手机号或邮箱") end diff --git a/config/routes/api.rb b/config/routes/api.rb index 64014e40..9a9e5a62 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -8,6 +8,7 @@ defaults format: :json do post :check_password post :check_email post :check_email_verify_code + post :check_phone_verify_code patch :update_email patch :update_phone end