conditionally add email verification fields to schema

This commit is contained in:
Elliot DeNolf
2020-09-15 14:05:02 -04:00
parent 55488c5c2e
commit f20feae4d9
3 changed files with 15 additions and 2 deletions

View File

@@ -23,6 +23,10 @@ function registerCollections() {
schema.plugin(passportLocalMongoose, { usernameField: 'email' });
schema.path('hash').options.hide = true;
schema.path('salt').options.hide = true;
if (collection.auth.emailVerification) {
schema.add({ verified: { type: Boolean, hide: true } });
schema.add({ verificationToken: { type: String, hide: true } });
}
}
schema.plugin(mongooseHidden);

View File

@@ -138,8 +138,15 @@ async function create(args) {
result.setLocale(locale, fallbackLocale);
}
if (collectionConfig.auth && data.email) {
data.email = data.email.toLowerCase();
if (collectionConfig.auth) {
if (data.email) {
data.email = data.email.toLowerCase();
}
if (collectionConfig.auth.emailVerification) {
data.verified = false;
data.verificationToken = 'asdf'; // TODO: Use bcrypt
// TODO: Generate and send email
}
}
Object.assign(result, data);