Catch email error forgot password

This commit is contained in:
Jim Laurie 2017-12-04 14:00:09 +01:00
parent 74164aa38a
commit 2c43a856ce
4 changed files with 33 additions and 31 deletions

View File

@ -14,30 +14,26 @@ const sendmail = require('sendmail')({
module.exports = {
send: (options, cb) => {
return new Promise((resolve, reject) => {
try {
// Default values.
options = _.isObject(options) ? options : {};
options.from = 'admin-dashboard@your-strapi-app.com';
options.text = options.text || options.html;
options.html = options.html || options.text;
// Default values.
options = _.isObject(options) ? options : {};
options.from = 'admin-dashboard@your-strapi-app.com';
options.text = options.text || options.html;
options.html = options.html || options.text;
// Send the email.
sendmail({
from: options.from,
to: options.to,
subject: options.subject,
text: options.text,
html: options.html
}, function (err) {
if (err) {
reject(err);
} else {
resolve();
}
});
} catch (err) {
reject(err);
}
// Send the email.
sendmail({
from: options.from,
to: options.to,
subject: options.subject,
text: options.text,
html: options.html
}, function (err) {
if (err) {
reject([{ messages: [{ id: 'Auth.form.error.email.invalid' }] }]);
} else {
resolve();
}
});
});
}
};

View File

@ -30,6 +30,7 @@
"Auth.form.register-success.email.placeholder": "mysuperemail@gmail.com",
"Auth.form.error.email.provide": "Please provide your username or your e-mail.",
"Auth.form.error.email.invalid": "This e-mail is invalid.",
"Auth.form.error.password.provide": "Please provide your password.",
"Auth.form.error.invalid": "Identifier or password invalid.",
"Auth.form.error.password.local": "This user never set a local password, please login thanks to the provider used during account creation.",

View File

@ -30,6 +30,7 @@
"Auth.form.register-success.email.placeholder": "mysuperemail@gmail.com",
"Auth.form.error.email.provide": "Votre identifiant est manquant.",
"Auth.form.error.email.invalid": "Cette e-mail n'est pas valide.",
"Auth.form.error.password.provide": "Votre mot de passe est manquant.",
"Auth.form.error.invalid": "Votre identifiant ou mot de passe est incorrect.",
"Auth.form.error.password.local": "Ce compte n'a pas de mot de passe.",

View File

@ -122,17 +122,21 @@ module.exports = {
// Set the property code.
user.resetPasswordToken = resetPasswordToken;
// Send an email to the user.
try {
await strapi.plugins['email'].services.email.send({
to: user.email,
subject: 'Reset password',
text: url + '?code=' + resetPasswordToken,
html: url + '?code=' + resetPasswordToken
});
} catch (err) {
return ctx.badRequest(null, err);
}
// Update the user.
await strapi.query('user', 'users-permissions').update(user);
// Send an email to the user.
await strapi.plugins['email'].services.email.send({
to: user.email,
subject: 'Reset password',
text: url + '?code=' + resetPasswordToken,
html: url + '?code=' + resetPasswordToken
});
ctx.send({ ok: true });
},