diff --git a/app/models/memo.rb b/app/models/memo.rb index 1b2be5476..6b7da3548 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -16,7 +16,8 @@ class Memo < ApplicationRecord has_many :children, foreign_key: :parent_id, class_name: 'Memo' has_many :attachments, as: :container, dependent: :destroy has_many :tidings, as: :container, dependent: :destroy - validate_harmonious_of [:content, :subject] + validate_harmonious_of [:subject, :content] + validate :validate_sensitive_string scope :field_for_list, lambda{ select([:id, :subject, :author_id, :sticky, :updated_at, :language, :reward, :all_replies_count, :viewed_count, :forum_id]) @@ -55,4 +56,9 @@ class Memo < ApplicationRecord self.tidings << Tiding.new(tiding_attr) end + + def validate_sensitive_string + raise("标题包含敏感词汇,请重新输入") unless HarmoniousDictionary.clean?(subject) + raise("内容包含敏感词汇,请重新输入") unless HarmoniousDictionary.clean?(content) + end end diff --git a/app/models/user.rb b/app/models/user.rb index 7c1463b7f..54aa8d85e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -178,14 +178,8 @@ class User < ApplicationRecord 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 :mail, maximum: MAIL_LENGTH_LMIT - validate_harmonious_of [:lastname, :nickname] - # validates_format_of :mail, with: VALID_EMAIL_REGEX, multiline: true - # validates_format_of :phone, with: VALID_PHONE_REGEX, multiline: true + validate :validate_sensitive_string validate :validate_password_length - #validate :validate_ID_number - #validates_format_of :ID_number, with: VALID_NUMBER_REGEX, multiline: true, message: "身份证号格式不对" - # validates :nickname, presence: true, length: { maximum: 10 } - # validates :lastname, presence: true # 删除自动登录的token,一旦退出下次会提示需要登录 def delete_autologin_token(value) @@ -728,6 +722,11 @@ class User < ApplicationRecord end end + def validate_sensitive_string + raise("真实姓名包含敏感词汇,请重新输入") unless HarmoniousDictionary.clean?(lastname) + raise("昵称包含敏感词汇,请重新输入") unless HarmoniousDictionary.clean?(nickname) + end + def set_laboratory return unless new_record?