Merge branch '2.1' into 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-2017 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
14 /**
15 * @exports WoltLabSuite/Core/User
16 */
17 return {
18 /**
19 * Initializes the user object.
20 *
21 * @param {int} userId id of the user, `0` for guests
22 * @param {string} username name of the user, empty for guests
23 */
24 init: function(userId, username) {
25 if (_didInit) {
26 throw new Error('User has already been initialized.');
27 }
28
29 // define non-writeable properties for userId and username
30 Object.defineProperty(this, 'userId', {
31 value: userId,
32 writable: false
33 });
34 Object.defineProperty(this, 'username', {
35 value: username,
36 writable: false
37 });
38
39 _didInit = true;
40 }
41 };
42 });