1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-26 07:19:23 +00:00

Can set security questions

This commit is contained in:
Pierre HUBERT 2020-03-22 14:18:59 +01:00
parent e1dae7f2f6
commit e06fc281aa
3 changed files with 49 additions and 6 deletions

View File

@ -93,6 +93,8 @@ export const Routes : Route[] = [
{path: "/settings/get_security", cb: (h) => SettingsController.GetSecurity(h)}, {path: "/settings/get_security", cb: (h) => SettingsController.GetSecurity(h)},
{path: "/settings/set_security", cb: (h) => SettingsController.SetSecurity(h)},
// Friends controller // Friends controller
{path: "/friends/getList", cb: (h) => FriendsController.GetList(h)}, {path: "/friends/getList", cb: (h) => FriendsController.GetList(h)},

View File

@ -6,7 +6,7 @@
import { RequestHandler } from "../entities/RequestHandler"; import { RequestHandler } from "../entities/RequestHandler";
import { UserHelper } from "../helpers/UserHelper"; import { UserHelper } from "../helpers/UserHelper";
import { GeneralSettings, UserPageStatus, SupportedLanguages, LangSettings } from "../entities/User"; import { GeneralSettings, UserPageStatus, SupportedLanguages, LangSettings, SecuritySettings } from "../entities/User";
import { removeHTMLNodes, checkURL, fixEncoding } from "../utils/StringUtils"; import { removeHTMLNodes, checkURL, fixEncoding } from "../utils/StringUtils";
import { checkVirtualDirectoryAvailability, VirtualDirType } from "../utils/VirtualDirsUtils"; import { checkVirtualDirectoryAvailability, VirtualDirType } from "../utils/VirtualDirsUtils";
import { AccountHelper } from "../helpers/AccountHelper"; import { AccountHelper } from "../helpers/AccountHelper";
@ -148,10 +148,31 @@ export class SettingsController {
h.send({ h.send({
id: userInfo.id, id: userInfo.id,
security_question_1: userInfo.hasSecurityQuestion1 ? fixEncoding(userInfo.security_question_1) : "", security_question_1: userInfo.hasSecurityQuestion1 ? userInfo.security_question_1 : "",
security_answer_1: userInfo.hasSecurityAnswer1 ? fixEncoding(userInfo.security_answer_1) : "", security_answer_1: userInfo.hasSecurityAnswer1 ? userInfo.security_answer_1 : "",
security_question_2: userInfo.hasSecurityQuestion2 ? fixEncoding(userInfo.security_question_2) : "", security_question_2: userInfo.hasSecurityQuestion2 ? userInfo.security_question_2 : "",
security_answer_2: userInfo.hasSecurityAnswer2 ? fixEncoding(userInfo.security_answer_2) : "", security_answer_2: userInfo.hasSecurityAnswer2 ? userInfo.security_answer_2 : "",
}); });
} }
/**
* Set security settings
*
* @param h Request handler
*/
public static async SetSecurity(h: RequestHandler) {
await h.needUserPostPassword("password");
const newSettings: SecuritySettings = {
id: h.getUserId(),
security_question_1: removeHTMLNodes(h.postString("security_question_1", 0)),
security_answer_1: removeHTMLNodes(h.postString("security_answer_1", 0)),
security_question_2: removeHTMLNodes(h.postString("security_question_2", 0)),
security_answer_2: removeHTMLNodes(h.postString("security_answer_2", 0))
}
await AccountHelper.SetSecuritySettings(newSettings);
h.success();
}
} }

View File

@ -5,7 +5,7 @@ import { DatabaseHelper } from "./DatabaseHelper";
import { UserHelper } from "./UserHelper"; import { UserHelper } from "./UserHelper";
import { time, mysql_date } from "../utils/DateUtils"; import { time, mysql_date } from "../utils/DateUtils";
import { NewAccount } from "../entities/NewAccount"; import { NewAccount } from "../entities/NewAccount";
import { GeneralSettings, UserPageStatus, LangSettings } from "../entities/User"; import { GeneralSettings, UserPageStatus, LangSettings, SecuritySettings } from "../entities/User";
/** /**
* Account helper * Account helper
@ -354,4 +354,24 @@ export class AccountHelper {
} }
}); });
} }
/**
* Update (set) new security settings
*
* @param settings New settings
*/
public static async SetSecuritySettings(settings: SecuritySettings) {
await DatabaseHelper.UpdateRows({
table: USER_TABLE,
where: {
ID: settings.id
},
set: {
question1: settings.security_question_1,
reponse1: settings.security_answer_1,
question2: settings.security_question_2,
reponse2: settings.security_answer_2
}
});
}
} }