ge-admin-auth.js 37 KB

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