Core.User = class extends _core { /** * Get class name. * @return {string} */ static getClassName() { return 'Core.User'; } /** * Create new user. * @param {data} form * @param {function()} callback */ static create(form, callback) { Server.call( new Core.User().getURI(), { func: '_create', form: form }, function (data) { if ($.isFunction(callback)) { callback(); } }, null, 'Creating user...' ); } /** * Logout current user. */ static logout() { Server.call( new Core.User().getURI(), { func: 'apiLogout' }, function (data) { location.reload(); }, null, 'Logging out...' ); } /** * Take object lock. * @param {string} method * @param {string} id * @param {bool} force * @param {function(bool)} callback */ static lockObject(method, id, force, callback) { Server.call( new Core.User().getURI(), { func: 'apiTakeLock', method: method, id: id, force: force }, function (data) { if ($.isFunction(callback)) { callback( Boolean(data.locked), data.locked_by_user_id ); } }, null, { hide: force == false, text: 'Taking lock...' } ); } /** * Instantiate new user. * @param {string} id */ constructor(id) { super(); if (!id) { id = Core.User.loggedInUser; } this.id = id; } /** * Log user in. * @param {string} password * @param {function()} success * @param {function(string)} failed * @param {jQuery} $context * @return {boolean} */ login(password, success, failed, $context) { Server.call( this.getURI('/login'), { func: 'apiLogin', user_id: this.id, password: password, error_return_code: 2, force_login: false }, function (data) { if (data.return == 1) { if ($.isFunction(success)) { success(data.default_page); } } else if (data.return == 2) { if ($.isFunction(failed)) { failed(data.message); } } }, $context, 'Logging in...' ); } /** * Change user password. * @param {string} password * @param {jQuery} $context * @param {function()} callback */ changePassword(password, $context, callback) { Server.call( this.getURI(), { func: 'apiChangePassword', user_id: this.id, password: password }, function (data) { if ($.isFunction(callback)) { callback(); } }, $context, 'Changing password...' ); } /** * Delete user. * @param {function()} callback */ delete(callback) { Server.call( `DELETE ${this.getURI()}`, { user_id: this.id, }, function (data) { if ($.isFunction(callback)) { callback(); } }, null, 'Deleting user...' ); } };