mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-12-29 06:58:51 +00:00
Can set security questions
This commit is contained in:
parent
e1dae7f2f6
commit
e06fc281aa
@ -93,6 +93,8 @@ export const Routes : Route[] = [
|
||||
|
||||
{path: "/settings/get_security", cb: (h) => SettingsController.GetSecurity(h)},
|
||||
|
||||
{path: "/settings/set_security", cb: (h) => SettingsController.SetSecurity(h)},
|
||||
|
||||
|
||||
// Friends controller
|
||||
{path: "/friends/getList", cb: (h) => FriendsController.GetList(h)},
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
import { RequestHandler } from "../entities/RequestHandler";
|
||||
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 { checkVirtualDirectoryAvailability, VirtualDirType } from "../utils/VirtualDirsUtils";
|
||||
import { AccountHelper } from "../helpers/AccountHelper";
|
||||
@ -148,10 +148,31 @@ export class SettingsController {
|
||||
|
||||
h.send({
|
||||
id: userInfo.id,
|
||||
security_question_1: userInfo.hasSecurityQuestion1 ? fixEncoding(userInfo.security_question_1) : "",
|
||||
security_answer_1: userInfo.hasSecurityAnswer1 ? fixEncoding(userInfo.security_answer_1) : "",
|
||||
security_question_2: userInfo.hasSecurityQuestion2 ? fixEncoding(userInfo.security_question_2) : "",
|
||||
security_answer_2: userInfo.hasSecurityAnswer2 ? fixEncoding(userInfo.security_answer_2) : "",
|
||||
security_question_1: userInfo.hasSecurityQuestion1 ? userInfo.security_question_1 : "",
|
||||
security_answer_1: userInfo.hasSecurityAnswer1 ? userInfo.security_answer_1 : "",
|
||||
security_question_2: userInfo.hasSecurityQuestion2 ? userInfo.security_question_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();
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@ import { DatabaseHelper } from "./DatabaseHelper";
|
||||
import { UserHelper } from "./UserHelper";
|
||||
import { time, mysql_date } from "../utils/DateUtils";
|
||||
import { NewAccount } from "../entities/NewAccount";
|
||||
import { GeneralSettings, UserPageStatus, LangSettings } from "../entities/User";
|
||||
import { GeneralSettings, UserPageStatus, LangSettings, SecuritySettings } from "../entities/User";
|
||||
|
||||
/**
|
||||
* 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
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user