UNPKG

dl

Version:

DreamLab Libs

61 lines (56 loc) 1.4 kB
/** * Id sessions API user profile * * @param {Object} [data] Profile data * @constructor */ var UidProfile = function (data) { this._data = data || {}; }; /** * Checks whether user is logged in. * * @type Boolean */ UidProfile.prototype.isLogged = function () { return this._data.hasOwnProperty('usr_uuid') && this._data.usr_uuid !== null; }; /** * Checks whether user is anonymous. * * @type Boolean */ UidProfile.prototype.isAnonymous = function () { var profile = this.toJSON(); return !UidProfile.AUTH_FIELDS.some(function (field) { return profile[field]; }); }; /** * Returns user data. * * @returns {Object} User data: * {String} id - UUID, * {String} email - e-mail address, * {String} phone - mobile phone number, * {String} name - first name, * {String} surname - last name, * {Date} lastLogin - last login date */ UidProfile.prototype.toJSON = function () { return { id: this._data.usr_uuid, email: this._data.usr_email, phone: this._data.usr_phone, name: this._data.usr_name, surname: this._data.usr_surname, lastLogin: this._data.usr_last_login === undefined ? undefined : new Date(this._data.usr_last_login) }; }; /** * List of fields based on which user is able to authenticate. * * @static */ UidProfile.AUTH_FIELDS = ['email', 'phone']; exports.UidProfile = UidProfile;