From 4297cabd7ee3945e857dafeb5037306f34ebcc72 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sun, 29 Dec 2019 19:40:35 +0100 Subject: [PATCH] Can check out wheter user has setup security questions or not --- src/controllers/AccountController.ts | 16 ++++++++ src/controllers/Routes.ts | 2 + src/entities/User.ts | 55 +++++++++++++++++++++++++--- src/helpers/UserHelper.ts | 4 ++ 4 files changed, 71 insertions(+), 6 deletions(-) diff --git a/src/controllers/AccountController.ts b/src/controllers/AccountController.ts index d31e86f..57bd224 100644 --- a/src/controllers/AccountController.ts +++ b/src/controllers/AccountController.ts @@ -1,5 +1,6 @@ import { RequestHandler } from "../entities/RequestHandler"; import { AccountHelper } from "../helpers/AccountHelper"; +import { UserHelper } from "../helpers/UserHelper"; /** * Account controller @@ -78,4 +79,19 @@ export class AccountController { exists: await AccountHelper.ExistsEmail(email) }) } + + /** + * Check if an account associated with an email address has + * setup security questions or not + * + * @param h Request handler + */ + public static async HasSecurityQuestions(h: RequestHandler) { + const userID = await h.postUserIdFromEmail("email"); + const settings = await UserHelper.GetUserInfo(userID); + + h.send({ + defined: settings.hasSecurityQuestions + }) + } } \ No newline at end of file diff --git a/src/controllers/Routes.ts b/src/controllers/Routes.ts index f9af892..18facc9 100644 --- a/src/controllers/Routes.ts +++ b/src/controllers/Routes.ts @@ -45,6 +45,8 @@ export const Routes : Route[] = [ {path: "/account/exists_email", cb: (h) => AccountController.ExistsMail(h), needLogin: false}, + {path: "/account/has_security_questions", cb: (h) => AccountController.HasSecurityQuestions(h), needLogin: false}, + // User controller {path: "/user/getInfo", cb: (h) => UserController.GetSingle(h), needLogin: false}, diff --git a/src/entities/User.ts b/src/entities/User.ts index c7ce788..b43d976 100644 --- a/src/entities/User.ts +++ b/src/entities/User.ts @@ -12,7 +12,9 @@ export enum UserPageStatus { OPEN } -export interface UserBuilder { + + +export interface UserInfo { id: number, firstName: string, lastName: string, @@ -27,12 +29,20 @@ export interface UserBuilder { allowPostsFromFriends: boolean, } +export interface SecuritySettings { + id: number, + security_question_1 ?: string, + security_answer_1 ?: string, + security_question_2 ?: string, + security_answer_2 ?: string +} + + +export interface UserBuilder extends UserInfo, SecuritySettings { + +} + export class User implements UserBuilder { - friendsListPublic: boolean; - personnalWebsite?: string; - publicNote?: string; - blockComments: boolean; - allowPostsFromFriends: boolean; id: number; firstName: string; lastName: string; @@ -40,6 +50,16 @@ export class User implements UserBuilder { virtualDirectory: string; pageStatus: UserPageStatus; accountImage: AccountImage; + friendsListPublic: boolean; + personnalWebsite?: string; + publicNote?: string; + blockComments: boolean; + allowPostsFromFriends: boolean; + security_question_1?: string; + security_answer_1?: string; + security_question_2?: string; + security_answer_2?: string; + public constructor(info : UserBuilder) { for (const key in info) { @@ -62,4 +82,27 @@ export class User implements UserBuilder { && this.publicNote.length > 0 && this.publicNote != "null" } + + get hasSecurityQuestion1() : boolean { + return this.security_question_1 != null && this.security_question_1 && this.security_question_1.length > 0; + } + + + get hasSecurityAnswer1() : boolean { + return this.security_answer_1 != null && this.security_answer_1 && this.security_answer_1.length > 0; + } + + get hasSecurityQuestion2() : boolean { + return this.security_question_2 != null && this.security_question_2 != null && this.security_question_2 && this.security_question_2.length > 0; + } + + + get hasSecurityAnswer2() : boolean { + return this.security_answer_2 != null && this.security_answer_2 && this.security_answer_2.length > 0; + } + + get hasSecurityQuestions() : boolean { + return (this.hasSecurityQuestion1 && this.hasSecurityAnswer1 + && this.hasSecurityQuestion2 && this.hasSecurityAnswer2) == true; + } } \ No newline at end of file diff --git a/src/helpers/UserHelper.ts b/src/helpers/UserHelper.ts index d36e71d..66b6039 100644 --- a/src/helpers/UserHelper.ts +++ b/src/helpers/UserHelper.ts @@ -184,6 +184,10 @@ export class UserHelper { publicNote: row.public_note, blockComments: row.bloquecommentaire == 1, allowPostsFromFriends: row.autoriser_post_amis == 1, + security_question_1: row.question1, + security_answer_1: row.reponse1, + security_question_2: row.question2, + security_answer_2: row.reponse2 }); } } \ No newline at end of file