conditionally add email verification fields to schema
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user