StrongLoop 客户端扩展用户模型内置登录报错
StrongLoop Client extending User Model Built-in log in error
有没有人体验过通过客户端在 StrongLoop 中扩展内置模型 "user"?
问题是,我不能跳过对新创建的客户端的验证。我已经使用选项 "emailVerificationRequired": false 声明了客户端,但我仍然无法登录。
错误:
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();
}
});
有没有人体验过通过客户端在 StrongLoop 中扩展内置模型 "user"?
问题是,我不能跳过对新创建的客户端的验证。我已经使用选项 "emailVerificationRequired": false 声明了客户端,但我仍然无法登录。
错误:
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();
}
});