From ff6649cd2c3eef3513f95e8884041b5efd40c79a Mon Sep 17 00:00:00 2001 From: p31729568 Date: Tue, 20 Aug 2019 11:16:34 +0800 Subject: [PATCH] modify bind email and phone error tip --- app/libs/util.rb | 9 +++++++++ app/services/users/bind_email_service.rb | 2 +- app/services/users/bind_phone_service.rb | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/libs/util.rb b/app/libs/util.rb index 6c7784606..f39ce2b58 100644 --- a/app/libs/util.rb +++ b/app/libs/util.rb @@ -42,4 +42,13 @@ module Util return '' if str.blank? str.gsub(/<\/?.*?>/, '').gsub(/[\n\t\r]/, '').gsub(/ /, '') end + + def conceal(str, type = nil) + str = str.to_s + case type + when :phone then "#{str[0..2]}***#{str[-4..-1]}" + when :email then "#{str[0..2]}***#{str[str.rindex('@')..-1]}" + else "#{str[0..2]}***#{str[-3..-1]}" + end + end end \ No newline at end of file diff --git a/app/services/users/bind_email_service.rb b/app/services/users/bind_email_service.rb index 4c8124ffa..ed1c46404 100644 --- a/app/services/users/bind_email_service.rb +++ b/app/services/users/bind_email_service.rb @@ -11,7 +11,7 @@ class Users::BindEmailService < ApplicationService def call Users::BindEmailForm.new(params).validate! - raise Error, '该邮箱已被绑定' if User.where.not(id: user.id).exists?(mail: params[:email]) + raise Error, '该邮箱已被其他账号绑定' if User.where.not(id: user.id).exists?(mail: params[:email]) code = VerificationCode.where(email: params[:email], code: params[:code], code_type: 5).last raise Error, '验证码无效' unless code&.effective? diff --git a/app/services/users/bind_phone_service.rb b/app/services/users/bind_phone_service.rb index af4292230..2294e4b3c 100644 --- a/app/services/users/bind_phone_service.rb +++ b/app/services/users/bind_phone_service.rb @@ -11,7 +11,7 @@ class Users::BindPhoneService < ApplicationService def call Users::BindPhoneForm.new(params).validate! - raise Error, '该手机号已被绑定' if User.where.not(id: user.id).exists?(phone: params[:phone]) + raise Error, '该手机号已被其他账号绑定' if User.where.not(id: user.id).exists?(phone: params[:phone]) code = VerificationCode.where(phone: params[:phone], code: params[:code], code_type: 4).last raise Error, '验证码无效' unless code&.effective?