mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-11-22 12:09:21 +00:00
Can send request to delete user accounts
This commit is contained in:
parent
e55614b4c8
commit
d6413887c2
@ -3,3 +3,7 @@
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
|
||||
.box-delete-account-settings .btn {
|
||||
float: right;
|
||||
}
|
@ -598,6 +598,13 @@ var ComunicWeb = {
|
||||
//TODO : implement
|
||||
},
|
||||
|
||||
/**
|
||||
* Settings helper
|
||||
*/
|
||||
helper: {
|
||||
//TODO : implement
|
||||
},
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -62,7 +62,7 @@ ComunicWeb.common.messages.createLoadingCallout = function(target){
|
||||
*
|
||||
* @param {object} info Information about the callout to create
|
||||
* @argument {string} type The type of modal
|
||||
* @param {string} title The title of the modal
|
||||
* @argument {string} title The title of the modal
|
||||
* @return {object} Information about the created dialog
|
||||
*/
|
||||
ComunicWeb.common.messages.createDialogSkeleton = function(info){
|
||||
|
@ -31,4 +31,18 @@ ComunicWeb.components.account.interface = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Request the deletion of the account
|
||||
*
|
||||
* @param {string} password The password of the account
|
||||
* @param {function} callback
|
||||
*/
|
||||
deleteAccount: function(password, callback){
|
||||
var apiURI = "account/delete";
|
||||
var params = {
|
||||
password: password
|
||||
};
|
||||
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
|
||||
},
|
||||
|
||||
}
|
122
assets/js/components/settings/helper.js
Normal file
122
assets/js/components/settings/helper.js
Normal file
@ -0,0 +1,122 @@
|
||||
/**
|
||||
* Settings helper
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
|
||||
ComunicWeb.components.settings.helper = {
|
||||
|
||||
/**
|
||||
* Request user account deletion
|
||||
*/
|
||||
requestAccountDeletion: function(){
|
||||
|
||||
//Prompt user confirmation
|
||||
ComunicWeb.common.messages.confirm("Do you really want to delete your account ? This operation can not be reverted !", function(r){
|
||||
|
||||
//Check if the user cancelled the operation
|
||||
if(!r) return;
|
||||
|
||||
//Prompt user password
|
||||
var dialog = ComunicWeb.common.messages.createDialogSkeleton({
|
||||
type: "danger",
|
||||
title: "Password required"
|
||||
});
|
||||
$(dialog.modal).modal("show");
|
||||
|
||||
//Create modal close function
|
||||
var closeModal = function(){
|
||||
$(dialog.modal).modal("hide");
|
||||
emptyElem(dialog.modal);
|
||||
dialog.modal.remove();
|
||||
};
|
||||
dialog.cancelButton.addEventListener("click", closeModal);
|
||||
dialog.closeModal.addEventListener("click", closeModal);
|
||||
|
||||
//Set dialog body
|
||||
var passwordForm = createElem2({
|
||||
appendTo: dialog.modalBody,
|
||||
type: "div"
|
||||
});
|
||||
|
||||
createElem2({
|
||||
appendTo: passwordForm,
|
||||
type: "p",
|
||||
innerHTML: "We need your password to continue. Note: once you click 'Confirm', you will not be able to go back..."
|
||||
});
|
||||
|
||||
//Create pasword input group
|
||||
var inputGroup = createElem2({
|
||||
appendTo: passwordForm,
|
||||
type: "div",
|
||||
class: "input-group input-group-sm"
|
||||
});
|
||||
|
||||
//Create password input
|
||||
var passwordInput = createElem2({
|
||||
appendTo: inputGroup,
|
||||
type: "input",
|
||||
class: "form-control",
|
||||
elemType: "password"
|
||||
});
|
||||
|
||||
//Create input group
|
||||
var inputGroupContainer = createElem2({
|
||||
appendTo: inputGroup,
|
||||
type: "span",
|
||||
class: "input-group-btn"
|
||||
});
|
||||
|
||||
//Add submit button
|
||||
var submitButton = createElem2({
|
||||
appendTo: inputGroupContainer,
|
||||
type: "button",
|
||||
class: "btn btn-danger",
|
||||
innerHTML: "Confirm deletion"
|
||||
});
|
||||
|
||||
submitButton.addEventListener("click", function(e){
|
||||
|
||||
//Check given password
|
||||
var password = passwordInput.value;
|
||||
if(password.length < 4)
|
||||
return notify("Please check given password !", "danger");
|
||||
|
||||
//Close modal
|
||||
closeModal();
|
||||
|
||||
//Perform a request over the interface
|
||||
ComunicWeb.components.settings.helper.deleteAccount(password);
|
||||
});
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Delete the account of the user
|
||||
*
|
||||
* @param {string} password The password of the account to delete
|
||||
*/
|
||||
deleteAccount: function(password){
|
||||
|
||||
//Lock the screen with a loading splash screen
|
||||
var splashScreen = ComunicWeb.common.page.showTransparentWaitSplashScreen();
|
||||
|
||||
//Perform the request over the interface
|
||||
ComunicWeb.components.account.interface.deleteAccount(password, function(result){
|
||||
|
||||
//Remove loading splash screen
|
||||
splashScreen.remove();
|
||||
|
||||
//Check for errors
|
||||
if(result.error)
|
||||
return notify("Could not delete your account (please check given password) !", "danger");
|
||||
|
||||
//Restart the page in case of success
|
||||
ComunicWeb.common.system.restart();
|
||||
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
}
|
@ -13,12 +13,24 @@ ComunicWeb.pages.settings.sections.privacy = {
|
||||
* @param {HTMLElement} target The target for the page
|
||||
*/
|
||||
open: function(args, target){
|
||||
|
||||
//Delete account box
|
||||
this.showDeleteAccountBox(target);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Display delete account box
|
||||
*
|
||||
* @param {HTMLElement} target The target for the box
|
||||
*/
|
||||
showDeleteAccountBox: function(target){
|
||||
|
||||
//Create a box
|
||||
var box = createElem2({
|
||||
appendTo: target,
|
||||
type: "div",
|
||||
class: "box box-primary box-privacy-settings"
|
||||
class: "box box-danger box-delete-account-settings"
|
||||
});
|
||||
|
||||
//Add box header
|
||||
@ -31,7 +43,7 @@ ComunicWeb.pages.settings.sections.privacy = {
|
||||
appendTo: boxHead,
|
||||
type: "h3",
|
||||
class: "box-title",
|
||||
innerHTML: "Privacy"
|
||||
innerHTML: "Delete account"
|
||||
});
|
||||
|
||||
//Create box body
|
||||
@ -41,10 +53,27 @@ ComunicWeb.pages.settings.sections.privacy = {
|
||||
class: "box-body"
|
||||
});
|
||||
|
||||
//Create a form contener
|
||||
var formContener = createElem2({
|
||||
//Add a notice
|
||||
createElem2({
|
||||
appendTo: boxBody,
|
||||
type: "div"
|
||||
type: "p",
|
||||
innerHTML: "You can decide here to delete your account. <br /><b>Warning! Warning! Warning! This operation CAN NOT BE REVERTED !!!! All your data (post, conversation " +
|
||||
"messages, comments...) will be permanently deleted ! You will not be able to recover from this operation !</b>"
|
||||
});
|
||||
|
||||
//Add delete account button
|
||||
var deleteAccountBtn = createElem2({
|
||||
appendTo: boxBody,
|
||||
type: "div",
|
||||
class: "btn btn-danger",
|
||||
innerHTML: "Delete your account"
|
||||
});
|
||||
|
||||
deleteAccountBtn.addEventListener("click", function(e){
|
||||
|
||||
//Request account deletion
|
||||
ComunicWeb.components.settings.helper.requestAccountDeletion();
|
||||
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -251,6 +251,7 @@ class Dev {
|
||||
|
||||
//Settings
|
||||
"js/components/settings/interface.js",
|
||||
"js/components/settings/helper.js",
|
||||
|
||||
//Main menubar
|
||||
"js/components/menuBar/common.js",
|
||||
|
Loading…
Reference in New Issue
Block a user