Merge branch '3.0'
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / js / WoltLabSuite / Core / User.js
1 /**
2 * Provides data of the active user.
3 *
4 * @author Matthias Schmidt
5 * @copyright 2001-2018 WoltLab GmbH
6 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
7 * @module WoltLabSuite/Core/User
8 */
9 define([], function() {
10 "use strict";
11
12 var _didInit = false;
13 var _link;
14
15 /**
16 * @exports WoltLabSuite/Core/User
17 */
18 return {
19 /**
20 * Returns the link to the active user's profile or an empty string
21 * if the active user is a guest.
22 *
23 * @return {string}
24 */
25 getLink: function() {
26 return _link;
27 },
28
29 /**
30 * Initializes the user object.
31 *
32 * @param {int} userId id of the user, `0` for guests
33 * @param {string} username name of the user, empty for guests
34 * @param {string} userLink link to the user's profile, empty for guests
35 */
36 init: function(userId, username, userLink) {
37 if (_didInit) {
38 throw new Error('User has already been initialized.');
39 }
40
41 // define non-writeable properties for userId and username
42 Object.defineProperty(this, 'userId', {
43 value: userId,
44 writable: false
45 });
46 Object.defineProperty(this, 'username', {
47 value: username,
48 writable: false
49 });
50
51 _link = userLink;
52
53 _didInit = true;
54 }
55 };
56 });