diff --git a/assets/css/pages/settings/sections/globalLogout.css b/assets/css/pages/settings/sections/globalLogout.css new file mode 100644 index 00000000..1d0c69a8 --- /dev/null +++ b/assets/css/pages/settings/sections/globalLogout.css @@ -0,0 +1,11 @@ +/** + * Global logout section + * + * @author Pierre HUBERT + */ + +.box-global-logout .form-submit { + width: 170px; + margin: auto; + display: block; +} \ No newline at end of file diff --git a/assets/js/common/shorcuts.js b/assets/js/common/shorcuts.js index 8e8d5b21..b3bb844f 100644 --- a/assets/js/common/shorcuts.js +++ b/assets/js/common/shorcuts.js @@ -290,4 +290,17 @@ function getGroups(list, force){ */ function timeDiffToStr(time) { return ComunicWeb.common.date.timeDiffToStr(time); +} + +/** + * Ask a confirmation to the user + * + * @param {String} msg Associated message + */ +async function showConfirmDialog(msg) { + return new Promise((res, err) => { + ComunicWeb.common.messages.confirm(msg, (c) => { + res(c == true); + }); + }) } \ No newline at end of file diff --git a/assets/js/components/account/interface.js b/assets/js/components/account/interface.js index 32413377..5483454c 100644 --- a/assets/js/components/account/interface.js +++ b/assets/js/components/account/interface.js @@ -4,7 +4,7 @@ * @author Pierre HUBERT */ -ComunicWeb.components.account.interface = { +const AccountInterface = { /** * Send a request on the server to create an account @@ -134,6 +134,13 @@ ComunicWeb.components.account.interface = { ComunicWeb.common.api.makeAPIrequest(apiURI, params, false, callback); }, + /** + * Disconnect user from all its connected devices + */ + disconnectAllDevices: async function() { + await api("/account/disconnect_all_devices", {}, true); + }, + /** * Request the export of all the data of the user * @@ -162,4 +169,6 @@ ComunicWeb.components.account.interface = { ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback); }, -} \ No newline at end of file +} + +ComunicWeb.components.account.interface = AccountInterface; \ No newline at end of file diff --git a/assets/js/pages/settings/sections/globalLogout.js b/assets/js/pages/settings/sections/globalLogout.js new file mode 100644 index 00000000..a91d0aba --- /dev/null +++ b/assets/js/pages/settings/sections/globalLogout.js @@ -0,0 +1,62 @@ +/** + * Global logout section + * + * In this section, the user can choose to sign out + * from all its devices + * + * @author Pierre Hubert + */ + +const GlobalSignOutSection = { + /** + * Open settings section + * + * @param {object} args Additionnal arguments + * @param {HTMLElement} target The target for the page + */ + open: function(args, target) { + + //Create a box + var box = createElem2({ + appendTo: target, + type: "div", + class: "box box-primary box-global-logout" + }); + + //Add box header + var boxHead = createElem2({ + appendTo: box, + type: "div", + class: "box-header", + }); + var boxTitle = createElem2({ + appendTo: boxHead, + type: "h3", + class: "box-title", + innerHTML: "Sign out from all devices" + }); + + //Create box body + var boxBody = createElem2({ + appendTo: box, + type: "div", + class: "box-body", + innerHTML: "
You can decide do sign out from all your connected devices (including the current one). You should do this if one of the devices you use to access Comunic is stolen.
" + }); + + const signoutButton = createElem2({ + appendTo: boxBody, + type: "div", + class: "btn btn-danger form-submit", + innerHTML: "Sign out from all devices" + }) + + signoutButton.addEventListener("click",async (e) => { + + if(!await showConfirmDialog("Do you really want to get disconnected on all your devices?")) + return; + + await AccountInterface.disconnectAllDevices(); + }) + } +} \ No newline at end of file diff --git a/assets/js/pages/settings/sections/security.js b/assets/js/pages/settings/sections/security.js index 87eec62a..90a01ec1 100644 --- a/assets/js/pages/settings/sections/security.js +++ b/assets/js/pages/settings/sections/security.js @@ -41,11 +41,14 @@ ComunicWeb.pages.settings.sections.security = { class: "box-body" }); - //Append the form to query user password + // Append the form to query user password this._append_form_prompt_user_password(boxBody); - //Offer the user to update its password too + // Offer the user to update its password too ComunicWeb.pages.settings.sections.password.open(args, target); + + // Offer the user to sign out from its account + GlobalSignOutSection.open(args, target); }, /** diff --git a/system/config/dev.config.php b/system/config/dev.config.php index f2c087c9..1ee3ebbb 100644 --- a/system/config/dev.config.php +++ b/system/config/dev.config.php @@ -274,6 +274,7 @@ class Dev { "css/pages/settings/sections/customEmojis.css", "css/pages/settings/sections/security.css", "css/pages/settings/sections/password.css", + "css/pages/settings/sections/globalLogout.css", "css/pages/settings/sections/accountImage.css", "css/pages/settings/sections/privacy.css", @@ -533,6 +534,7 @@ class Dev { "js/pages/settings/sections/emojis.js", "js/pages/settings/sections/security.js", "js/pages/settings/sections/password.js", + "js/pages/settings/sections/globalLogout.js", "js/pages/settings/sections/accountImage.js", "js/pages/settings/sections/privacy.js",