ge-admin-auth.js 37 KB

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