1 | import { HttpClient } from '@angular/common/http';
|
2 | import { ActivatedRoute } from '@angular/router';
|
3 | import { Observable } from 'rxjs';
|
4 | import { NbAuthResult } from '../../services/auth-result';
|
5 | import { NbAuthStrategy } from '../auth-strategy';
|
6 | import { NbAuthStrategyClass } from '../../auth.options';
|
7 | import { NbPasswordAuthStrategyOptions } from './password-strategy-options';
|
8 | import * as i0 from "@angular/core";
|
9 | /**
|
10 | * The most common authentication provider for email/password strategy.
|
11 | *
|
12 | * Strategy settings. Note, there is no need to copy over the whole object to change the settings you need.
|
13 | * Also, this.getOption call won't work outside of the default options declaration
|
14 | * (which is inside of the `NbPasswordAuthStrategy` class), so you have to replace it with a custom helper function
|
15 | * if you need it.
|
16 | *
|
17 | * ```ts
|
18 | *export class NbPasswordAuthStrategyOptions extends NbAuthStrategyOptions {
|
19 | * name: string;
|
20 | * baseEndpoint? = '/api/auth/';
|
21 | * login?: boolean | NbPasswordStrategyModule = {
|
22 | * alwaysFail: false,
|
23 | * endpoint: 'login',
|
24 | * method: 'post',
|
25 | * requireValidToken: true,
|
26 | * redirect: {
|
27 | * success: '/',
|
28 | * failure: null,
|
29 | * },
|
30 | * defaultErrors: ['Login/Email combination is not correct, please try again.'],
|
31 | * defaultMessages: ['You have been successfully logged in.'],
|
32 | * };
|
33 | * register?: boolean | NbPasswordStrategyModule = {
|
34 | * alwaysFail: false,
|
35 | * endpoint: 'register',
|
36 | * method: 'post',
|
37 | * requireValidToken: true,
|
38 | * redirect: {
|
39 | * success: '/',
|
40 | * failure: null,
|
41 | * },
|
42 | * defaultErrors: ['Something went wrong, please try again.'],
|
43 | * defaultMessages: ['You have been successfully registered.'],
|
44 | * };
|
45 | * requestPass?: boolean | NbPasswordStrategyModule = {
|
46 | * endpoint: 'request-pass',
|
47 | * method: 'post',
|
48 | * redirect: {
|
49 | * success: '/',
|
50 | * failure: null,
|
51 | * },
|
52 | * defaultErrors: ['Something went wrong, please try again.'],
|
53 | * defaultMessages: ['Reset password instructions have been sent to your email.'],
|
54 | * };
|
55 | * resetPass?: boolean | NbPasswordStrategyReset = {
|
56 | * endpoint: 'reset-pass',
|
57 | * method: 'put',
|
58 | * redirect: {
|
59 | * success: '/',
|
60 | * failure: null,
|
61 | * },
|
62 | * resetPasswordTokenKey: 'reset_password_token',
|
63 | * defaultErrors: ['Something went wrong, please try again.'],
|
64 | * defaultMessages: ['Your password has been successfully changed.'],
|
65 | * };
|
66 | * logout?: boolean | NbPasswordStrategyReset = {
|
67 | * alwaysFail: false,
|
68 | * endpoint: 'logout',
|
69 | * method: 'delete',
|
70 | * redirect: {
|
71 | * success: '/',
|
72 | * failure: null,
|
73 | * },
|
74 | * defaultErrors: ['Something went wrong, please try again.'],
|
75 | * defaultMessages: ['You have been successfully logged out.'],
|
76 | * };
|
77 | * refreshToken?: boolean | NbPasswordStrategyModule = {
|
78 | * endpoint: 'refresh-token',
|
79 | * method: 'post',
|
80 | * requireValidToken: true,
|
81 | * redirect: {
|
82 | * success: null,
|
83 | * failure: null,
|
84 | * },
|
85 | * defaultErrors: ['Something went wrong, please try again.'],
|
86 | * defaultMessages: ['Your token has been successfully refreshed.'],
|
87 | * };
|
88 | * token?: NbPasswordStrategyToken = {
|
89 | * class: NbAuthSimpleToken,
|
90 | * key: 'data.token',
|
91 | * getter: (module: string, res: HttpResponse<Object>, options: NbPasswordAuthStrategyOptions) => getDeepFromObject(
|
92 | * res.body,
|
93 | * options.token.key,
|
94 | * ),
|
95 | * };
|
96 | * errors?: NbPasswordStrategyMessage = {
|
97 | * key: 'data.errors',
|
98 | * getter: (module: string, res: HttpErrorResponse, options: NbPasswordAuthStrategyOptions) => getDeepFromObject(
|
99 | * res.error,
|
100 | * options.errors.key,
|
101 | * options[module].defaultErrors,
|
102 | * ),
|
103 | * };
|
104 | * messages?: NbPasswordStrategyMessage = {
|
105 | * key: 'data.messages',
|
106 | * getter: (module: string, res: HttpResponse<Object>, options: NbPasswordAuthStrategyOptions) => getDeepFromObject(
|
107 | * res.body,
|
108 | * options.messages.key,
|
109 | * options[module].defaultMessages,
|
110 | * ),
|
111 | * };
|
112 | * validation?: {
|
113 | * password?: {
|
114 | * required?: boolean;
|
115 | * minLength?: number | null;
|
116 | * maxLength?: number | null;
|
117 | * regexp?: string | null;
|
118 | * };
|
119 | * email?: {
|
120 | * required?: boolean;
|
121 | * regexp?: string | null;
|
122 | * };
|
123 | * fullName?: {
|
124 | * required?: boolean;
|
125 | * minLength?: number | null;
|
126 | * maxLength?: number | null;
|
127 | * regexp?: string | null;
|
128 | * };
|
129 | * };
|
130 | *}
|
131 | * ```
|
132 | */
|
133 | export declare class NbPasswordAuthStrategy extends NbAuthStrategy {
|
134 | protected http: HttpClient;
|
135 | private route;
|
136 | protected defaultOptions: NbPasswordAuthStrategyOptions;
|
137 | static setup(options: NbPasswordAuthStrategyOptions): [NbAuthStrategyClass, NbPasswordAuthStrategyOptions];
|
138 | constructor(http: HttpClient, route: ActivatedRoute);
|
139 | authenticate(data?: any): Observable<NbAuthResult>;
|
140 | register(data?: any): Observable<NbAuthResult>;
|
141 | requestPassword(data?: any): Observable<NbAuthResult>;
|
142 | resetPassword(data?: any): Observable<NbAuthResult>;
|
143 | logout(): Observable<NbAuthResult>;
|
144 | refreshToken(data?: any): Observable<NbAuthResult>;
|
145 | protected handleResponseError(res: any, module: string): Observable<NbAuthResult>;
|
146 | static ɵfac: i0.ɵɵFactoryDeclaration<NbPasswordAuthStrategy, never>;
|
147 | static ɵprov: i0.ɵɵInjectableDeclaration<NbPasswordAuthStrategy>;
|
148 | }
|