From c25d89db7578c2448a66f505adea9fd7a8477df6 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 19 Jul 2019 21:02:02 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/accounts_controller.rb | 9 +++++++++ app/models/user.rb | 8 -------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 52d405955..71da15386 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -72,6 +72,15 @@ class AccountsController < ApplicationController # 用户登录 def login @user = User.try_to_login(params[:login], params[:password]) + + if @user + # user is already in local database + return normal_status(-2, "违反平台使用规范,账号已被锁定") if @user.locked? + return normal_status(-2, "错误的账号或密码") unless @user.check_password?(params[:password].to_s) + else + return normal_status(-2, "错误的账号或密码") + end + @user.update_column(:last_login_on, Time.now) successful_authentication(@user) diff --git a/app/models/user.rb b/app/models/user.rb index 894a28910..299ad1ff4 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -507,14 +507,6 @@ class User < ApplicationRecord user = find_by_login(login) end - if user - # user is already in local database - raise Educoder::TipException.new(-2, "违反平台使用规范,账号已被锁定") if user.locked? - raise Educoder::TipException.new(-2, "错误的账号或密码") unless user.check_password?(password) - else - raise Educoder::TipException.new(-2, "错误的账号或密码") - end - user rescue => text raise text