mirror of
https://github.com/directus/directus.git
synced 2026-01-23 07:28:03 -05:00
Minor code cleanup
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user