mirror of
https://github.com/strapi/strapi.git
synced 2025-12-12 07:27:46 +00:00
Catch email error forgot password
This commit is contained in:
parent
74164aa38a
commit
2c43a856ce
@ -14,30 +14,26 @@ const sendmail = require('sendmail')({
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
send: (options, cb) => {
|
send: (options, cb) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
try {
|
// Default values.
|
||||||
// Default values.
|
options = _.isObject(options) ? options : {};
|
||||||
options = _.isObject(options) ? options : {};
|
options.from = 'admin-dashboard@your-strapi-app.com';
|
||||||
options.from = 'admin-dashboard@your-strapi-app.com';
|
options.text = options.text || options.html;
|
||||||
options.text = options.text || options.html;
|
options.html = options.html || options.text;
|
||||||
options.html = options.html || options.text;
|
|
||||||
|
|
||||||
// Send the email.
|
// Send the email.
|
||||||
sendmail({
|
sendmail({
|
||||||
from: options.from,
|
from: options.from,
|
||||||
to: options.to,
|
to: options.to,
|
||||||
subject: options.subject,
|
subject: options.subject,
|
||||||
text: options.text,
|
text: options.text,
|
||||||
html: options.html
|
html: options.html
|
||||||
}, function (err) {
|
}, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject([{ messages: [{ id: 'Auth.form.error.email.invalid' }] }]);
|
||||||
} else {
|
} else {
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (err) {
|
|
||||||
reject(err);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -30,6 +30,7 @@
|
|||||||
"Auth.form.register-success.email.placeholder": "mysuperemail@gmail.com",
|
"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.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.password.provide": "Please provide your password.",
|
||||||
"Auth.form.error.invalid": "Identifier or password invalid.",
|
"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.",
|
"Auth.form.error.password.local": "This user never set a local password, please login thanks to the provider used during account creation.",
|
||||||
|
|||||||
@ -30,6 +30,7 @@
|
|||||||
"Auth.form.register-success.email.placeholder": "mysuperemail@gmail.com",
|
"Auth.form.register-success.email.placeholder": "mysuperemail@gmail.com",
|
||||||
|
|
||||||
"Auth.form.error.email.provide": "Votre identifiant est manquant.",
|
"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.password.provide": "Votre mot de passe est manquant.",
|
||||||
"Auth.form.error.invalid": "Votre identifiant ou mot de passe est incorrect.",
|
"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.",
|
"Auth.form.error.password.local": "Ce compte n'a pas de mot de passe.",
|
||||||
|
|||||||
@ -122,17 +122,21 @@ module.exports = {
|
|||||||
// Set the property code.
|
// Set the property code.
|
||||||
user.resetPasswordToken = resetPasswordToken;
|
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.
|
// Update the user.
|
||||||
await strapi.query('user', 'users-permissions').update(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 });
|
ctx.send({ ok: true });
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user