ge-admin-auth.js 40 KB

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