UNPKG

ionic-coreo

Version:

Ionic2 module for integration with Coreo

87 lines 3.05 kB
"use strict"; var core_1 = require('@angular/core'); var storage_1 = require('@ionic/storage'); var USER_STORAGE_KEY = 'coreo.user'; var urlBase64Decode = function (str) { var output = str.replace('-', '+').replace('_', '/'); switch (output.length % 4) { case 0: break; case 2: output += '=='; break; case 3: output += '='; break; default: throw 'Illegal base64url string!'; } return window.atob(output); }; var CoreoUser = (function () { function CoreoUser(storage) { this.storage = storage; this.usernameConfirmed = false; this.isLoggedIn = false; this.load(); } CoreoUser.prototype.setProfile = function (data) { this.id = data.userId || data.id; this.role = data.role; this.email = data.email; this.imageUrl = data.imageUrl; this.displayName = data.displayName; this.username = data.username; this.usernameConfirmed = data.usernameConfirmed; this.isLoggedIn = true; }; CoreoUser.prototype.setUsername = function (username) { this.username = username; this.usernameConfirmed = true; }; CoreoUser.prototype.load = function () { var _this = this; return this.storage.ready().then(function () { _this.storage.get(USER_STORAGE_KEY).then(function (data) { if (data) { _this.setProfile(JSON.parse(data)); } return _this; }); }); }; CoreoUser.prototype.save = function () { var _this = this; return this.storage.ready().then(function () { _this.storage.set(USER_STORAGE_KEY, JSON.stringify(_this)); }); }; CoreoUser.prototype.clear = function () { var _this = this; this.id = null; this.email = null; this.displayName = null; this.username = null; this.usernameConfirmed = false; this.role = null; this.imageUrl = null; this.isLoggedIn = false; this.storage.ready().then(function () { return _this.storage.remove(USER_STORAGE_KEY); }); }; CoreoUser.prototype.toJSON = function () { var _a = this, id = _a.id, email = _a.email, displayName = _a.displayName, role = _a.role, imageUrl = _a.imageUrl, username = _a.username, usernameConfirmed = _a.usernameConfirmed; return Object.assign({}, { id: id, email: email, displayName: displayName, role: role, imageUrl: imageUrl, username: username, usernameConfirmed: usernameConfirmed }); }; CoreoUser.decorators = [ { type: core_1.Injectable }, ]; /** @nocollapse */ CoreoUser.ctorParameters = function () { return [ { type: storage_1.Storage, }, ]; }; return CoreoUser; }()); exports.CoreoUser = CoreoUser; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = CoreoUser; //# sourceMappingURL=user.js.map