Merge branch 'pre_trustie_server' into trustie_server

This commit is contained in:
yystopf 2022-11-25 15:59:12 +08:00
commit 22450c2748
10 changed files with 123 additions and 9 deletions

View File

@ -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 phone =~ 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
@ -78,4 +93,13 @@ class Api::V1::UsersController < Api::V1::BaseController
return render_error('更改邮箱失败!')
end
end
def update_phone
@result_object = Api::V1::Users::UpdatePhoneService.call(@observe_user, params)
if @result_object
return render_ok
else
return render_error('更改手机号失败!')
end
end
end

View File

@ -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
@ -105,7 +104,7 @@ class ApplicationController < ActionController::Base
sigle_para = {phone: value}
# status = Gitlink::Sms.send(mobile: value, code: code)
# tip_exception(-2, code_msg(status)) if status != 0
status = Sms::UcloudService.call(value, code)
status = Sms::UcloudService.call(value, code, send_type)
tip_exception(-2, ucloud_code_msg(status)) if status != 0
when 8, 3, 5
# 邮箱类型的发送

View File

@ -193,7 +193,8 @@ class User < Owner
:show_email, :show_location, :show_department, :super_description, :show_super_description,
:technical_title, :province, :city, :custom_department, to: :user_extension, allow_nil: true
before_save :update_hashed_password, :set_lastname
# before_save :update_hashed_password, :set_lastname
before_save :update_hashed_password
after_save :reset_cache_data
after_create do
SyncTrustieJob.perform_later("user", 1) if allow_sync_to_trustie?

View File

@ -14,7 +14,7 @@ class Api::V1::Users::UpdateEmailService < ApplicationService
@mail = params[:email]
@old_mail = user.mail
@code = params[:code]
@verify_code = VerificationCode.where(email: @mail, code: @code, code_type: 10).last
@verify_code = VerificationCode.where(email: @mail, code_type: 10).last
end
def call

View File

@ -0,0 +1,35 @@
class Api::V1::Users::UpdatePhoneService < ApplicationService
include ActiveModel::Model
attr_reader :user, :password, :phone, :code, :verify_code
validates :password, :code, presence: true
validates :phone, presence: true, format: { with: CustomRegexp::PHONE }
def initialize(user, params)
@user = user
@password = params[:password]
@phone = params[:phone]
@code = params[:code]
@verify_code = VerificationCode.where(phone: @phone, code_type: 4).last
end
def call
raise Error, errors.full_messages.join(",") unless valid?
raise Error, "密码不正确." unless @user.check_password?(@password)
exist_owner = Owner.find_by(phone: @phone)
raise Error, "手机号已被使用." if exist_owner
is_debug = @code == "123123" && EduSetting.get("code_debug") # 万能验证码,用于测试 # TODO 万能验证码,用于测试
raise Error, "验证码不正确." if @verify_code&.code != @code && !is_debug
raise Error, "验证码已失效." if !@verify_code&.effective? && !is_debug
begin
ActiveRecord::Base.transaction do
@user.update_attributes!({phone: @phone})
end
return true
rescue
raise Error, "服务器错误,请联系系统管理员!"
end
end
end

View File

@ -1,9 +1,10 @@
class Sms::UcloudService < ApplicationService
attr_reader :phone, :code
attr_reader :phone, :code, :send_type
def initialize(phone, code)
def initialize(phone, code, send_type)
@phone = phone
@code = code
@send_type = send_type
end
def call
@ -14,7 +15,7 @@ class Sms::UcloudService < ApplicationService
sign_params = {
"Action" => "SendUSMSMessage",
"ProjectId" => project_id,
"TemplateId" => "UTA221114S2MGTY",
"TemplateId" => get_template_id(@send_type),
"PublicKey" => public_key,
"PhoneNumbers.0" => @phone,
"TemplateParams.0" => "#{@code}",
@ -95,4 +96,17 @@ class Sms::UcloudService < ApplicationService
end
end
# 1注册手机验证码 2找回密码手机验证码 4绑定手机 9验证手机号有效
def get_template_id(send_type)
case send_type
when 1, 2, 9
"UTA221114S2MGTY"
when 4
"UTA22112486FXLZ"
else
"UTA221114S2MGTY"
end
end
end

View File

@ -11,7 +11,7 @@ json.user_identity @user.identity
json.tidding_count 0
json.user_phone_binded @user.phone.present?
json.need_edit_info @user.need_edit_info?
# json.phone @user.phone
json.phone @user.phone
# json.email @user.mail
json.profile_completed @user.profile_is_completed?
json.professional_certification @user.professional_certification

View File

@ -8,7 +8,9 @@ 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
end
scope module: :users do

View File

@ -0,0 +1,23 @@
class UpdateUserNickName < ActiveRecord::Migration[5.2]
def change
execute("ALTER TABLE `users` MODIFY `nickname` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;")
execute("ALTER TABLE `open_users` MODIFY `extra` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;")
execute("ALTER TABLE `issues` MODIFY `subject` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;")
execute("ALTER TABLE `issues` MODIFY `description` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;")
execute("ALTER TABLE `projects` MODIFY `description` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;")
execute("ALTER TABLE `project_details` MODIFY `content` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;")
execute("ALTER TABLE `journals` MODIFY `notes` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;")
execute("ALTER TABLE `journal_details` MODIFY `old_value` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;")
execute("ALTER TABLE `journal_details` MODIFY `value` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;")
execute("ALTER TABLE `claims` MODIFY `note` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;")
execute("ALTER TABLE `commit_logs` MODIFY `message` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;")
execute("ALTER TABLE `user_extensions` MODIFY `description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;")
end
end

View File

@ -0,0 +1,16 @@
class UpdatePullRequestUtfName < ActiveRecord::Migration[5.2]
def change
execute("ALTER TABLE `projects` MODIFY `name` VARCHAR(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;")
execute("ALTER TABLE `pull_requests` MODIFY `title` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;")
execute("ALTER TABLE `pull_requests` MODIFY `body` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;")
execute("ALTER TABLE `organization_extensions` MODIFY `description` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;")
execute("ALTER TABLE `version_releases` MODIFY `name` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;")
execute("ALTER TABLE `version_releases` MODIFY `body` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;")
execute("ALTER TABLE `version_releases` MODIFY `tag_name` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;")
execute("ALTER TABLE `versions` MODIFY `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;")
execute("ALTER TABLE `versions` MODIFY `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;")
execute("ALTER TABLE `issue_tags` MODIFY `name` varchar(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;")
execute("ALTER TABLE `issue_tags` MODIFY `description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;")
execute("ALTER TABLE `projects_activity` MODIFY `project_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;")
end
end