Has anyone experienced extending the built-in model "user" in StrongLoop via Client?
The thing is, I can't skip the verification for the newly created clients. I have declared the Client with the option "emailVerificationRequired": false, but still I can't log in.
Error:
error: Object code: "LOGIN_FAILED_EMAIL_NOT_VERIFIED" message: "login failed as the email has not been verified" name: "Error" stack: "Error: login failed as the email has not been verified↵ at C:\xampp\htdocs\loopback-getting-started\node_modules\loopback\common\models\user.js:248:21↵ at C:\xampp\htdocs\loopback-getting-started\node_modules\loopback\common\models\user.js:312:9" status: 401 statusCode: 401
If you don't want email verification PUT below code in model-config.json
"user": {
"dataSource": "YOUR DATASOURCE",
"public": true,
"options": {
"emailVerificationRequired": false
},
"$promise": {},
"$resolved": true}
And other thing is, you manually stop verification doing below logic. For example if users created by Admin.
user.beforeRemote('create' ,function(ctx, modelInstance, next)
{
if(ctx.req.query.key == "admin") // if users created by Admin.
{
ctx.args.data.emailVerified = 1;
}
next();
});
IN afterRemote
user.afterRemote('create', function(context, user, next) {
if(!user.emailVerified)
{
console.log('> user.afterRemote triggered');
var options = {
type: 'email',
to: user.email,
from: 'youremail,
subject: 'Thanks for registering.',
template: path.resolve(__dirname, '../../server/views/verify.ejs'),
redirect: '/verified',
user: user
};
user.verify(options, function(err, response) {
if (err) return next(err);
context.res.render('response', {
title: 'Signed up successfully',
content: 'Please check your email and click on the verification link ' +
'before logging in.',
redirectTo: '/',
redirectToLinkText: 'Log in'
});
});
}
else
{
next();
}
});