Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
✨ Add endpoint for password details
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Aug 28, 2020
1 parent 9558c36 commit 161b264
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/_staart/rest/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,22 @@ export const getMembershipsForUser = async (
throw new Error(INSUFFICIENT_PERMISSION);
};

export const getPasswordForUser = async (
tokenUserId: number,
dataUserId: number
) => {
if (
await can(tokenUserId, UserScopes.READ_USER_MEMBERSHIPS, "user", dataUserId)
) {
const user = await prisma.users.findOne({
where: { id: dataUserId },
});
if (!user) throw new Error(USER_NOT_FOUND);
return { hasPassword: !!user.password };
}
throw new Error(INSUFFICIENT_PERMISSION);
};

export const getAllDataForUser = async (
tokenUserId: number,
userId: number
Expand Down
8 changes: 8 additions & 0 deletions src/controllers/users/_id/security.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
regenerateBackupCodesForUser,
updatePasswordForUser,
verify2FAForUser,
getPasswordForUser,
} from "../../../_staart/rest/user";

@ClassMiddleware(authHandler)
Expand Down Expand Up @@ -53,6 +54,13 @@ export class UserSecurityController {
return respond(RESOURCE_UPDATED);
}

@Get("password")
async getPassword(req: Request, res: Response) {
const id = twtToId(req.params.id, res.locals.token.id);
joiValidate({ id: Joi.number().required() }, { id });
return getPasswordForUser(res.locals.token.id, id);
}

@Get("data")
async getUserData(req: Request, res: Response) {
const id = twtToId(req.params.id, res.locals.token.id);
Expand Down

0 comments on commit 161b264

Please sign in to comment.