ge-admin-auth.js 40 KB

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