Skip to content

Commit 26568bd

Browse files
alainabbastacxou
authored andcommitted
save
1 parent c72f4fc commit 26568bd

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/management/passwd/dto/reset-by-code-dto.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@ export class ResetByCodeDto {
99
@IsNumber
1010
@ApiProperty({ example: '123456', description: 'Code received by email or Sms' })
1111
code: number;
12+
@IsString()
13+
@ApiProperty({ example: 'hdfddyf18A', description: 'new password' })
14+
newpassword: string;
15+
1216
}

src/management/passwd/passwd.service.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,31 @@ export class PasswdService extends AbstractService {
262262
}
263263
}
264264
public async resetByCode(data:ResetByCodeDto):Promise<[Jobs,any]>{
265+
const tokenData=await this.decryptTokenWithCode(data.token,data.code)
266+
try{
267+
const identity = await this.identities.findOne({ 'inetOrgPerson.uid': tokenData.uid }) as Identities;
268+
const [_, response] = await this.backends.executeJob(
269+
ActionType.IDENTITY_PASSWORD_RESET,
270+
identity._id,
271+
{ uid: tokenData.uid, newPassword: data.newPassword, ...pick(identity, ['inetOrgPerson']) },
272+
{
273+
async: false,
274+
timeoutDiscard: true,
275+
disableLogs: true,
276+
updateStatus: false,
277+
},
278+
);
265279

280+
if (response?.status === 0) {
281+
await this.redis.del(data.token);
282+
return [_, response];
283+
}
284+
this.logger.error("Error from backend while reseting password by code" );
285+
throw new InternalServerErrorException('Une erreur est survenue : Impossible de réinitialiser le mot de passe');
286+
}catch (e) {
287+
this.logger.error("Error while reseting password by code. " + e + ` (token=${data?.token})`);
288+
throw new BadRequestException('Une erreur est survenue : Tentative de réinitialisation de mot de passe impossible');
289+
}
266290
}
267291
public async reset(data: ResetPasswordDto): Promise<[Jobs, any]> {
268292
const tokenData = await this.decryptToken(data.token);

0 commit comments

Comments
 (0)