This commit is contained in:
2021-04-02 18:08:36 +08:00
parent c4a43c4392
commit fba58800a7
6 changed files with 60 additions and 30 deletions

View File

@@ -1,19 +1,19 @@
# == Schema Information
#
# Table name: tokens
#
# id :integer not null, primary key
# user_id :integer default("0"), not null
# action :string(30) default(""), not null
# value :string(40) default(""), not null
# created_on :datetime not null
#
# Indexes
#
# index_tokens_on_user_id (user_id)
# tokens_value (value) UNIQUE
#
# == Schema Information
#
# Table name: tokens
#
# id :integer not null, primary key
# user_id :integer default("0"), not null
# action :string(30) default(""), not null
# value :string(40) default(""), not null
# created_on :datetime not null
#
# Indexes
#
# index_tokens_on_user_id (user_id)
# tokens_value (value) UNIQUE
#
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -76,7 +76,7 @@ class Token < ActiveRecord::Base
# Returns the active user who owns the key for the given action
def self.find_active_user(action, key, validity_days=nil)
user = find_user(action, key, validity_days)
if user && user.active?
if user && (user.active? || user.need_edit_info?)
user
end
end

View File

@@ -79,7 +79,7 @@ class User < Owner
STATUS_ACTIVE = 1
STATUS_REGISTERED = 2
STATUS_LOCKED = 3
STATUS_EDIT_PASSWORD = 4
STATUS_EDIT_INFO = 4
# tpi tpm权限控制
EDU_ADMIN = 1 # 超级管理员
@@ -162,7 +162,7 @@ class User < Owner
has_many :organizations, through: :organization_users
# Groups and active users
scope :active, lambda { where(status: [STATUS_ACTIVE, STATUS_EDIT_PASSWORD]) }
scope :active, lambda { where(status: [STATUS_ACTIVE, STATUS_EDIT_INFO]) }
scope :like, lambda { |keywords|
where("LOWER(concat(lastname, firstname, login, mail)) LIKE ?", "%#{keywords.split(" ").join('|')}%") unless keywords.blank?
}
@@ -379,8 +379,8 @@ class User < Owner
status == STATUS_LOCKED
end
def need_edit_password?
status == STATUS_EDIT_PASSWORD
def need_edit_info?
status == STATUS_EDIT_INFO
end
def activate
@@ -395,8 +395,8 @@ class User < Owner
self.status = STATUS_LOCKED
end
def need_edit_password
self.status = STATUS_EDIT_PASSWORD
def need_edit_info
self.status = STATUS_EDIT_INFO
end
def activate!
@@ -411,8 +411,8 @@ class User < Owner
update_attribute(:status, STATUS_LOCKED)
end
def need_edit_password!
update_attribute(:status, STATUS_LOCKED)
def need_edit_info!
update_attribute(:status, STATUS_EDIT_INFO)
end
# 课程用户身份