From: joshuaruesweg Date: Fri, 30 Oct 2020 13:55:13 +0000 (+0100) Subject: Add session list for user X-Git-Tag: 5.4.0_Alpha_1~656^2~3 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=68ae9c6a6abc99767b145579e7ceab5a89d28009;p=GitHub%2FWoltLab%2FWCF.git Add session list for user --- diff --git a/com.woltlab.wcf/templates/accountSecurity.tpl b/com.woltlab.wcf/templates/accountSecurity.tpl index ccb4ffae54..d8581b1b19 100644 --- a/com.woltlab.wcf/templates/accountSecurity.tpl +++ b/com.woltlab.wcf/templates/accountSecurity.tpl @@ -2,6 +2,48 @@ {include file='header' __disableAds=true __sidebarLeftHasMenu=true} -{* @TODO *} +
+

{lang}wcf.user.security.activeSessions{/lang}

+ + +
+ + {include file='footer' __disableAds=true} diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/User/Session/Delete.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/User/Session/Delete.js new file mode 100644 index 0000000000..bb4c43bd7d --- /dev/null +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/User/Session/Delete.js @@ -0,0 +1,65 @@ +/** + * Handles the deletion of a user session. + * + * @author Joshua Ruesweg + * @copyright 2001-2020 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLabSuite/Core/Ui/User/Session/Delete + */ +define(["require", "exports", "tslib", "../../../Ajax", "../../Notification", "../../Confirmation", "../../../Language"], function (require, exports, tslib_1, Ajax, UiNotification, UiConfirmation, Language) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.UiUserSessionDelete = void 0; + Ajax = tslib_1.__importStar(Ajax); + UiNotification = tslib_1.__importStar(UiNotification); + UiConfirmation = tslib_1.__importStar(UiConfirmation); + Language = tslib_1.__importStar(Language); + class UiUserSessionDelete { + /** + * Initializes the session delete buttons. + */ + constructor() { + this.knownElements = new Map(); + document.querySelectorAll(".sessionDeleteButton").forEach((element) => { + if (!element.dataset.sessionId) { + throw new Error(`No sessionId for session delete button given.`); + } + if (!this.knownElements.has(element.dataset.sessionId)) { + element.addEventListener("click", (ev) => this.delete(element, ev)); + this.knownElements.set(element.dataset.sessionId, element); + } + }); + } + /** + * Opens the user trophy list for a specific user. + */ + delete(element, event) { + event.preventDefault(); + UiConfirmation.show({ + message: Language.get("wcf.user.security.deleteSession.confirmMessage"), + confirm: (_parameters) => { + Ajax.api(this, { + sessionID: element.dataset.sessionId, + }); + }, + }); + } + _ajaxSuccess(data) { + const element = this.knownElements.get(data.sessionID); + if (element !== undefined) { + const sessionItem = element.closest("li"); + if (sessionItem !== null) { + sessionItem.remove(); + } + } + UiNotification.show(); + } + _ajaxSetup() { + return { + url: "index.php?delete-session/&t=" + window.SECURITY_TOKEN, + }; + } + } + exports.UiUserSessionDelete = UiUserSessionDelete; + exports.default = UiUserSessionDelete; +}); diff --git a/wcfsetup/install/files/lib/action/DeleteSessionAction.class.php b/wcfsetup/install/files/lib/action/DeleteSessionAction.class.php index 512b31d8a8..b1ecf71620 100644 --- a/wcfsetup/install/files/lib/action/DeleteSessionAction.class.php +++ b/wcfsetup/install/files/lib/action/DeleteSessionAction.class.php @@ -23,7 +23,7 @@ class DeleteSessionAction extends AbstractAction { /** * @var string */ - public $sessionID; + private $sessionID; /** * @inheritDoc diff --git a/wcfsetup/install/files/lib/page/AccountSecurityPage.class.php b/wcfsetup/install/files/lib/page/AccountSecurityPage.class.php index dbd0061a78..5a9fc2b49a 100644 --- a/wcfsetup/install/files/lib/page/AccountSecurityPage.class.php +++ b/wcfsetup/install/files/lib/page/AccountSecurityPage.class.php @@ -1,6 +1,9 @@ activeSessions = SessionHandler::getInstance()->getUserSessions(WCF::getUser()); + } + + /** + * @inheritDoc + */ + public function assignVariables() { + parent::assignVariables(); + + WCF::getTPL()->assign([ + 'activeSessions' => $this->activeSessions + ]); + } + /** * @inheritDoc */ diff --git a/wcfsetup/install/files/style/ui/accountSecurity.scss b/wcfsetup/install/files/style/ui/accountSecurity.scss new file mode 100644 index 0000000000..a3c7be6a26 --- /dev/null +++ b/wcfsetup/install/files/style/ui/accountSecurity.scss @@ -0,0 +1,8 @@ +.accountSecurityContainer { + display: flex; + flex-wrap: wrap; +} + +.accountSecurityInformation { + flex: 1 1 auto; +} diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/User/Session/Delete.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/User/Session/Delete.ts new file mode 100644 index 0000000000..dc05dfd2fe --- /dev/null +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/User/Session/Delete.ts @@ -0,0 +1,77 @@ +/** + * Handles the deletion of a user session. + * + * @author Joshua Ruesweg + * @copyright 2001-2020 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLabSuite/Core/Ui/User/Session/Delete + */ + +import * as Ajax from "../../../Ajax"; +import { AjaxCallbackObject, AjaxCallbackSetup, DatabaseObjectActionResponse } from "../../../Ajax/Data"; +import * as UiNotification from "../../Notification"; +import * as UiConfirmation from "../../Confirmation"; +import * as Language from "../../../Language"; + +export class UiUserSessionDelete implements AjaxCallbackObject { + private readonly knownElements = new Map(); + + /** + * Initializes the session delete buttons. + */ + constructor() { + document.querySelectorAll(".sessionDeleteButton").forEach((element: HTMLElement) => { + if (!element.dataset.sessionId) { + throw new Error(`No sessionId for session delete button given.`); + } + + if (!this.knownElements.has(element.dataset.sessionId)) { + element.addEventListener("click", (ev) => this.delete(element, ev)); + + this.knownElements.set(element.dataset.sessionId, element); + } + }); + } + + /** + * Opens the user trophy list for a specific user. + */ + private delete(element: HTMLElement, event: MouseEvent): void { + event.preventDefault(); + + UiConfirmation.show({ + message: Language.get("wcf.user.security.deleteSession.confirmMessage"), + confirm: (_parameters) => { + Ajax.api(this, { + sessionID: element.dataset.sessionId, + }); + }, + }); + } + + _ajaxSuccess(data: AjaxResponse): void { + const element = this.knownElements.get(data.sessionID); + + if (element !== undefined) { + const sessionItem = element.closest("li"); + + if (sessionItem !== null) { + sessionItem.remove(); + } + } + + UiNotification.show(); + } + + _ajaxSetup(): ReturnType { + return { + url: "index.php?delete-session/&t=" + window.SECURITY_TOKEN, + }; + } +} + +export default UiUserSessionDelete; + +interface AjaxResponse extends DatabaseObjectActionResponse { + sessionID: string; +} diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index de506e6845..5513869ec5 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -4822,6 +4822,13 @@ Die E-Mail-Adresse des neuen Benutzers lautet: {@$user->email}

Quelle: Mustervorlage.net

]]> + + + + getLastActivityTime()|time}]]> + + + username} anzeigen]]> diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index b05416d052..659a52c140 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -4819,6 +4819,13 @@ Open the link below to access the user profile:

Source: Mustervorlage.net

]]>
+ + + + getLastActivityTime()|time}]]> + + + username}]]>