ionic-coreo
Version:
Ionic2 module for integration with Coreo
71 lines • 2.29 kB
JavaScript
"use strict";
var core_1 = require('@angular/core');
var storage_1 = require('@ionic/storage');
var USER_STORAGE_KEY = 'coreo_user_storage';
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.isLoggedIn = false;
}
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.isLoggedIn = true;
};
CoreoUser.prototype.load = function () {
var _this = this;
return this.storage.get(USER_STORAGE_KEY).then(function (data) {
if (data) {
_this.setProfile(JSON.parse(data));
}
return _this;
});
};
CoreoUser.prototype.save = function () {
return this.storage.set(USER_STORAGE_KEY, JSON.stringify(this));
};
CoreoUser.prototype.clear = function () {
this.id = null;
this.email = null;
this.displayName = null;
this.role = null;
this.imageUrl = null;
this.isLoggedIn = false;
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;
return Object.assign({}, { id: id, email: email, displayName: displayName, role: role, imageUrl: imageUrl });
};
CoreoUser.decorators = [
{ type: core_1.Injectable },
];
/** @nocollapse */
CoreoUser.ctorParameters = [
{ type: storage_1.Storage, },
];
return CoreoUser;
}());
exports.CoreoUser = CoreoUser;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = CoreoUser;
//# sourceMappingURL=user.js.map