UNPKG

armisa-models

Version:
124 lines (123 loc) 6.49 kB
"use strict"; var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var _AuthFactory_urls, _AuthFactory_apiAxios, _AuthFactory_afterLoginSuccess; Object.defineProperty(exports, "__esModule", { value: true }); exports.AuthFactory = void 0; const ElementsOfFormFactory_1 = require("../Page/ElementsOfFormFactory"); const _1_MenuFactory_1 = require("./Menus/1-MenuFactory"); const TokenInfo_1 = require("./Models/StorageManager/TokenInfo"); const LoginByToken_1 = require("./Logins/Token/LoginByToken"); const LoginByUserPass_1 = require("./Logins/UserPass/LoginByUserPass"); class AuthFactory { get any() { return this; } constructor(mainStateManager) { this.mainStateManager = mainStateManager; _AuthFactory_urls.set(this, (0, TokenInfo_1.useUrls)('BaseCode', 'auth')); _AuthFactory_apiAxios.set(this, (0, TokenInfo_1.useAxios)(__classPrivateFieldGet(this, _AuthFactory_urls, "f"))); this.forceUpdate = () => { }; this.cach = {}; this.userRoutes = []; this.getUser = () => { return this.any['userBoxArmisa']; }; this.getPass = () => { return this.any['passwordBoxArmisa']; }; this.getRememberMe = () => { return this.any['RemeberMe']; }; this.loginByToken = () => { LoginByToken_1.LoginByToken.createNew(this)?.login(); }; this.loginByUserPass = () => { LoginByUserPass_1.LoginByUserPass.createNew(this)?.login(); }; _AuthFactory_afterLoginSuccess.set(this, (response) => { if (typeof this.afterLoginSuccess === 'function') { this.afterLoginSuccess(response); } }); /* @internal */ this.logedIn = (response, rememberMe, path) => { this.deserialize(response, rememberMe); __classPrivateFieldGet(this, _AuthFactory_afterLoginSuccess, "f").call(this, response); this.mainStateManager.push(path); }; this.signOut = () => { this.mainStateManager.tokenInfo.signOut(); this.mainStateManager.settingInfo.signOut(); this.mainStateManager.subSystemsInfo.signOut(); this.mainStateManager.userInfo.signOut(); this.mainStateManager.push('/login'); this.mainStateManager.forceUpdate(); }; this.selectNewActiveFiscalYear = (currentRow) => { this.elementsOfForm.showWaitingFormSpinner(); __classPrivateFieldGet(this, _AuthFactory_apiAxios, "f").get(`${__classPrivateFieldGet(this, _AuthFactory_urls, "f").selectActiveYear}?FK_tbl_axData=${currentRow.id}`) .then((res) => { if (res.status == 200 && res.data.isSuccess) { this.deserialize(res.data); if (typeof this.afterLoginSuccess === 'function') { this.afterLoginSuccess(res.data); } this.elementsOfForm.closeWaitingFormSpinner(); // this.close(); } else { console.error("error on login user error : ", res.data); this.elementsOfForm.closeWaitingFormSpinner(); this.elementsOfForm.showInvalidArgumentMessageBox(res.data.message); } }) .catch((error) => { console.error("exception error on login user error : ", error); this.elementsOfForm.closeWaitingFormSpinner(); this.elementsOfForm.showErrorMessageBox(error); }); }; this.selectNewActiveSystems = () => { this.elementsOfForm.showFullScreenWaittingSpinner(); __classPrivateFieldGet(this, _AuthFactory_apiAxios, "f").post(__classPrivateFieldGet(this, _AuthFactory_urls, "f").login, this.mainStateManager.subSystemsInfo.selected) .then((res) => { if (res.status == 200 && res.data.isSuccess) { this.deserialize(res.data); if (typeof this.afterLoginSuccess === 'function') { this.afterLoginSuccess(res.data); } this.elementsOfForm.closeFullScreenWaittingSpinner(); this.menuFactory.forceUpdateAfterSystemsChange(); } else { console.error("error on select active user error : ", res.data); this.elementsOfForm.closeFullScreenWaittingSpinner(); this.elementsOfForm.showInvalidArgumentMessageBox(res.data.message); } }) .catch((error) => { console.error("exception error on select active user error : ", error); this.elementsOfForm.closeFullScreenWaittingSpinner(); this.elementsOfForm.showErrorMessageBox(error); }); }; this.deserialize = (data, rememberMe = false) => { this.mainStateManager.tokenInfo.deserialize(data.token, rememberMe); this.mainStateManager.settingInfo.deserialize(data.data.settingInfo); this.mainStateManager.userInfo.deserialize(data.data.userInfo); this.mainStateManager.fiscalYearsInfo.deserialize(data.data.fiscalYearsInfo); this.mainStateManager.subSystemsInfo.deserialize(data.data.subSystemsInfo); }; this.menuFactory = new _1_MenuFactory_1.MenuFactory(this.mainStateManager, this); this.elementsOfForm = new ElementsOfFormFactory_1.ElementsOfFormFactory(this); } get isAtunticated() { return this.mainStateManager.userInfo.isAuthenticated(); } } exports.AuthFactory = AuthFactory; _AuthFactory_urls = new WeakMap(), _AuthFactory_apiAxios = new WeakMap(), _AuthFactory_afterLoginSuccess = new WeakMap();