33 lines
943 B
TypeScript
33 lines
943 B
TypeScript
|
|
import { CryptIO } from "../../../crypt/CryptIO";
|
||
|
|
import { RJLog } from "../../../log/RJLog";
|
||
|
|
import { RequestHandler, RequestType } from "../../RequestHandler";
|
||
|
|
import { FastifyRequest, FastifyReply } from 'fastify';
|
||
|
|
|
||
|
|
export class ChangePasswordHandler extends RequestHandler
|
||
|
|
{
|
||
|
|
static url = "/change-password";
|
||
|
|
constructor(){ super( RequestType.POST, ChangePasswordHandler.url ); }
|
||
|
|
|
||
|
|
async _handle( request:FastifyRequest, reply:FastifyReply )
|
||
|
|
{
|
||
|
|
let requestBody = request.body;
|
||
|
|
let { id, password, token } = requestBody as { id: string; password:string, token: string, };
|
||
|
|
|
||
|
|
if ( ! id || ! token || ! password)
|
||
|
|
{
|
||
|
|
return this.sendError( "Missing id, token or password" );
|
||
|
|
}
|
||
|
|
|
||
|
|
let result = await this.userDB.changePassword( id, token, password, this.ip );
|
||
|
|
|
||
|
|
if ( ! result )
|
||
|
|
{
|
||
|
|
return this.sendError( "Password change failed" );
|
||
|
|
}
|
||
|
|
|
||
|
|
return this.sendInfo( "Changed password" );
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
}
|