<commit_before>M      = require \mongoose
Cons   = require \../../lib/model-constraints
Crypt  = require \../crypt
Crud   = require \../crud
P-Id   = require \./plugin-id
P-Meta = require \./plugin-meta

const AUTHTYPE-PASSWORD = \password

spec =
  login_id    : type:String, required:yes, index:{+unique} # logins._id or openauth id
  auth_type   : type:String, required:yes, enum:[AUTHTYPE-PASSWORD] ++ <[ facebook github google mock ]>
  name        : type:String, required:yes
  email       : type:String # validated below
  info        : type:String, match:Cons.url.regex
  role        : type:String, required:yes, enum:<[ admin user ]>, default:\user
  create_date : type:Date  , required:yes, default:Date.now
  quota_daily : type:Number, required:yes, default:5
  freeze_until: type:String  # allow sign-in only after this datetime
  # TODO: remove the following deprecated fields after oauth migration
  login       : type:String
  password    : type:String

schema = new M.Schema spec
  ..plugin P-Id
  ..pre \save, (next) -> # encrypt email
    return next! unless @isModified \email
    @email = Crypt.encrypt @email
    next!
  ..pre \validate, (next) -> # validate email
    # Set self-created user's meta. This really belongs in pre-init but doesn't
    # seem to work there, so we'll leave it in pre-validate for now.
    if @isNew then @set \meta.create_user_id, @_id unless @get \meta.create_user_id
    # normal validation
    return next! unless @email
    return next! unless @isModified \email
    @invalidate \email, "Invalid email #{@email}" unless Cons.email.regex.test @email<commit_msg>remove deprecated fields<commit_after>M      = require \mongoose
Cons   = require \../../lib/model-constraints
Crypt  = require \../crypt
Crud   = require \../crud
P-Id   = require \./plugin-id
P-Meta = require \./plugin-meta

const AUTHTYPE-PASSWORD = \password

spec =
  login_id    : type:String, required:yes, index:{+unique} # logins._id or openauth id
  auth_type   : type:String, required:yes, enum:[AUTHTYPE-PASSWORD] ++ <[ facebook github google mock ]>
  name        : type:String, required:yes
  email       : type:String # validated below
  info        : type:String, match:Cons.url.regex
  role        : type:String, required:yes, enum:<[ admin user ]>, default:\user
  create_date : type:Date  , required:yes, default:Date.now
  quota_daily : type:Number, required:yes, default:5
  freeze_until: type:String  # allow sign-in only after this datetime

schema = new M.Schema spec
  ..plugin P-Id
  ..pre \save, (next) -> # encrypt email
    return next! unless @isModified \email
    @email = Crypt.encrypt @email
    next!
  ..pre \validate, (next) -> # validate email
    # Set self-created user's meta. This really belongs in pre-init but doesn't
    # seem to work there, so we'll leave it in pre-validate for now.
    if @isNew then @set \meta.create_user_id, @_id unless @get \meta.create_user_id
    # normal validation
    return next! unless @email
    return next! unless @isModified \email
    @invalidate \email, "Invalid email #{@email}" unless Cons.email.regex.test @email
{'fraction_non_alphanumeric': 0.11760925449871465, 'fraction_numerical': 0.0006426735218508997, 'mean_word_length': 3.161764705882353, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5595192', 'n_tokens_mistral': 973, 'n_tokens_neox': 954, 'n_words': 308}