1
- const User = require ( './security/user' ) ;
1
+ const
2
+ BaseController = require ( './base' ) ,
3
+ User = require ( './security/user' ) ;
2
4
3
5
/**
4
6
* Auth controller
5
7
*
6
8
* @param kuzzle
7
9
* @constructor
8
10
*/
9
- class AuthController {
11
+ class AuthController extends BaseController {
10
12
11
13
/**
12
14
* constructor
13
15
* @param kuzzle
14
16
*/
15
17
constructor ( kuzzle ) {
16
- this . _kuzzle = kuzzle ;
17
- }
18
-
19
- get kuzzle ( ) {
20
- return this . _kuzzle ;
18
+ super ( kuzzle , 'auth' ) ;
21
19
}
22
20
23
21
/**
@@ -27,8 +25,7 @@ class AuthController {
27
25
* @return {Promise|*|PromiseLike<T>|Promise<T> }
28
26
*/
29
27
checkToken ( token ) {
30
- return this . kuzzle . query ( {
31
- controller : 'auth' ,
28
+ return this . query ( {
32
29
action : 'checkToken' ,
33
30
body : { token}
34
31
} , { queuable : false } )
@@ -44,9 +41,8 @@ class AuthController {
44
41
* @returns {Promise|*|PromiseLike<T>|Promise<T> }
45
42
*/
46
43
createMyCredentials ( strategy , credentials , options = { } ) {
47
- return this . kuzzle . query ( {
44
+ return this . query ( {
48
45
strategy,
49
- controller : 'auth' ,
50
46
action : 'createMyCredentials' ,
51
47
body : credentials
52
48
} , options )
@@ -60,9 +56,8 @@ class AuthController {
60
56
* @returns {Promise|*|PromiseLike<T>|Promise<T> }
61
57
*/
62
58
credentialsExist ( strategy , options = { } ) {
63
- return this . kuzzle . query ( {
59
+ return this . query ( {
64
60
strategy,
65
- controller : 'auth' ,
66
61
action : 'credentialsExist'
67
62
} , options )
68
63
. then ( response => response . result ) ;
@@ -76,9 +71,8 @@ class AuthController {
76
71
* @returns {Promise|*|PromiseLike<T>|Promise<T> }
77
72
*/
78
73
deleteMyCredentials ( strategy , options = { } ) {
79
- return this . kuzzle . query ( {
74
+ return this . query ( {
80
75
strategy,
81
- controller : 'auth' ,
82
76
action : 'deleteMyCredentials'
83
77
} , options )
84
78
. then ( response => response . result . acknowledged ) ;
@@ -90,8 +84,7 @@ class AuthController {
90
84
* @returns {Promise|*|PromiseLike<T>|Promise<T> }
91
85
*/
92
86
getCurrentUser ( options = { } ) {
93
- return this . kuzzle . query ( {
94
- controller : 'auth' ,
87
+ return this . query ( {
95
88
action : 'getCurrentUser'
96
89
} , options )
97
90
. then ( response => new User ( this . kuzzle , response . result . _id , response . result . _source , response . result . _meta ) ) ;
@@ -104,9 +97,8 @@ class AuthController {
104
97
* @returns {Promise|*|PromiseLike<T>|Promise<T> }
105
98
*/
106
99
getMyCredentials ( strategy , options = { } ) {
107
- return this . kuzzle . query ( {
100
+ return this . query ( {
108
101
strategy,
109
- controller : 'auth' ,
110
102
action : 'getMyCredentials'
111
103
} , options )
112
104
. then ( response => response . result ) ;
@@ -119,8 +111,7 @@ class AuthController {
119
111
* @returns {Promise|*|PromiseLike<T>|Promise<T> }
120
112
*/
121
113
getMyRights ( options = { } ) {
122
- return this . kuzzle . query ( {
123
- controller : 'auth' ,
114
+ return this . query ( {
124
115
action : 'getMyRights'
125
116
} , options )
126
117
. then ( response => response . result . hits ) ;
@@ -133,8 +124,7 @@ class AuthController {
133
124
* @returns {Promise|*|PromiseLike<T>|Promise<T> }
134
125
*/
135
126
getStrategies ( options = { } ) {
136
- return this . kuzzle . query ( {
137
- controller : 'auth' ,
127
+ return this . query ( {
138
128
action : 'getStrategies'
139
129
} , options )
140
130
. then ( response => response . result ) ;
@@ -159,11 +149,10 @@ class AuthController {
159
149
strategy,
160
150
expiresIn,
161
151
body : credentials ,
162
- controller : 'auth' ,
163
152
action : 'login'
164
153
} ;
165
154
166
- return this . kuzzle . query ( request , { queuable : false } )
155
+ return this . query ( request , { queuable : false } )
167
156
. then ( response => {
168
157
try {
169
158
this . kuzzle . jwt = response . result . jwt ;
@@ -186,8 +175,7 @@ class AuthController {
186
175
* @returns {Promise|*|PromiseLike<T>|Promise<T> }
187
176
*/
188
177
logout ( ) {
189
- return this . kuzzle . query ( {
190
- controller : 'auth' ,
178
+ return this . query ( {
191
179
action : 'logout'
192
180
} , { queuable : false } )
193
181
. then ( ( ) => {
@@ -204,10 +192,9 @@ class AuthController {
204
192
* @returns {Promise|*|PromiseLike<T>|Promise<T> }
205
193
*/
206
194
updateMyCredentials ( strategy , credentials , options = { } ) {
207
- return this . kuzzle . query ( {
195
+ return this . query ( {
208
196
strategy,
209
197
body : credentials ,
210
- controller : 'auth' ,
211
198
action : 'updateMyCredentials'
212
199
} , options )
213
200
. then ( response => response . result ) ;
@@ -221,9 +208,8 @@ class AuthController {
221
208
* @returns {Promise|*|PromiseLike<T>|Promise<T> }
222
209
*/
223
210
updateSelf ( body , options = { } ) {
224
- return this . kuzzle . query ( {
211
+ return this . query ( {
225
212
body,
226
- controller : 'auth' ,
227
213
action : 'updateSelf'
228
214
} , options )
229
215
. then ( response => new User ( this . kuzzle , response . result . _id , response . result . _source , response . result . _meta ) ) ;
@@ -238,10 +224,9 @@ class AuthController {
238
224
* @returns {Promise|*|PromiseLike<T>|Promise<T> }
239
225
*/
240
226
validateMyCredentials ( strategy , credentials , options = { } ) {
241
- return this . kuzzle . query ( {
227
+ return this . query ( {
242
228
strategy,
243
229
body : credentials ,
244
- controller : 'auth' ,
245
230
action : 'validateMyCredentials'
246
231
} , options )
247
232
. then ( response => response . result ) ;
@@ -255,12 +240,11 @@ class AuthController {
255
240
*/
256
241
refreshToken ( options = { } ) {
257
242
const query = {
258
- controller : 'auth' ,
259
243
action : 'refreshToken' ,
260
244
expiresIn : options . expiresIn
261
245
} ;
262
246
263
- return this . kuzzle . query ( query , options )
247
+ return this . query ( query , options )
264
248
. then ( response => {
265
249
this . kuzzle . jwt = response . result . jwt ;
266
250
0 commit comments