diff --git a/assets/css/pages/settings/sections/privacy.css b/assets/css/pages/settings/sections/privacy.css
index 5926d2ef..b56fb3a0 100644
--- a/assets/css/pages/settings/sections/privacy.css
+++ b/assets/css/pages/settings/sections/privacy.css
@@ -3,3 +3,7 @@
*
* @author Pierre HUBERT
*/
+
+.box-delete-account-settings .btn {
+ float: right;
+}
\ No newline at end of file
diff --git a/assets/js/common/functionsSchema.js b/assets/js/common/functionsSchema.js
index 79dbc9d9..9c941549 100644
--- a/assets/js/common/functionsSchema.js
+++ b/assets/js/common/functionsSchema.js
@@ -598,6 +598,13 @@ var ComunicWeb = {
//TODO : implement
},
+ /**
+ * Settings helper
+ */
+ helper: {
+ //TODO : implement
+ },
+
},
/**
diff --git a/assets/js/common/messages.js b/assets/js/common/messages.js
index 035e315b..614bc03d 100644
--- a/assets/js/common/messages.js
+++ b/assets/js/common/messages.js
@@ -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){
diff --git a/assets/js/components/account/interface.js b/assets/js/components/account/interface.js
index 102973cb..b3b97d31 100644
--- a/assets/js/components/account/interface.js
+++ b/assets/js/components/account/interface.js
@@ -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);
+ },
+
}
\ No newline at end of file
diff --git a/assets/js/components/settings/helper.js b/assets/js/components/settings/helper.js
new file mode 100644
index 00000000..1138b1d3
--- /dev/null
+++ b/assets/js/components/settings/helper.js
@@ -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();
+
+ });
+
+ },
+
+}
\ No newline at end of file
diff --git a/assets/js/pages/settings/sections/privacy.js b/assets/js/pages/settings/sections/privacy.js
index e4692820..379f5c1e 100644
--- a/assets/js/pages/settings/sections/privacy.js
+++ b/assets/js/pages/settings/sections/privacy.js
@@ -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.
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 !"
+ });
+
+ //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();
+
});
},
diff --git a/system/config/dev.config.php b/system/config/dev.config.php
index c4658ee1..855c5bbd 100644
--- a/system/config/dev.config.php
+++ b/system/config/dev.config.php
@@ -251,6 +251,7 @@ class Dev {
//Settings
"js/components/settings/interface.js",
+ "js/components/settings/helper.js",
//Main menubar
"js/components/menuBar/common.js",