有没有人通过客户端在StrongLoop中扩展内置模型“user”?
问题是,我不能跳过新创建的客户端的验证。我已使用选项“emailVerificationRequired”声明客户端:false,但我仍然无法登录。
错误:
错误:对象代码:“LOGIN_FAILED_EMAIL_NOT_VERIFIED”消息:“登录 失败,因为电子邮件尚未验证“名称:”错误“堆栈: “错误:登录失败,因为电子邮件尚未经过验证 C:\ XAMPP \ htdocs中\回送工具入门\ node_modules \回环\ COMMON \型号\ user.js的:248:21↵ 在 C:\ XAMPP \ htdocs中\回送工具入门\ node_modules \回环\ COMMON \型号\ user.js的:312:9" 状态:401 statusCode:401
答案 0 :(得分:0)
如果您不希望电子邮件验证PUT,请参阅以下代码 模型config.json
"user": {
"dataSource": "YOUR DATASOURCE",
"public": true,
"options": {
"emailVerificationRequired": false
},
"$promise": {},
"$resolved": true}
另外一点是,你手动停止验证做到以下逻辑。 例如,如果用户是由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();
}
});