underscore prefix verification fields
This commit is contained in:
@@ -11,5 +11,6 @@ module.exports = {
|
||||
]
|
||||
}
|
||||
],
|
||||
'no-underscore-dangle': 'off',
|
||||
},
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -17,7 +17,7 @@ module.exports = ({ operations }, { Model, config }) => {
|
||||
},
|
||||
},
|
||||
{
|
||||
verified: {
|
||||
_verified: {
|
||||
equals: true,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -27,7 +27,7 @@ module.exports = ({ config, collections, operations }) => {
|
||||
},
|
||||
},
|
||||
{
|
||||
verified: {
|
||||
_verified: {
|
||||
equals: true,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -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 } });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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: {
|
||||
|
||||
Reference in New Issue
Block a user