<commit_before>'use strict';

const promise = require('utils/promise'),
    <%_ if (locals.useMongo) {_%>
    mongoose = require('utils/mongoose'),
    <%_}_%>
    <%_ if (locals.useSequelize) {_%>
    sequelize = require('utils/sequelize'),
    Sequelize = require('sequelize'),
    <%_}_%>
    bcrypt = require('utils/bcrypt'),
    SALT_WORK_FACTOR = 10;

/**
 * User entity scheme.
 * @type {*|Schema}
 */

<%_ if (locals.useMongo) {_%>
let userSchema = new mongoose.Schema({
    login: {
        type: String,
        required: true,
        index: true,
        unique: true
    },
    password: {
        type: String,
        required: true
    },
    email: {
        type: String,
        required: true
    },
    status: {
        type: String,
        enum: ['ACTIVE', 'BLOCKED'],
        default: 'ACTIVE',
        required: true
    },
    verified: {
        type: Boolean,
        required: true
    },
    verifyLinkExpiration: {
        type: String
    },
    verifyToken: {
        type: String
    }
});

/**
 * Save-hook that fills password field with bcrypt hash.
 */
userSchema.pre('save', promise.asyncHook(async user => {

    if (!user.isModified('password')) {
        return;
    }

    user.password = await bcrypt.hashAsync(user.password, await bcrypt.genSaltAsync(SALT_WORK_FACTOR));
}));


/**
 * Verifies that password is equal to password of this user.
 * @param candidatePassword password to verify.
 * @return promised true if equals, false otherwise.
 */
userSchema.methods.comparePasswordAsync = async function (candidatePassword) {
    return await bcrypt.compareAsync(candidatePassword || '', this.password);
};

module.exports = mongoose.model('User', userSchema);
<%_}_%>
<%_ if (locals.useSequelize) {_%>
let userModel = sequelize.define('User', {
    login: {
        type: Sequelize.STRING,
        allowNull: false
    },
    password: {
        type: Sequelize.STRING,
        allowNull: false
    },
    email: {
        type: Sequelize.STRING,
        allowNull: false
    },
    verified: {
        type: Sequelize.BOOLEAN,
        required: true
    },
    verifyLinkExpiration: {
        type: Sequelize.STRING
    },
    verifyToken: {
        type: Sequelize.STRING
    },
    status: {
        type: Sequelize.ENUM,
        values: ['ACTIVE', 'BLOCKED'],
        defaultValue: 'ACTIVE',
        allowNull: false
    },
}, {
    instanceMethods: {
        comparePasswordAsync: async function (candidatePassword) {
            return await bcrypt.compareAsync(candidatePassword || '', this.password);
        }
    }<commit_msg>added default value for verified property<commit_after>'use strict';

const promise = require('utils/promise'),
    <%_ if (locals.useMongo) {_%>
    mongoose = require('utils/mongoose'),
    <%_}_%>
    <%_ if (locals.useSequelize) {_%>
    sequelize = require('utils/sequelize'),
    Sequelize = require('sequelize'),
    <%_}_%>
    bcrypt = require('utils/bcrypt'),
    SALT_WORK_FACTOR = 10;

/**
 * User entity scheme.
 * @type {*|Schema}
 */

<%_ if (locals.useMongo) {_%>
let userSchema = new mongoose.Schema({
    login: {
        type: String,
        required: true,
        index: true,
        unique: true
    },
    password: {
        type: String,
        required: true
    },
    email: {
        type: String,
        required: true
    },
    status: {
        type: String,
        enum: ['ACTIVE', 'BLOCKED'],
        default: 'ACTIVE',
        required: true
    },
    verified: {
        type: Boolean,
        default: false,
        required: true
    },
    verifyLinkExpiration: {
        type: String
    },
    verifyToken: {
        type: String
    }
});

/**
 * Save-hook that fills password field with bcrypt hash.
 */
userSchema.pre('save', promise.asyncHook(async user => {

    if (!user.isModified('password')) {
        return;
    }

    user.password = await bcrypt.hashAsync(user.password, await bcrypt.genSaltAsync(SALT_WORK_FACTOR));
}));


/**
 * Verifies that password is equal to password of this user.
 * @param candidatePassword password to verify.
 * @return promised true if equals, false otherwise.
 */
userSchema.methods.comparePasswordAsync = async function (candidatePassword) {
    return await bcrypt.compareAsync(candidatePassword || '', this.password);
};

module.exports = mongoose.model('User', userSchema);
<%_}_%>
<%_ if (locals.useSequelize) {_%>
let userModel = sequelize.define('User', {
    login: {
        type: Sequelize.STRING,
        allowNull: false
    },
    password: {
        type: Sequelize.STRING,
        allowNull: false
    },
    email: {
        type: Sequelize.STRING,
        allowNull: false
    },
    verified: {
        type: Sequelize.BOOLEAN,
        defaultValue: false,
        required: true
    },
    verifyLinkExpiration: {
        type: Sequelize.STRING
    },
    verifyToken: {
        type: Sequelize.STRING
    },
    status: {
        type: Sequelize.ENUM,
        values: ['ACTIVE', 'BLOCKED'],
        defaultValue: 'ACTIVE',
        allowNull: false
    },
}, {
    instanceMethods: {
        comparePasswordAsync: async function (candidatePassword) {
            return await bcrypt.compareAsync(candidatePassword || '', this.password);
        }
    }
{'fraction_non_alphanumeric': 0.13340956737183152, 'fraction_numerical': 0.0007623403849818944, 'mean_word_length': 2.385806451612903, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, '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': '15627', 'n_tokens_mistral': 1629, 'n_tokens_neox': 1617, 'n_words': 353}