enable password on invite or reset
This commit is contained in:
parent
ddb460f8d0
commit
0ea12eaafc
8 changed files with 61 additions and 32 deletions
|
@ -16,6 +16,7 @@ import UserService from "../service/management/userService";
|
|||
import CustomRequestException from "../exceptions/customRequestException";
|
||||
import InviteFactory from "../factory/admin/management/invite";
|
||||
import SettingHelper from "../helpers/settingsHelper";
|
||||
import { LoginRoutineEnum } from "../enums/loginRoutineEnum";
|
||||
|
||||
/**
|
||||
* @description get all invites
|
||||
|
@ -112,20 +113,26 @@ export async function verifyInvite(req: Request, res: Response): Promise<any> {
|
|||
*/
|
||||
export async function finishInvite(req: Request, res: Response, grantAdmin: boolean = false): Promise<any> {
|
||||
let mail = req.body.mail;
|
||||
let routine = req.body.routine;
|
||||
let token = req.body.token;
|
||||
let totp = req.body.totp;
|
||||
let passedSecret = req.body.secret;
|
||||
|
||||
let { secret, username, firstname, lastname } = await InviteService.getByMailAndToken(mail, token);
|
||||
|
||||
let valid = speakeasy.totp.verify({
|
||||
secret: secret,
|
||||
encoding: "base32",
|
||||
token: totp,
|
||||
window: 2,
|
||||
});
|
||||
let valid = false;
|
||||
if (routine == LoginRoutineEnum.totp) {
|
||||
valid = speakeasy.totp.verify({
|
||||
secret: secret,
|
||||
encoding: "base32",
|
||||
token: passedSecret,
|
||||
window: 2,
|
||||
});
|
||||
} else {
|
||||
valid = passedSecret != "";
|
||||
}
|
||||
|
||||
if (!valid) {
|
||||
throw new UnauthorizedRequestException("Token not valid or expired");
|
||||
throw new UnauthorizedRequestException("Credentials not valid or expired");
|
||||
}
|
||||
|
||||
let createUser: CreateUserCommand = {
|
||||
|
@ -133,8 +140,9 @@ export async function finishInvite(req: Request, res: Response, grantAdmin: bool
|
|||
firstname: firstname,
|
||||
lastname: lastname,
|
||||
mail: mail,
|
||||
secret: secret,
|
||||
secret: routine == LoginRoutineEnum.totp ? secret : passedSecret,
|
||||
isOwner: grantAdmin,
|
||||
routine,
|
||||
};
|
||||
let id = await UserCommandHandler.create(createUser);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue