From 11bcc8a64b0f972199c21a76b5c5dda5bcb9173b Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 6 Nov 2019 15:37:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=86=E7=A0=81=E9=94=99=E8=AF=AF=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/accounts_controller.rb | 10 ++++++---- app/libs/limit_forbid_control/base.rb | 8 ++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 1f67cc3c4..37c524f63 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -78,12 +78,12 @@ class AccountsController < ApplicationController return normal_status(-2, "违反平台使用规范,账号已被锁定") if @user.locked? login_control = LimitForbidControl::UserLogin.new(@user) - return normal_status(-2, "登录密码出错已达上限,将锁定密码#{login_control.forbid_expires/60}分钟") if login_control.forbid? + return normal_status(-2, "登录密码出错已达上限,账号已被锁定, 请#{login_control.forbid_expires/60}分钟后重新登录或找回登录密码,") if login_control.forbid? password_ok = @user.check_password?(params[:password].to_s) unless password_ok login_control.increment! - return normal_status(-2, "错误的账号或密码") + return normal_status(-2, "你已经输错密码#{login_control.error_times}次,还剩余#{login_control.remain_times}次机会") end successful_authentication(@user) @@ -111,9 +111,11 @@ class AccountsController < ApplicationController return normal_status(-2, "验证码已失效") if !verifi_code&.effective? user.password, user.password_confirmation = params[:new_password], params[:new_password_confirmation] - if user.save! - sucess_status + ActiveRecord::Base.transaction do + user.save! + LimitForbidControl::UserLogin.new(user).clear end + sucess_status rescue Exception => e uid_logger_error(e.message) tip_exception("密码重置失败") diff --git a/app/libs/limit_forbid_control/base.rb b/app/libs/limit_forbid_control/base.rb index fbde5e6ea..26977b314 100644 --- a/app/libs/limit_forbid_control/base.rb +++ b/app/libs/limit_forbid_control/base.rb @@ -40,6 +40,14 @@ class LimitForbidControl::Base end end + def error_times + Rails.cache.read(cache_key).to_i + end + + def remain_times + allow_times - error_times + end + def clear Rails.logger.info("[LimitForbidControl] Clear #{cache_key}") Rails.cache.delete(forbid_cache_key)