forked from jasder/forgeplus
test_user
This commit is contained in:
parent
0a80b7c43f
commit
451d8c0a3f
|
@ -1,9 +1,6 @@
|
||||||
class User < ApplicationRecord
|
class User < ApplicationRecord
|
||||||
include Watchable
|
include Watchable
|
||||||
include Likeable
|
include Searchable::Dependents::User
|
||||||
include BaseModel
|
|
||||||
include ProjectOperable
|
|
||||||
# include Searchable::Dependents::User
|
|
||||||
|
|
||||||
# Account statuses
|
# Account statuses
|
||||||
STATUS_ANONYMOUS = 0
|
STATUS_ANONYMOUS = 0
|
||||||
|
@ -22,7 +19,7 @@ class User < ApplicationRecord
|
||||||
EDU_NORMAL = 8 # 普通用户
|
EDU_NORMAL = 8 # 普通用户
|
||||||
|
|
||||||
VALID_EMAIL_REGEX = /^[a-zA-Z0-9]+([.\-_\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/i
|
VALID_EMAIL_REGEX = /^[a-zA-Z0-9]+([.\-_\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/i
|
||||||
# VALID_PHONE_REGEX = /^1\d{10}$/
|
VALID_PHONE_REGEX = /^1\d{10}$/
|
||||||
# 身份证
|
# 身份证
|
||||||
VALID_NUMBER_REGEX = /(^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^([A-Z]\d{6,10}(\(\w{1}\))?)$)/
|
VALID_NUMBER_REGEX = /(^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^([A-Z]\d{6,10}(\(\w{1}\))?)$)/
|
||||||
|
|
||||||
|
@ -33,14 +30,6 @@ class User < ApplicationRecord
|
||||||
|
|
||||||
LOGIN_CHARS = %W(2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z).freeze
|
LOGIN_CHARS = %W(2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z).freeze
|
||||||
|
|
||||||
# FIX Invalid single-table inheritance type
|
|
||||||
self.inheritance_column = nil
|
|
||||||
|
|
||||||
# educoder: 来自Educoder平台
|
|
||||||
# trustie: 来自Trustie平台
|
|
||||||
# forge: 平台本身注册的用户
|
|
||||||
enum platform: [:forge, :educoder, :trustie]
|
|
||||||
|
|
||||||
belongs_to :laboratory, optional: true
|
belongs_to :laboratory, optional: true
|
||||||
|
|
||||||
has_one :user_extension, dependent: :destroy
|
has_one :user_extension, dependent: :destroy
|
||||||
|
@ -58,8 +47,6 @@ class User < ApplicationRecord
|
||||||
has_many :study_shixuns, through: :myshixuns, source: :shixun # 已学习的实训
|
has_many :study_shixuns, through: :myshixuns, source: :shixun # 已学习的实训
|
||||||
has_many :course_messages
|
has_many :course_messages
|
||||||
has_many :courses, foreign_key: 'tea_id', dependent: :destroy
|
has_many :courses, foreign_key: 'tea_id', dependent: :destroy
|
||||||
has_many :versions
|
|
||||||
has_many :issue_times, :dependent => :destroy
|
|
||||||
|
|
||||||
#试卷
|
#试卷
|
||||||
has_many :exercise_banks, :dependent => :destroy
|
has_many :exercise_banks, :dependent => :destroy
|
||||||
|
@ -131,8 +118,8 @@ class User < ApplicationRecord
|
||||||
has_many :manage_courses, through: :manage_course_members, source: :course
|
has_many :manage_courses, through: :manage_course_members, source: :course
|
||||||
|
|
||||||
# 关注
|
# 关注
|
||||||
has_many :be_watchers, foreign_key: :user_id, dependent: :destroy # 我的关注
|
# has_many :be_watchers, foreign_key: :user_id, dependent: :destroy # 我的关注
|
||||||
has_many :be_watcher_users, through: :be_watchers, dependent: :destroy # 我关注的用户
|
# has_many :be_watcher_users, through: :be_watchers, dependent: :destroy # 我关注的用户
|
||||||
|
|
||||||
# 认证
|
# 认证
|
||||||
has_many :apply_user_authentication
|
has_many :apply_user_authentication
|
||||||
|
@ -155,9 +142,6 @@ class User < ApplicationRecord
|
||||||
# 项目
|
# 项目
|
||||||
has_many :applied_projects, dependent: :destroy
|
has_many :applied_projects, dependent: :destroy
|
||||||
|
|
||||||
has_many :projects, dependent: :destroy
|
|
||||||
has_many :repositories, dependent: :destroy
|
|
||||||
|
|
||||||
# 教学案例
|
# 教学案例
|
||||||
has_many :libraries, dependent: :destroy
|
has_many :libraries, dependent: :destroy
|
||||||
|
|
||||||
|
@ -170,27 +154,22 @@ class User < ApplicationRecord
|
||||||
has_many :hacks, dependent: :destroy
|
has_many :hacks, dependent: :destroy
|
||||||
has_many :hack_user_lastest_codes, dependent: :destroy
|
has_many :hack_user_lastest_codes, dependent: :destroy
|
||||||
|
|
||||||
has_many :composes, dependent: :destroy
|
|
||||||
has_many :compose_users, dependent: :destroy
|
|
||||||
|
|
||||||
has_many :project_trends, dependent: :destroy
|
|
||||||
# 题库
|
# 题库
|
||||||
has_many :item_banks, dependent: :destroy
|
has_many :item_banks, dependent: :destroy
|
||||||
has_many :item_baskets, -> { order("item_baskets.position ASC") }, dependent: :destroy
|
has_many :item_baskets, -> { order("item_baskets.position ASC") }, dependent: :destroy
|
||||||
has_many :examination_banks, dependent: :destroy
|
has_many :examination_banks, dependent: :destroy
|
||||||
has_many :examination_intelligent_settings, dependent: :destroy
|
has_many :examination_intelligent_settings, dependent: :destroy
|
||||||
|
|
||||||
|
has_many :teacher_group_records, dependent: :destroy
|
||||||
|
|
||||||
# Groups and active users
|
# Groups and active users
|
||||||
scope :active, lambda { where(status: STATUS_ACTIVE) }
|
scope :active, lambda { where(status: STATUS_ACTIVE) }
|
||||||
scope :like, lambda { |keywords|
|
|
||||||
where("LOWER(concat(lastname, firstname, login)) LIKE ?", "%#{keywords.split(" ").join('|')}%") unless keywords.blank?
|
|
||||||
}
|
|
||||||
|
|
||||||
attr_accessor :password, :password_confirmation
|
attr_accessor :password, :password_confirmation
|
||||||
|
|
||||||
delegate :gender, :department_id, :school_id, :location, :location_city, :technical_title, to: :user_extension, allow_nil: true
|
delegate :gender, :department_id, :school_id, :location, :location_city, :technical_title, to: :user_extension, allow_nil: true
|
||||||
|
|
||||||
before_save :update_hashed_password
|
before_save :update_hashed_password, :set_laboratory
|
||||||
after_create do
|
after_create do
|
||||||
SyncTrustieJob.perform_later("user", 1) if allow_sync_to_trustie?
|
SyncTrustieJob.perform_later("user", 1) if allow_sync_to_trustie?
|
||||||
end
|
end
|
||||||
|
@ -198,11 +177,10 @@ class User < ApplicationRecord
|
||||||
#
|
#
|
||||||
# validations
|
# validations
|
||||||
#
|
#
|
||||||
validates :platform, inclusion: { in: %w(forge educoder trustie) }
|
|
||||||
validates_presence_of :login, :if => Proc.new { |user| !user.is_a?(AnonymousUser) }, case_sensitive: false
|
validates_presence_of :login, :if => Proc.new { |user| !user.is_a?(AnonymousUser) }, case_sensitive: false
|
||||||
validates_uniqueness_of :login, :if => Proc.new { |user| user.login_changed? && user.login.present? }, case_sensitive: false
|
validates_uniqueness_of :login, :if => Proc.new { |user| user.login_changed? && user.login.present? }, case_sensitive: false
|
||||||
validates_uniqueness_of :mail, :if => Proc.new { |user| user.mail_changed? && user.mail.present? }, case_sensitive: false
|
validates_uniqueness_of :mail, :if => Proc.new { |user| user.mail_changed? && user.mail.present? }, case_sensitive: false
|
||||||
# validates_uniqueness_of :phone, :if => Proc.new { |user| user.phone_changed? && user.phone.present? }, case_sensitive: false
|
validates_uniqueness_of :phone, :if => Proc.new { |user| user.phone_changed? && user.phone.present? }, case_sensitive: false
|
||||||
validates_length_of :login, maximum: LOGIN_LENGTH_LIMIT
|
validates_length_of :login, maximum: LOGIN_LENGTH_LIMIT
|
||||||
validates_length_of :mail, maximum: MAIL_LENGTH_LMIT
|
validates_length_of :mail, maximum: MAIL_LENGTH_LMIT
|
||||||
validate :validate_sensitive_string
|
validate :validate_sensitive_string
|
||||||
|
@ -221,10 +199,6 @@ class User < ApplicationRecord
|
||||||
mail.blank? ? "#{login}@educoder.net" : mail
|
mail.blank? ? "#{login}@educoder.net" : mail
|
||||||
end
|
end
|
||||||
|
|
||||||
def project_manager?(project)
|
|
||||||
project.manager_members.exists?(user: self) || self.admin?
|
|
||||||
end
|
|
||||||
|
|
||||||
# 学号
|
# 学号
|
||||||
def student_id
|
def student_id
|
||||||
self.user_extension.try(:student_id)
|
self.user_extension.try(:student_id)
|
||||||
|
@ -590,7 +564,7 @@ class User < ApplicationRecord
|
||||||
anonymous_user = AnonymousUser.unscoped.take
|
anonymous_user = AnonymousUser.unscoped.take
|
||||||
if anonymous_user.nil?
|
if anonymous_user.nil?
|
||||||
anonymous_user = AnonymousUser.unscoped.create(lastname: 'Anonymous', firstname: '', login: '',
|
anonymous_user = AnonymousUser.unscoped.create(lastname: 'Anonymous', firstname: '', login: '',
|
||||||
mail: '358551897@qq.com', phone: '13333333333', status: 0, platform: User.platforms[:forge])
|
mail: '358551897@qq.com', phone: '13333333333', status: 0)
|
||||||
raise "Unable to create the anonymous user: error_info:#{anonymous_user.errors.messages}" if anonymous_user.new_record?
|
raise "Unable to create the anonymous user: error_info:#{anonymous_user.errors.messages}" if anonymous_user.new_record?
|
||||||
end
|
end
|
||||||
anonymous_user
|
anonymous_user
|
||||||
|
@ -683,6 +657,7 @@ class User < ApplicationRecord
|
||||||
|
|
||||||
# 邮箱:w***l@qq.com
|
# 邮箱:w***l@qq.com
|
||||||
def hidden_mail
|
def hidden_mail
|
||||||
|
Rails.logger.info("######-----: #{mail}")
|
||||||
Util.conceal(mail, :email).to_s
|
Util.conceal(mail, :email).to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -754,8 +729,8 @@ class User < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_sensitive_string
|
def validate_sensitive_string
|
||||||
raise("真实姓名包含敏感词汇,请重新输入") if lastname && !HarmoniousDictionary.clean?(lastname)
|
raise("真实姓名包含敏感词汇,请重新输入#{lastname}") if lastname && !HarmoniousDictionary.clean?(lastname)
|
||||||
raise("昵称包含敏感词汇,请重新输入") if nickname && !HarmoniousDictionary.clean?(nickname)
|
raise("昵称包含敏感词汇,请重新输入#{nickname}") if nickname && !HarmoniousDictionary.clean?(nickname)
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_laboratory
|
def set_laboratory
|
||||||
|
|
Loading…
Reference in New Issue