ge-admin-auth.js 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862
  1. import { CommonModule } from '@angular/common';
  2. import { NbAlertModule, NbButtonModule, NbCardModule, NbCheckboxModule, NbInputModule, NbLayoutModule } from '@nebular/theme';
  3. import { FormsModule } from '@angular/forms';
  4. import { switchMap, map, catchError, concatAll } from 'rxjs/operators';
  5. import { HttpClient, HttpErrorResponse } from '@angular/common/http';
  6. import { __extends } from 'tslib';
  7. import { JSEncrypt } from 'jsencrypt';
  8. import { NB_AUTH_OPTIONS, NbAuthService, NbAuthStrategyOptions, NbAuthIllegalTokenError, NbAuthResult, NbAuthStrategy, NbAuthModule } from '@nebular/auth';
  9. import { Router, ActivatedRoute, RouterModule } from '@angular/router';
  10. import { getDeepFromObject } from '@nebular/auth/helpers';
  11. import { Injectable, InjectionToken, Inject, Optional, ChangeDetectionStrategy, ChangeDetectorRef, Component, NgModule } from '@angular/core';
  12. import { of, Subject } from 'rxjs';
  13. import { TranslateService, TranslateModule } from '@ngx-translate/core';
  14. /**
  15. * @fileoverview added by tsickle
  16. * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  17. */
  18. var zhCn = {
  19. '与第一次输入不符合': '与第一次输入不符合.',
  20. '修改密码': '修改密码',
  21. '密码': '密码',
  22. '密码:': '密码:',
  23. '密码是必填的': '密码是必填的',
  24. '密码规则提示': '密码应该包含 最小长度 {{minLength}} 最大长度 {{maxLength}} 个字符',
  25. '您好,欢迎使用': '您好,欢迎使用',
  26. '成功!': '成功!',
  27. '新密码': '新密码',
  28. '新密码:': '新密码:',
  29. '新密码是必填的!': '新密码是必填的!',
  30. '旧密码:': '旧密码:',
  31. '旧密码是必填的!': '旧密码是必填的',
  32. '登出提示': '正在登出, 请等待...',
  33. '登录': '登录',
  34. '确认密码': '确认密码',
  35. '确认密码:': '确认密码:',
  36. '确认密码是必填的!': '确认密码是必填的!',
  37. '请设置您的新密码': '请设置您的新密码',
  38. '账户': '账户',
  39. '账户:': '账户:',
  40. '账户是必填的': '账户是必填的',
  41. '错误!': '错误!'
  42. };
  43. var ZHCN = /*#__PURE__*/Object.freeze({
  44. default: zhCn
  45. });
  46. /**
  47. * @fileoverview added by tsickle
  48. * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  49. */
  50. var zhHk = {
  51. '与第一次输入不符合': '與第一次輸入不符合.',
  52. '修改密码': '更改密碼',
  53. '密码': '密碼',
  54. '密码:': '密碼:',
  55. '密码是必填的': '必須填寫密碼',
  56. '密码规则提示': '密碼應該包含 最小長度 {{minLength}} 最大長度 {{maxLength}} 個字符',
  57. '您好,欢迎使用': '您好,歡迎使用',
  58. '成功!': '成功!',
  59. '新密码': '新密碼',
  60. '新密码:': '新密碼:',
  61. '新密码是必填的!': '必須填寫新密碼',
  62. '旧密码:': '舊密碼:',
  63. '旧密码是必填的!': '必須填寫舊密碼',
  64. '登出提示': '正在登出, 請稍候⋯',
  65. '登录': '登入',
  66. '确认密码': '確認密碼',
  67. '确认密码:': '確認密碼:',
  68. '确认密码是必填的!': '必須填寫確認密碼',
  69. '请设置您的新密码': '請設置您的新密碼',
  70. '账户': '賬戶',
  71. '账户:': '賬戶:',
  72. '账户是必填的': '必須填寫賬戶',
  73. '错误!': '錯誤!'
  74. };
  75. var ZHHK = /*#__PURE__*/Object.freeze({
  76. default: zhHk
  77. });
  78. /**
  79. * @fileoverview added by tsickle
  80. * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  81. */
  82. /** @type {?} */
  83. var AUTH_DEFAULT_LANG = new InjectionToken('AUTH_DEFAULT_LANG');
  84. var LoginLangService = /** @class */ (function () {
  85. function LoginLangService(_translate, lang) {
  86. this._translate = _translate;
  87. this._translate.setTranslation('zh-cn', ZHCN);
  88. this._translate.setTranslation('zh-hk', ZHHK);
  89. this._translate.setDefaultLang(lang ? lang : 'zh-cn');
  90. }
  91. /**
  92. * @param {?=} lang
  93. * @return {?}
  94. */
  95. LoginLangService.prototype.setTranslate = /**
  96. * @param {?=} lang
  97. * @return {?}
  98. */
  99. function (lang) {
  100. this._translate.use(lang);
  101. };
  102. LoginLangService.decorators = [
  103. { type: Injectable }
  104. ];
  105. /** @nocollapse */
  106. LoginLangService.ctorParameters = function () { return [
  107. { type: TranslateService },
  108. { type: String, decorators: [{ type: Optional }, { type: Inject, args: [AUTH_DEFAULT_LANG,] }] }
  109. ]; };
  110. return LoginLangService;
  111. }());
  112. /**
  113. * @fileoverview added by tsickle
  114. * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  115. */
  116. var LoginComponent = /** @class */ (function () {
  117. function LoginComponent(service, langService, options, cd, router) {
  118. if (options === void 0) { options = {}; }
  119. this.service = service;
  120. this.langService = langService;
  121. this.options = options;
  122. this.cd = cd;
  123. this.router = router;
  124. this.redirectDelay = 0;
  125. this.showMessages = {};
  126. this.strategy = '';
  127. this.errors = [];
  128. this.messages = [];
  129. this.user = {};
  130. this.submitted = false;
  131. this.socialLinks = [];
  132. this.rememberMe = false;
  133. this.redirectDelay = this.getConfigValue('forms.login.redirectDelay');
  134. this.showMessages = this.getConfigValue('forms.login.showMessages');
  135. this.strategy = this.getConfigValue('forms.login.strategy');
  136. this.socialLinks = this.getConfigValue('forms.login.socialLinks');
  137. this.rememberMe = this.getConfigValue('forms.login.rememberMe');
  138. }
  139. /**
  140. * @return {?}
  141. */
  142. LoginComponent.prototype.login = /**
  143. * @return {?}
  144. */
  145. function () {
  146. var _this = this;
  147. this.errors = [];
  148. this.messages = [];
  149. this.submitted = true;
  150. this.service.authenticate(this.strategy, this.user).subscribe(function (result) {
  151. _this.submitted = false;
  152. if (result.isSuccess()) {
  153. _this.messages = result.getMessages();
  154. }
  155. else {
  156. _this.errors = result.getErrors();
  157. }
  158. /** @type {?} */
  159. var redirect = result.getRedirect();
  160. if (redirect) {
  161. setTimeout(function () {
  162. return _this.router.navigateByUrl(redirect);
  163. }, _this.redirectDelay);
  164. }
  165. _this.cd.detectChanges();
  166. });
  167. };
  168. /**
  169. * @param {?} key
  170. * @return {?}
  171. */
  172. LoginComponent.prototype.getConfigValue = /**
  173. * @param {?} key
  174. * @return {?}
  175. */
  176. function (key) {
  177. return getDeepFromObject(this.options, key, null);
  178. };
  179. LoginComponent.decorators = [
  180. { type: Component, args: [{
  181. selector: 'auth-login',
  182. template: "<h1 id=\"title\" class=\"title\" translate>\u767B\u5F55</h1>\r\n<p class=\"sub-title\" translate>\u60A8\u597D,\u6B22\u8FCE\u4F7F\u7528</p>\r\n\r\n<nb-alert *ngIf=\"showMessages.error && errors?.length && !submitted\" outline=\"danger\" role=\"alert\">\r\n <p class=\"alert-title\"><b translate>\u9519\u8BEF!</b></p>\r\n <ul class=\"alert-message-list\">\r\n <li *ngFor=\"let error of errors\" class=\"alert-message\">{{ error }}</li>\r\n </ul>\r\n</nb-alert>\r\n\r\n<nb-alert\r\n *ngIf=\"showMessages.success && messages?.length && !submitted\"\r\n outline=\"success\"\r\n role=\"alert\"\r\n>\r\n <p class=\"alert-title\"><b translate>\u6210\u529F!</b></p>\r\n <ul class=\"alert-message-list\">\r\n <li *ngFor=\"let message of messages\" class=\"alert-message\">{{ message }}</li>\r\n </ul>\r\n</nb-alert>\r\n\r\n<form (ngSubmit)=\"login()\" #form=\"ngForm\" aria-labelledby=\"title\">\r\n <div class=\"form-control-group\">\r\n <label class=\"label\" for=\"input-email\" translate>\u8D26\u6237:</label>\r\n <input\r\n nbInput\r\n fullWidth\r\n [(ngModel)]=\"user.loginId\"\r\n #loginId=\"ngModel\"\r\n name=\"loginId\"\r\n id=\"input-loginId\"\r\n placeholder=\"{{ '\u8D26\u6237' | translate }}\"\r\n autofocus\r\n [status]=\"loginId.dirty ? (loginId.invalid ? 'danger' : 'success') : ''\"\r\n [required]=\"true\"\r\n [attr.aria-invalid]=\"loginId.invalid && loginId.touched ? true : null\"\r\n />\r\n <ng-container *ngIf=\"loginId.invalid && loginId.touched\">\r\n <p class=\"error-message\" *ngIf=\"loginId.errors?.required\" translate=\"\u8D26\u6237\u662F\u5FC5\u586B\u7684\">\r\n\r\n </p>\r\n </ng-container>\r\n </div>\r\n\r\n <div class=\"form-control-group\">\r\n <label class=\"label\" for=\"input-password\" translate>\u5BC6\u7801:</label>\r\n <input\r\n nbInput\r\n fullWidth\r\n [(ngModel)]=\"user.loginPassword\"\r\n #password=\"ngModel\"\r\n name=\"password\"\r\n type=\"password\"\r\n id=\"input-password\"\r\n placeholder=\"{{'\u5BC6\u7801'|translate}}\"\r\n [status]=\"password.dirty ? (password.invalid ? 'danger' : 'success') : ''\"\r\n [required]=\"true\"\r\n [minlength]=\"getConfigValue('forms.validation.password.minLength')\"\r\n [maxlength]=\"getConfigValue('forms.validation.password.maxLength')\"\r\n [attr.aria-invalid]=\"password.invalid && password.touched ? true : null\"\r\n />\r\n <ng-container *ngIf=\"password.invalid && password.touched\">\r\n <p class=\"error-message\" *ngIf=\"password.errors?.required\" translate=\"\u5BC6\u7801\u662F\u5FC5\u586B\u7684\">\r\n\r\n </p>\r\n <p class=\"error-message\" *ngIf=\"password.errors?.minlength || password.errors?.maxlength\"\r\n translate=\"\u5BC6\u7801\u89C4\u5219\u63D0\u793A\" [translateParams]=\"{minLength: getConfigValue('forms.validation.password.minLength'), maxLength:getConfigValue('forms.validation.password.maxLength')}\"\r\n >\r\n \u5BC6\u7801\u5E94\u8BE5\u5305\u542B \u6700\u5C0F\u957F\u5EA6 {{ getConfigValue('forms.validation.password.minLength') }} \u6700\u5927\u957F\u5EA6\r\n {{ getConfigValue('forms.validation.password.maxLength') }}\r\n \u4E2A\u5B57\u7B26\r\n </p>\r\n </ng-container>\r\n </div>\r\n\r\n <!--<div class=\"form-control-group accept-group\">-->\r\n <!--<nb-checkbox name=\"rememberMe\" [(ngModel)]=\"user.rememberMe\" *ngIf=\"rememberMe\">\u8BB0\u4F4F\u8D26\u53F7</nb-checkbox>-->\r\n <!--&lt;!&ndash;<a class=\"forgot-password\" routerLink=\"../request-password\">Forgot Password?</a>&ndash;&gt;-->\r\n <!--</div>-->\r\n\r\n <button\r\n nbButton\r\n fullWidth\r\n status=\"success\"\r\n [disabled]=\"submitted || !form.valid\"\r\n [class.btn-pulse]=\"submitted\"\r\n translate=\"\u767B\u5F55\"\r\n >\r\n </button>\r\n</form>\r\n\r\n<!--<section *ngIf=\"socialLinks && socialLinks.length > 0\" class=\"links\" aria-label=\"Social sign in\">-->\r\n<!--or enter with:-->\r\n<!--<div class=\"socials\">-->\r\n<!--<ng-container *ngFor=\"let socialLink of socialLinks\">-->\r\n<!--<a *ngIf=\"socialLink.link\"-->\r\n<!--[routerLink]=\"socialLink.link\"-->\r\n<!--[attr.target]=\"socialLink.target\"-->\r\n<!--[attr.class]=\"socialLink.icon\"-->\r\n<!--[class.with-icon]=\"socialLink.icon\">{{ socialLink.title }}</a>-->\r\n<!--<a *ngIf=\"socialLink.url\"-->\r\n<!--[attr.href]=\"socialLink.url\"-->\r\n<!--[attr.target]=\"socialLink.target\"-->\r\n<!--[attr.class]=\"socialLink.icon\"-->\r\n<!--[class.with-icon]=\"socialLink.icon\">{{ socialLink.title }}</a>-->\r\n<!--</ng-container>-->\r\n<!--</div>-->\r\n<!--</section>-->\r\n\r\n<!--<section class=\"another-action\" aria-label=\"Register\">-->\r\n<!--Don't have an account? <a class=\"text-link\" routerLink=\"../register\">Register</a>-->\r\n<!--</section>-->\r\n",
  183. changeDetection: ChangeDetectionStrategy.OnPush
  184. }] }
  185. ];
  186. /** @nocollapse */
  187. LoginComponent.ctorParameters = function () { return [
  188. { type: NbAuthService },
  189. { type: LoginLangService },
  190. { type: undefined, decorators: [{ type: Inject, args: [NB_AUTH_OPTIONS,] }] },
  191. { type: ChangeDetectorRef },
  192. { type: Router }
  193. ]; };
  194. return LoginComponent;
  195. }());
  196. /**
  197. * @fileoverview added by tsickle
  198. * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  199. */
  200. var NamePasswordAuthStrategyOptions = /** @class */ (function (_super) {
  201. __extends(NamePasswordAuthStrategyOptions, _super);
  202. function NamePasswordAuthStrategyOptions() {
  203. var _this = _super !== null && _super.apply(this, arguments) || this;
  204. _this.baseEndpoint = '/api/auth/';
  205. _this.getPublicKey = {
  206. endpoint: 'getPublicKey',
  207. method: 'get'
  208. };
  209. _this.login = {
  210. alwaysFail: false,
  211. endpoint: 'login',
  212. method: 'post',
  213. redirect: {
  214. success: '/',
  215. failure: null
  216. },
  217. defaultErrors: ['未知错误!'],
  218. defaultMessages: ['You have been successfully logged in.']
  219. };
  220. _this.createUser = {
  221. endpoint: 'createUser',
  222. method: 'post',
  223. defaultErrors: ['未知错误!']
  224. };
  225. _this.updatePasswordForAdmin = {
  226. endpoint: 'updatePasswordForAdmin',
  227. method: 'patch',
  228. defaultErrors: ['未知错误!']
  229. };
  230. _this.register = {
  231. alwaysFail: false,
  232. endpoint: 'register',
  233. method: 'post',
  234. redirect: {
  235. success: '/',
  236. failure: null
  237. },
  238. defaultErrors: ['Something went wrong, please try again.'],
  239. defaultMessages: ['You have been successfully registered.']
  240. };
  241. _this.requestPass = {
  242. endpoint: 'request-pass',
  243. method: 'post',
  244. redirect: {
  245. success: '/',
  246. failure: null
  247. },
  248. defaultErrors: ['Something went wrong, please try again.'],
  249. defaultMessages: ['Reset password instructions have been sent to your email.']
  250. };
  251. _this.resetPass = {
  252. endpoint: 'updateUserPassword',
  253. method: 'patch',
  254. redirect: {
  255. success: '/',
  256. failure: null
  257. },
  258. defaultErrors: ['未知错误.'],
  259. defaultMessages: ['Your password has been successfully changed.']
  260. };
  261. _this.logout = {
  262. alwaysFail: false,
  263. endpoint: 'logout',
  264. method: 'delete',
  265. redirect: {
  266. success: '/',
  267. failure: null
  268. },
  269. defaultErrors: ['Something went wrong, please try again.'],
  270. defaultMessages: ['You have been successfully logged out.']
  271. };
  272. _this.errors = {
  273. key: 'messager',
  274. getter: function (module, res, options) { return [
  275. getDeepFromObject(res.error, options.errors.key, options[module].defaultErrors)
  276. ]; }
  277. };
  278. _this.messages = {
  279. key: 'messager',
  280. getter: function (module, res, options) { return [getDeepFromObject(res.body, options.messages.key, false)]; }
  281. };
  282. _this.success = {
  283. key: 'success',
  284. getter: function (module, res, options) {
  285. return getDeepFromObject(res.body, options.success.key, options[module].defaultMessages);
  286. }
  287. };
  288. return _this;
  289. }
  290. return NamePasswordAuthStrategyOptions;
  291. }(NbAuthStrategyOptions));
  292. /** @type {?} */
  293. var namePasswordStrategyOptions = new NamePasswordAuthStrategyOptions();
  294. /**
  295. * @fileoverview added by tsickle
  296. * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  297. */
  298. var ResultError = /** @class */ (function () {
  299. function ResultError(message) {
  300. this.message = message;
  301. }
  302. return ResultError;
  303. }());
  304. var NamePasswordStrategyService = /** @class */ (function (_super) {
  305. __extends(NamePasswordStrategyService, _super);
  306. function NamePasswordStrategyService(http, route) {
  307. var _this = _super.call(this) || this;
  308. _this.http = http;
  309. _this.route = route;
  310. _this.defaultOptions = namePasswordStrategyOptions;
  311. return _this;
  312. }
  313. /**
  314. * @param {?} options
  315. * @return {?}
  316. */
  317. NamePasswordStrategyService.setup = /**
  318. * @param {?} options
  319. * @return {?}
  320. */
  321. function (options) {
  322. return [NamePasswordStrategyService, options];
  323. };
  324. /**
  325. * @param {?=} data
  326. * @return {?}
  327. */
  328. NamePasswordStrategyService.prototype.authenticate = /**
  329. * @param {?=} data
  330. * @return {?}
  331. */
  332. function (data) {
  333. var _this = this;
  334. /** @type {?} */
  335. var module = 'login';
  336. /** @type {?} */
  337. var method = this.getOption(module + ".method");
  338. /** @type {?} */
  339. var url = this.getActionEndpoint(module);
  340. /** @type {?} */
  341. var requireValidToken = this.getOption(module + ".requireValidToken");
  342. return this.getEncryptPassword(data.loginPassword).pipe(map(function (body) {
  343. body.loginID = data.loginId;
  344. return _this.http.request(method, url, { body: body, observe: 'response' })
  345. .pipe(map(function (res) {
  346. if (_this.getOption(module + ".alwaysFail")) {
  347. throw _this.createFailResponse(data);
  348. }
  349. else if (!_this.getOption('success.getter')(module, res, _this.options)) {
  350. throw new ResultError(_this.getOption('messages.getter')(module, res, _this.options));
  351. }
  352. return res;
  353. }), map(function (res) {
  354. return new NbAuthResult(true, res, _this.getOption(module + ".redirect.success"), [], _this.getOption('messages.getter')(module, res, _this.options));
  355. }), catchError(function (res) {
  356. return _this.handleResponseError(res, module);
  357. }));
  358. }), concatAll());
  359. };
  360. /**
  361. * @return {?}
  362. */
  363. NamePasswordStrategyService.prototype.logout = /**
  364. * @return {?}
  365. */
  366. function () {
  367. var _this = this;
  368. /** @type {?} */
  369. var module = 'logout';
  370. /** @type {?} */
  371. var method = this.getOption(module + ".method");
  372. /** @type {?} */
  373. var url = this.getActionEndpoint(module);
  374. return of({})
  375. .pipe(switchMap(function (res) {
  376. if (!url) {
  377. return of(res);
  378. }
  379. return _this.http.request(method, url, { observe: 'response' });
  380. }), map(function (res) {
  381. if (_this.getOption(module + ".alwaysFail")) {
  382. throw _this.createFailResponse();
  383. }
  384. return res;
  385. }), map(function (res) {
  386. return new NbAuthResult(true, res, _this.getOption(module + ".redirect.success"), [], _this.getOption('messages.getter')(module, res, _this.options));
  387. }), catchError(function (res) {
  388. return _this.handleResponseError(res, module);
  389. }));
  390. };
  391. /**
  392. * @param {?=} data
  393. * @return {?}
  394. */
  395. NamePasswordStrategyService.prototype.refreshToken = /**
  396. * @param {?=} data
  397. * @return {?}
  398. */
  399. function (data) {
  400. return undefined;
  401. };
  402. /**
  403. * @param {?=} data
  404. * @return {?}
  405. */
  406. NamePasswordStrategyService.prototype.register = /**
  407. * @param {?=} data
  408. * @return {?}
  409. */
  410. function (data) {
  411. return undefined;
  412. };
  413. /**
  414. * @param {?=} data
  415. * @return {?}
  416. */
  417. NamePasswordStrategyService.prototype.requestPassword = /**
  418. * @param {?=} data
  419. * @return {?}
  420. */
  421. function (data) {
  422. return undefined;
  423. };
  424. /**
  425. * @param {?=} data
  426. * @return {?}
  427. */
  428. NamePasswordStrategyService.prototype.resetPassword = /**
  429. * @param {?=} data
  430. * @return {?}
  431. */
  432. function (data) {
  433. var _this = this;
  434. /** @type {?} */
  435. var module = 'resetPass';
  436. /** @type {?} */
  437. var method = this.getOption(module + ".method");
  438. /** @type {?} */
  439. var url = this.getActionEndpoint(module);
  440. return this.getEncryptPassword(data.loginPasswordNew + '-' + data.loginPasswordOld).pipe(map(function (body) {
  441. body.passwordData = body.loginPassword;
  442. return _this.http.request(method, url, { body: body, observe: 'response' })
  443. .pipe(map(function (res) {
  444. if (_this.getOption(module + ".alwaysFail")) {
  445. throw _this.createFailResponse(data);
  446. }
  447. else if (!_this.getOption('success.getter')(module, res, _this.options)) {
  448. throw new ResultError(_this.getOption('messages.getter')(module, res, _this.options));
  449. }
  450. return res;
  451. }), map(function (res) {
  452. return new NbAuthResult(true, res, _this.getOption(module + ".redirect.success"), [], _this.getOption('messages.getter')(module, res, _this.options));
  453. }), catchError(function (res) {
  454. return _this.handleResponseError(res, module);
  455. }));
  456. }), concatAll());
  457. };
  458. /**
  459. * @param {?=} data
  460. * @return {?}
  461. */
  462. NamePasswordStrategyService.prototype.createUser = /**
  463. * @param {?=} data
  464. * @return {?}
  465. */
  466. function (data) {
  467. var _this = this;
  468. /** @type {?} */
  469. var module = 'createUser';
  470. /** @type {?} */
  471. var method = this.getOption(module + ".method");
  472. /** @type {?} */
  473. var url = this.getActionEndpoint(module);
  474. return this.getEncryptPassword(data.loginPassword).pipe(map(function (body) {
  475. body.userName = data.userName;
  476. body.loginID = data.loginID;
  477. return _this.http.request(method, url, { body: body, observe: 'response' })
  478. .pipe(map(function (res) {
  479. if (_this.getOption(module + ".alwaysFail")) {
  480. throw _this.createFailResponse(data);
  481. }
  482. else if (!_this.getOption('success.getter')(module, res, _this.options)) {
  483. throw new ResultError(_this.getOption('messages.getter')(module, res, _this.options));
  484. }
  485. return res;
  486. }), map(function (res) {
  487. return new NbAuthResult(true, res, _this.getOption(module + ".redirect.success"), [], _this.getOption('messages.getter')(module, res, _this.options));
  488. }), catchError(function (res) {
  489. return _this.handleResponseError(res, module);
  490. }));
  491. }), concatAll());
  492. };
  493. /**
  494. * @param {?=} data
  495. * @return {?}
  496. */
  497. NamePasswordStrategyService.prototype.updatePasswordForAdmin = /**
  498. * @param {?=} data
  499. * @return {?}
  500. */
  501. function (data) {
  502. var _this = this;
  503. /** @type {?} */
  504. var module = 'updatePasswordForAdmin';
  505. /** @type {?} */
  506. var method = this.getOption(module + ".method");
  507. /** @type {?} */
  508. var url = this.getActionEndpoint(module);
  509. return this.getEncryptPassword(data.loginPassword).pipe(map(function (body) {
  510. body.userID = data.userID;
  511. return _this.http.request(method, url, { body: body, observe: 'response' })
  512. .pipe(map(function (res) {
  513. if (_this.getOption(module + ".alwaysFail")) {
  514. throw _this.createFailResponse(data);
  515. }
  516. else if (!_this.getOption('success.getter')(module, res, _this.options)) {
  517. throw new ResultError(_this.getOption('messages.getter')(module, res, _this.options));
  518. }
  519. return res;
  520. }), map(function (res) {
  521. return new NbAuthResult(true, res, _this.getOption(module + ".redirect.success"), [], _this.getOption('messages.getter')(module, res, _this.options));
  522. }), catchError(function (res) {
  523. return _this.handleResponseError(res, module);
  524. }));
  525. }), concatAll());
  526. };
  527. /**
  528. * @param {?} password
  529. * @return {?}
  530. */
  531. NamePasswordStrategyService.prototype.getEncryptPassword = /**
  532. * @param {?} password
  533. * @return {?}
  534. */
  535. function (password) {
  536. var _this = this;
  537. /** @type {?} */
  538. var module = 'getPublicKey';
  539. /** @type {?} */
  540. var method = this.getOption(module + ".method");
  541. /** @type {?} */
  542. var url = this.getActionEndpoint(module);
  543. return this.http.request(method, url, { observe: 'response' })
  544. .pipe(map(function (res) {
  545. return encryptPassword(res.body, password);
  546. }), catchError(function (res) {
  547. return _this.handleResponseError(res, module);
  548. }));
  549. /**
  550. * @param {?} result
  551. * @param {?} data
  552. * @return {?}
  553. */
  554. function encryptPassword(result, data) {
  555. /** @type {?} */
  556. var now = Date.now();
  557. /** @type {?} */
  558. var encrypt = new JSEncrypt();
  559. encrypt.setPublicKey(result.data.publicPEMKey);
  560. /** @type {?} */
  561. var encryptPass = encrypt.encrypt(data + now);
  562. return {
  563. cryptoKeyID: result.data.cryptoKeyID,
  564. utcTimestamp: now,
  565. loginPassword: encryptPass
  566. };
  567. }
  568. };
  569. /**
  570. * @protected
  571. * @param {?} res
  572. * @param {?} module
  573. * @return {?}
  574. */
  575. NamePasswordStrategyService.prototype.handleResponseError = /**
  576. * @protected
  577. * @param {?} res
  578. * @param {?} module
  579. * @return {?}
  580. */
  581. function (res, module) {
  582. /** @type {?} */
  583. var errors = [];
  584. if (res instanceof HttpErrorResponse) {
  585. errors = this.getOption('errors.getter')(module, res, this.options);
  586. }
  587. else if (res instanceof NbAuthIllegalTokenError) {
  588. errors.push(res.message);
  589. }
  590. else if (res instanceof ResultError) {
  591. errors = res.message;
  592. }
  593. else {
  594. errors.push('Something went wrong.');
  595. }
  596. return of(new NbAuthResult(false, res, this.getOption(module + ".redirect.failure"), errors));
  597. };
  598. NamePasswordStrategyService.decorators = [
  599. { type: Injectable }
  600. ];
  601. /** @nocollapse */
  602. NamePasswordStrategyService.ctorParameters = function () { return [
  603. { type: HttpClient },
  604. { type: ActivatedRoute }
  605. ]; };
  606. return NamePasswordStrategyService;
  607. }(NbAuthStrategy));
  608. /**
  609. * @fileoverview added by tsickle
  610. * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  611. */
  612. var ResetPasswordComponent = /** @class */ (function () {
  613. function ResetPasswordComponent(service, langService, options, cd, router) {
  614. if (options === void 0) { options = {}; }
  615. this.service = service;
  616. this.langService = langService;
  617. this.options = options;
  618. this.cd = cd;
  619. this.router = router;
  620. this.redirectDelay = 0;
  621. this.showMessages = {};
  622. this.strategy = '';
  623. this.submitted = false;
  624. this.errors = [];
  625. this.messages = [];
  626. this.user = {};
  627. this.redirectDelay = this.getConfigValue('forms.resetPassword.redirectDelay');
  628. this.showMessages = this.getConfigValue('forms.resetPassword.showMessages');
  629. this.strategy = this.getConfigValue('forms.resetPassword.strategy');
  630. }
  631. /**
  632. * @return {?}
  633. */
  634. ResetPasswordComponent.prototype.resetPass = /**
  635. * @return {?}
  636. */
  637. function () {
  638. var _this = this;
  639. this.errors = this.messages = [];
  640. this.submitted = true;
  641. this.service.resetPassword(this.strategy, this.user).subscribe(function (result) {
  642. _this.submitted = false;
  643. if (result.isSuccess()) {
  644. _this.messages = result.getMessages();
  645. }
  646. else {
  647. _this.errors = result.getErrors();
  648. }
  649. /** @type {?} */
  650. var redirect = result.getRedirect();
  651. if (redirect) {
  652. setTimeout(function () {
  653. return _this.router.navigateByUrl(redirect);
  654. }, _this.redirectDelay);
  655. }
  656. _this.cd.detectChanges();
  657. });
  658. };
  659. /**
  660. * @param {?} key
  661. * @return {?}
  662. */
  663. ResetPasswordComponent.prototype.getConfigValue = /**
  664. * @param {?} key
  665. * @return {?}
  666. */
  667. function (key) {
  668. return getDeepFromObject(this.options, key, null);
  669. };
  670. ResetPasswordComponent.decorators = [
  671. { type: Component, args: [{
  672. selector: 'auth-reset-password-page',
  673. template: "<h1 id=\"title\" class=\"title\" translate>\u4FEE\u6539\u5BC6\u7801</h1>\r\n<p class=\"sub-title\" translate>\u8BF7\u8BBE\u7F6E\u60A8\u7684\u65B0\u5BC6\u7801</p>\r\n\r\n<nb-alert *ngIf=\"showMessages.error && errors?.length && !submitted\" outline=\"danger\" role=\"alert\">\r\n <p class=\"alert-title\"><b translate>\u9519\u8BEF!</b></p>\r\n <ul class=\"alert-message-list\">\r\n <li *ngFor=\"let error of errors\" class=\"alert-message\">{{ error }}</li>\r\n </ul>\r\n</nb-alert>\r\n\r\n<nb-alert *ngIf=\"showMessages.success && messages?.length && !submitted\" outline=\"success\" role=\"alert\">\r\n <p class=\"alert-title\"><b translate>\u6210\u529F!</b></p>\r\n <ul class=\"alert-message-list\">\r\n <li *ngFor=\"let message of messages\" class=\"alert-message\">{{ message }}</li>\r\n </ul>\r\n</nb-alert>\r\n\r\n<form (ngSubmit)=\"resetPass()\" #resetPassForm=\"ngForm\" aria-labelledby=\"title\">\r\n\r\n <div class=\"form-control-group\">\r\n <label class=\"label\" for=\"input-old-password\" translate>\u65E7\u5BC6\u7801:</label>\r\n <input nbInput\r\n [(ngModel)]=\"user.loginPasswordOld\"\r\n #oldPassword=\"ngModel\"\r\n type=\"password\"\r\n id=\"input-old-password\"\r\n name=\"oldPassword\"\r\n class=\"first\"\r\n placeholder=\"{{'\u65B0\u5BC6\u7801'| translate}}\"\r\n autofocus\r\n fullWidth\r\n [status]=\"oldPassword.dirty ? (oldPassword.invalid ? 'danger' : 'success') : ''\"\r\n [required]=\"getConfigValue('forms.validation.password.required')\"\r\n [minlength]=\"getConfigValue('forms.validation.password.minLength')\"\r\n [maxlength]=\"getConfigValue('forms.validation.password.maxLength')\"\r\n [attr.aria-invalid]=\"oldPassword.invalid && oldPassword.touched ? true : null\">\r\n <ng-container *ngIf=\"oldPassword.invalid && oldPassword.touched\">\r\n <p class=\"error-message\" *ngIf=\"oldPassword.errors?.required\" translate=\"\u65E7\u5BC6\u7801\u662F\u5FC5\u586B\u7684!\">\r\n\r\n </p>\r\n <p class=\"error-message\" *ngIf=\"oldPassword.errors?.minlength || oldPassword.errors?.maxlength\"\r\n translate=\"\u5BC6\u7801\u89C4\u5219\u63D0\u793A\" [translateParams]=\"{minLength: getConfigValue('forms.validation.password.minLength'), maxLength:getConfigValue('forms.validation.password.maxLength')}\">\r\n \u5BC6\u7801\u5E94\u8BE5\u5305\u542B\r\n \u6700\u5C0F\u957F\u5EA6 {{ getConfigValue('forms.validation.password.minLength') }}\r\n \u6700\u5927\u957F\u5EA6 {{ getConfigValue('forms.validation.password.maxLength') }}\r\n \u4E2A\u5B57\u7B26\r\n </p>\r\n </ng-container>\r\n </div>\r\n\r\n <div class=\"form-control-group\">\r\n <label class=\"label\" for=\"input-new-password\" translate>\u65B0\u5BC6\u7801:</label>\r\n <input nbInput\r\n [(ngModel)]=\"user.loginPasswordNew\"\r\n #newPassword=\"ngModel\"\r\n type=\"password\"\r\n id=\"input-new-password\"\r\n name=\"newPassword\"\r\n class=\"first\"\r\n placeholder=\"{{'\u65B0\u5BC6\u7801'| translate}}\"\r\n autofocus\r\n fullWidth\r\n [status]=\"newPassword.dirty ? (newPassword.invalid ? 'danger' : 'success') : ''\"\r\n [required]=\"getConfigValue('forms.validation.password.required')\"\r\n [minlength]=\"getConfigValue('forms.validation.password.minLength')\"\r\n [maxlength]=\"getConfigValue('forms.validation.password.maxLength')\"\r\n [attr.aria-invalid]=\"newPassword.invalid && newPassword.touched ? true : null\">\r\n <ng-container *ngIf=\"newPassword.invalid && newPassword.touched\">\r\n <p class=\"error-message\" *ngIf=\"newPassword.errors?.required\" translate=\"\u65B0\u5BC6\u7801\u662F\u5FC5\u586B\u7684!\">\r\n\r\n </p>\r\n <p class=\"error-message\" *ngIf=\"newPassword.errors?.minlength || newPassword.errors?.maxlength\"\r\n translate=\"\u5BC6\u7801\u89C4\u5219\u63D0\u793A\"\r\n [translateParams]=\"{minLength: getConfigValue('forms.validation.password.minLength'), maxLength:getConfigValue('forms.validation.password.maxLength')}\">\r\n\r\n \u5BC6\u7801\u5E94\u8BE5\u5305\u542B\r\n \u6700\u5C0F\u957F\u5EA6 {{ getConfigValue('forms.validation.password.minLength') }}\r\n \u6700\u5927\u957F\u5EA6 {{ getConfigValue('forms.validation.password.maxLength') }}\r\n \u4E2A\u5B57\u7B26\r\n </p>\r\n </ng-container>\r\n </div>\r\n\r\n <div class=\"form-group\">\r\n <label class=\"label\" for=\"input-re-password\" translate>\u786E\u8BA4\u5BC6\u7801:</label>\r\n <input nbInput\r\n [(ngModel)]=\"user.confirmPassword\"\r\n #rePass=\"ngModel\"\r\n id=\"input-re-password\"\r\n name=\"rePass\"\r\n type=\"password\"\r\n class=\"last\"\r\n placeholder=\"{{'\u786E\u8BA4\u5BC6\u7801'| translate}}\"\r\n fullWidth\r\n [status]=\"rePass.touched\r\n ? (rePass.invalid || newPassword.value != rePass.value ? 'danger' : 'success')\r\n : ''\"\r\n [required]=\"getConfigValue('forms.validation.password.required')\"\r\n [attr.aria-invalid]=\"rePass.invalid && rePass.touched ? true : null\">\r\n <ng-container *ngIf=\"rePass.touched\">\r\n <p class=\"error-message\" *ngIf=\"rePass.invalid && rePass.errors?.required\" translate=\"\u786E\u8BA4\u5BC6\u7801\u662F\u5FC5\u586B\u7684!\">\r\n\r\n </p>\r\n <p class=\"error-message\" *ngIf=\"newPassword.value != rePass.value && !rePass.errors?.required\" translate=\"\u4E0E\u7B2C\u4E00\u6B21\u8F93\u5165\u4E0D\u7B26\u5408\"></p>\r\n </ng-container>\r\n </div>\r\n\r\n <button nbButton\r\n status=\"success\"\r\n fullWidth\r\n [disabled]=\"submitted || !resetPassForm.valid\"\r\n [class.btn-pulse]=\"submitted\" translate=\"\u4FEE\u6539\u5BC6\u7801\">\r\n </button>\r\n</form>\r\n\r\n<!--<section class=\"sign-in-or-up\" aria-label=\"Sign in or sign up\">-->\r\n <!--<p><a class=\"text-link\" routerLink=\"../login\">Back to Log In</a></p>-->\r\n <!--<p><a class=\"text-link\" routerLink=\"../register\">Register</a></p>-->\r\n<!--</section>-->\r\n",
  674. changeDetection: ChangeDetectionStrategy.OnPush,
  675. styles: [":host .form-group:last-of-type{margin-bottom:3rem}"]
  676. }] }
  677. ];
  678. /** @nocollapse */
  679. ResetPasswordComponent.ctorParameters = function () { return [
  680. { type: NbAuthService },
  681. { type: LoginLangService },
  682. { type: undefined, decorators: [{ type: Inject, args: [NB_AUTH_OPTIONS,] }] },
  683. { type: ChangeDetectorRef },
  684. { type: Router }
  685. ]; };
  686. return ResetPasswordComponent;
  687. }());
  688. /**
  689. * @fileoverview added by tsickle
  690. * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  691. */
  692. var LogoutComponent = /** @class */ (function () {
  693. function LogoutComponent(service, langService, options, router) {
  694. if (options === void 0) { options = {}; }
  695. this.service = service;
  696. this.langService = langService;
  697. this.options = options;
  698. this.router = router;
  699. this.redirectDelay = 0;
  700. this.strategy = '';
  701. this.redirectDelay = this.getConfigValue('forms.logout.redirectDelay');
  702. this.strategy = this.getConfigValue('forms.logout.strategy');
  703. }
  704. /**
  705. * @return {?}
  706. */
  707. LogoutComponent.prototype.ngOnInit = /**
  708. * @return {?}
  709. */
  710. function () {
  711. this.logout(this.strategy);
  712. };
  713. /**
  714. * @param {?} strategy
  715. * @return {?}
  716. */
  717. LogoutComponent.prototype.logout = /**
  718. * @param {?} strategy
  719. * @return {?}
  720. */
  721. function (strategy) {
  722. var _this = this;
  723. this.service.logout(strategy).subscribe(function (result) {
  724. /** @type {?} */
  725. var redirect = result.getRedirect();
  726. if (redirect) {
  727. setTimeout(function () {
  728. return _this.router.navigateByUrl(redirect);
  729. }, _this.redirectDelay);
  730. }
  731. });
  732. };
  733. /**
  734. * @param {?} key
  735. * @return {?}
  736. */
  737. LogoutComponent.prototype.getConfigValue = /**
  738. * @param {?} key
  739. * @return {?}
  740. */
  741. function (key) {
  742. return getDeepFromObject(this.options, key, null);
  743. };
  744. LogoutComponent.decorators = [
  745. { type: Component, args: [{
  746. selector: 'auth-logout',
  747. template: "<div translate=\"\u767B\u51FA\u63D0\u793A\"></div>\r\n",
  748. styles: ["div{text-align:center}"]
  749. }] }
  750. ];
  751. /** @nocollapse */
  752. LogoutComponent.ctorParameters = function () { return [
  753. { type: NbAuthService },
  754. { type: LoginLangService },
  755. { type: undefined, decorators: [{ type: Inject, args: [NB_AUTH_OPTIONS,] }] },
  756. { type: Router }
  757. ]; };
  758. return LogoutComponent;
  759. }());
  760. /**
  761. * @fileoverview added by tsickle
  762. * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  763. */
  764. var LoginStatusService = /** @class */ (function () {
  765. function LoginStatusService() {
  766. this.subject = new Subject();
  767. }
  768. /**
  769. * @param {?} status
  770. * @return {?}
  771. */
  772. LoginStatusService.prototype.changeStatus = /**
  773. * @param {?} status
  774. * @return {?}
  775. */
  776. function (status) {
  777. if (this.status !== status) {
  778. this.status = status;
  779. this.subject.next(status);
  780. }
  781. };
  782. LoginStatusService.decorators = [
  783. { type: Injectable }
  784. ];
  785. /** @nocollapse */
  786. LoginStatusService.ctorParameters = function () { return []; };
  787. return LoginStatusService;
  788. }());
  789. /** @enum {number} */
  790. var LoginStatus = {
  791. Login: 1,
  792. Logout: 2,
  793. };
  794. LoginStatus[LoginStatus.Login] = 'Login';
  795. LoginStatus[LoginStatus.Logout] = 'Logout';
  796. /**
  797. * @fileoverview added by tsickle
  798. * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  799. */
  800. var GeAdminAuthModule = /** @class */ (function () {
  801. function GeAdminAuthModule() {
  802. }
  803. GeAdminAuthModule.decorators = [
  804. { type: NgModule, args: [{
  805. declarations: [
  806. LoginComponent,
  807. ResetPasswordComponent,
  808. LogoutComponent
  809. ],
  810. imports: [
  811. CommonModule,
  812. NbLayoutModule,
  813. NbCardModule,
  814. NbCheckboxModule,
  815. NbAlertModule,
  816. NbInputModule,
  817. NbButtonModule,
  818. RouterModule,
  819. FormsModule,
  820. TranslateModule.forRoot(),
  821. NbAuthModule.forRoot()
  822. ],
  823. providers: [
  824. NamePasswordStrategyService,
  825. LoginStatusService,
  826. LoginLangService
  827. ],
  828. exports: [
  829. LoginComponent,
  830. ResetPasswordComponent,
  831. LogoutComponent
  832. ]
  833. },] }
  834. ];
  835. return GeAdminAuthModule;
  836. }());
  837. /**
  838. * @fileoverview added by tsickle
  839. * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  840. */
  841. /**
  842. * @fileoverview added by tsickle
  843. * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  844. */
  845. export { GeAdminAuthModule, LoginStatusService, LoginStatus, LoginComponent, LogoutComponent, ResetPasswordComponent, ResultError, NamePasswordStrategyService, NamePasswordAuthStrategyOptions, namePasswordStrategyOptions, AUTH_DEFAULT_LANG, LoginLangService };
  846. //# sourceMappingURL=ge-admin-auth.js.map