当前服务器堆栈为:
-服务器操作系统-Ubuntu 16.04
-Web服务器-NGINX
-服务器应用程序-Loopback.js和PM2
-数据库-MariaDB
这是我在本地运行服务器时收到的错误消息:
Web服务器在以下位置监听:http://0.0.0.0:3000(节点:3683) UnhandledPromiseRejectionWarning:ValidationError:
Account
实例无效。详细信息:
尽管出现此错误消息,我仍然能够登录,检索报告等。但是,我不能(本地/远程)做的一件事是使用该服务发送请求以重置用户密码。除了此错误外,当我尝试访问http://0.0.0.0:3000时,还会收到404错误。这使我相信webserver / webpage /未正确加载。
“视图”文件夹中目前有3个文件:
generic-message.pug
reset-password-email.pug
reset-password-form.pug。
这是routes.js文件:
module.exports = function (app) {
var Account = app.models.Account;
if (app.get('includeTestRoutes')) {
app.get('/api/request-password-reset', function (req, res) {
app.models.Email.send({
to: 'someguy@someplace.com',
from: 'support@someplace.com',
subject: 'my subject',
text: 'my text',
html: 'my <em>html</em>'
}, function (err, mail) {
if (err) {
return res.status(401).json(err);
}
return res.json({ 'status': 'OK' });
});
});
app.get('/email-preview', function (req, res) {
var host = app.get('publicUrl') ? app.get('publicUrl') : app.get('host');
var actionUrl = 'http://' + host;
actionUrl += app.get('publicPort') ? ':' + app.get('publicPort') : '';
actionUrl += '/reset-password-form';
res.render('reset-password-email', {
name: 'John Smith',
supportUrl: 'https://someplace.zendesk.com/hc/en-us',
productName: 'someplace',
companyName: 'someplace sometime',
actionUrl: actionUrl
});
});
}
app.get('/reset-password-form', function (req, res) {
// res.render( 'reset-password-form' );
if (!req.accessToken) {
return res.sendStatus(401);
}
res.render('reset-password-form', {
redirectUrl: '/reset-password?access_token=' + req.accessToken.id
});
});
app.post('/reset-password', function (req, res) {
//TODO: Refactor this later so it doesn't check via a hardcoded value
if (!req.body.password || req.body.password.toString().length < 4) {
res.render('generic-message', {
title: 'Password reset',
text: 'Failed to reset password. Make sure the new password is at least 4 letters long.'
});
}
else if (req.body.password && !req.body.confirm_password || req.body.password !== req.body.confirm_password) {
res.render('generic-message', {
title: 'Password reset',
text: 'Failed to reset password. Make sure both the password and password confirmation fields have the same value.'
});
}
else {
Account.findById(req.accessToken.userId, function (err, user) {
if (err) {
return res.sendStatus(404);
}
user.updateAttribute('password', req.body.password, function (err, user) {
if (err) {
return res.sendStatus(404);
}
console.log('> password reset processed successfully');
res.render('generic-message', {
title: 'Password reset',
text: 'You have successfully reset your password!'
});
});
});
}
});
app.post('/api/reset-password-request', function (req, res) {
Account.resetPassword({
email: req.body.email
}, function (err) {
console.log(err);
if (err) {
return res.status(err.statusCode).json({ code: err.code });
}
return res.json({ 'code': 'OK' });
});
});
}