From 95069423f59821b14d9348c429dc1ffdff1542a6 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Mon, 30 Dec 2019 08:16:10 +0100 Subject: [PATCH] Can get security questions of the user --- src/controllers/AccountController.ts | 21 +++++++++++++++++++++ src/controllers/Routes.ts | 2 ++ 2 files changed, 23 insertions(+) diff --git a/src/controllers/AccountController.ts b/src/controllers/AccountController.ts index 57bd224..94d146e 100644 --- a/src/controllers/AccountController.ts +++ b/src/controllers/AccountController.ts @@ -94,4 +94,25 @@ export class AccountController { defined: settings.hasSecurityQuestions }) } + + /** + * Get the security questions of a user, in order to reset its + * password + * + * @param h Request handler + */ + public static async GetSecurityQuestions(h: RequestHandler) { + const userID = await h.postUserIdFromEmail("email"); + const settings = await UserHelper.GetUserInfo(userID); + + if(!settings.hasSecurityQuestions) + h.error(401, "Specified user has not setup security questions !"); + + h.send({ + questions: [ + settings.security_question_1, + settings.security_question_2 + ] + }) + } } \ No newline at end of file diff --git a/src/controllers/Routes.ts b/src/controllers/Routes.ts index 18facc9..0533ab0 100644 --- a/src/controllers/Routes.ts +++ b/src/controllers/Routes.ts @@ -47,6 +47,8 @@ export const Routes : Route[] = [ {path: "/account/has_security_questions", cb: (h) => AccountController.HasSecurityQuestions(h), needLogin: false}, + {path: "/account/get_security_questions", cb: (h) => AccountController.GetSecurityQuestions(h), needLogin: false}, + // User controller {path: "/user/getInfo", cb: (h) => UserController.GetSingle(h), needLogin: false},