ge-admin-auth.js 40 KB

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