Minor code cleanup

This commit is contained in:
rijkvanzanten
2020-12-16 16:57:26 -05:00
parent 651263cbde
commit bbae89d633
2 changed files with 5 additions and 6 deletions

View File

@@ -167,9 +167,9 @@ router.post(
};
const service = new UsersService({ accountability, schema: req.schema });
try {
await service.requestPasswordReset(req.body.email, req.body.reset_url);
await service.requestPasswordReset(req.body.email, req.body.reset_url || null);
} catch {
// We don't want to give away what email addresses exist, so we'll always return a 200
// from this endpoint

View File

@@ -115,15 +115,14 @@ export class UsersService extends ItemsService {
}
}
async requestPasswordReset(email: string, url: string) {
async requestPasswordReset(email: string, url: string | null) {
const user = await this.knex.select('id').from('directus_users').where({ email }).first();
if (!user) throw new ForbiddenException();
const payload = { email, scope: 'password-reset' };
const token = jwt.sign(payload, env.SECRET as string, { expiresIn: '1d' });
let acceptURL = env.PUBLIC_URL + '/admin/reset-password?token=' + token
if(url && url !== '') acceptURL = url + '?token=' + token
const acceptURL = url ? `${url}?token=${token}` : `${env.PUBLIC_URL}/admin/reset-password?token=${token}`;
await sendPasswordResetMail(email, acceptURL);
}