ge-admin-auth.js 37 KB

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