underscore prefix verification fields

This commit is contained in:
Elliot DeNolf
2020-09-19 15:03:47 -04:00
parent c9d9d5269d
commit 0e15f8376c
9 changed files with 12 additions and 12 deletions

View File

@@ -11,5 +11,6 @@ module.exports = {
]
}
],
'no-underscore-dangle': 'off',
},
};

View File

@@ -32,7 +32,7 @@ async function login(args) {
const userDoc = await Model.findByUsername(email);
if (!userDoc || (args.collection.config.auth.emailVerification && !userDoc.verified)) {
if (!userDoc || (args.collection.config.auth.emailVerification && !userDoc._verified)) {
throw new AuthenticationError();
}
const authResult = await userDoc.authenticate(password);

View File

@@ -12,13 +12,13 @@ async function verifyEmail(args) {
// TODO: How do we know which collection this is?
const user = await args.collection.Model.findOne({
verificationToken: args.token,
_verificationToken: args.token,
});
if (!user) throw new APIError('User not found.', httpStatus.BAD_REQUEST);
user.verified = true;
user.verificationToken = null;
user._verified = true;
user._verificationToken = null;
await user.save();
}

View File

@@ -13,7 +13,7 @@ function sendVerificationEmail(args) {
if (!disableEmail) {
const url = collectionConfig.auth.generateVerificationUrl
? `${config.serverURL}${collectionConfig.auth.generateVerificationUrl(req, user.verificationToken)}`
? `${config.serverURL}${collectionConfig.auth.generateVerificationUrl(req, user._verificationToken)}`
: 'asdfasdf'; // TODO: point to payload view that verifies
const html = `Thank you for created an account.
Please click on the following link, or paste this into your browser to complete the process:

View File

@@ -17,7 +17,7 @@ module.exports = ({ operations }, { Model, config }) => {
},
},
{
verified: {
_verified: {
equals: true,
},
},

View File

@@ -27,7 +27,7 @@ module.exports = ({ config, collections, operations }) => {
},
},
{
verified: {
_verified: {
equals: true,
},
},

View File

@@ -24,7 +24,7 @@ function registerCollections() {
schema.path('hash').options.hide = true;
schema.path('salt').options.hide = true;
if (collection.auth.emailVerification) {
schema.add({ verificationToken: { type: String, hide: true } });
schema.add({ _verificationToken: { type: String, hide: true } });
}
}

View File

@@ -146,8 +146,8 @@ async function create(args) {
data.email = data.email.toLowerCase();
}
if (collectionConfig.auth.emailVerification) {
data.verified = false;
data.verificationToken = crypto.randomBytes(20).toString('hex');
data._verified = false;
data._verificationToken = crypto.randomBytes(20).toString('hex');
}
}

View File

@@ -239,8 +239,7 @@ const sanitizeCollection = (collections, collection) => {
}
if (collection.auth.emailVerification) {
authFields.push({
name: 'verified',
label: 'Verified',
name: '_verified',
type: 'checkbox',
hidden: true,
admin: {