diff --git a/back/methods/account/recover-password.js b/back/methods/account/recover-password.js index 54ccc56bc..b0923b61b 100644 --- a/back/methods/account/recover-password.js +++ b/back/methods/account/recover-password.js @@ -31,7 +31,7 @@ module.exports = Self => { }); if (!user) - throw new UserError(`This email does not belong to a user`); + return; const token = await models.AccessToken.create({ ttl: ttl, @@ -54,7 +54,5 @@ module.exports = Self => { title, body ]); - - return; }; }; diff --git a/back/methods/account/specs/recover-password.spec.js b/back/methods/account/specs/recover-password.spec.js index 2917b3e56..82d0d8e59 100644 --- a/back/methods/account/specs/recover-password.spec.js +++ b/back/methods/account/specs/recover-password.spec.js @@ -10,17 +10,6 @@ describe('account recoverPassword()', () => { return value; }; - it('should throw an error when email does not belong to a user', async() => { - let error; - try { - await models.Account.recoverPassword(ctx, 'thor@mydomain.com'); - } catch (e) { - error = e; - } - - expect(error.message).toEqual('This email does not belong to a user'); - }); - it('should update password when it passes requirements', async() => { const user = await models.Account.findById(1107); await models.Account.recoverPassword(ctx, user.email); diff --git a/back/models/account.js b/back/models/account.js index 506dc37ac..42618e322 100644 --- a/back/models/account.js +++ b/back/models/account.js @@ -1,5 +1,7 @@ /* eslint max-len: ["error", { "code": 150 }]*/ const md5 = require('md5'); +const app = require('../../loopback/server/server.js'); +const dataSources = require('../../loopback/server/datasources.json'); const LoopBackContext = require('loopback-context'); module.exports = Self => { @@ -29,7 +31,8 @@ module.exports = Self => { ctx.data.password = md5(ctx.data.password); }); - Self.observe('before save', async ctx => { + Self.observe('before save', async(ctx, instance) => { + console.log(instance); const models = Self.app.models; const loopBackContext = LoopBackContext.getCurrentContext(); const changes = ctx.data || ctx.instance; @@ -55,12 +58,22 @@ module.exports = Self => { ${title} `; - result = await Self.rawSql(`CALL vn.mail_insert(?,?,?,?)`, [ - changes.email, - null, - title, - body - ], ctx.options); + const url = app.get('rootUrl') || app.get('url'); + console.log(app.get('rootUrl')); + console.log(app.get('url')); + const options = { + type: 'email', + to: instance.email, + from: 'dataSources.email.settings.transports[0].auth.from', + subject: title, + template: body, + redirect: `${origin}#/login/${instance.email}?emailConfirmed`, + host: url.hostname, + port: url.port, + protocol: url.protocol.split(':')[0], + user: Self + }; + instance.verify(options); }); Self.remoteMethod('getCurrentUserData', { diff --git a/front/salix/components/app/app.js b/front/salix/components/app/app.js index 3990aac13..7af43d325 100644 --- a/front/salix/components/app/app.js +++ b/front/salix/components/app/app.js @@ -15,7 +15,7 @@ export default class App extends Component { get showLayout() { let state = this.$state.current.name; - return state && !state.includes('login'); + return state && state != 'login' && !this.isRecover; } get isRecover() { diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 36403a1ed..e2bb9bdf1 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -233,11 +233,10 @@ "Descanso diario 12h.": "Descanso diario 12h.", "Descanso semanal 36h. / 72h.": "Descanso semanal 36h. / 72h.", "Dirección incorrecta": "Dirección incorrecta", - "This email does not belong to a user": "Este correo electrónico no pertenece a un usuario.", "Recover password": "Recuperar contraseña", "Click on the following link to change your password.": "Pulsa en el siguiente link para cambiar tu contraseña.", "Verify email": "Verificar correo", "Click on the following link to verify this email. If you haven't requested this email, just ignore it": "Pulsa en el siguiente link para verificar este correo. Si no has pedido este correo, simplemente ignóralo.", "Click on the following link to change your password": "Click on the following link to change your password", "Landing cannot be lesser than shipment": "Landing cannot be lesser than shipment" -} \ No newline at end of file +}