1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-25 23:09:22 +00:00

Can check out wheter user has setup security questions or not

This commit is contained in:
Pierre HUBERT 2019-12-29 19:40:35 +01:00
parent 5b6ad59486
commit 4297cabd7e
4 changed files with 71 additions and 6 deletions

View File

@ -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
})
}
}

View File

@ -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},

View File

@ -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;
}
}

View File

@ -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
});
}
}