1- const User = require ( './security/user' ) ;
1+ const
2+ BaseController = require ( './base' ) ,
3+ User = require ( './security/user' ) ;
24
35/**
46 * Auth controller
57 *
68 * @param kuzzle
79 * @constructor
810 */
9- class AuthController {
11+ class AuthController extends BaseController {
1012
1113 /**
1214 * constructor
1315 * @param kuzzle
1416 */
1517 constructor ( kuzzle ) {
16- this . _kuzzle = kuzzle ;
17- }
18-
19- get kuzzle ( ) {
20- return this . _kuzzle ;
18+ super ( kuzzle , 'auth' ) ;
2119 }
2220
2321 /**
@@ -27,8 +25,7 @@ class AuthController {
2725 * @return {Promise|*|PromiseLike<T>|Promise<T> }
2826 */
2927 checkToken ( token ) {
30- return this . kuzzle . query ( {
31- controller : 'auth' ,
28+ return this . query ( {
3229 action : 'checkToken' ,
3330 body : { token}
3431 } , { queuable : false } )
@@ -44,9 +41,8 @@ class AuthController {
4441 * @returns {Promise|*|PromiseLike<T>|Promise<T> }
4542 */
4643 createMyCredentials ( strategy , credentials , options = { } ) {
47- return this . kuzzle . query ( {
44+ return this . query ( {
4845 strategy,
49- controller : 'auth' ,
5046 action : 'createMyCredentials' ,
5147 body : credentials
5248 } , options )
@@ -60,9 +56,8 @@ class AuthController {
6056 * @returns {Promise|*|PromiseLike<T>|Promise<T> }
6157 */
6258 credentialsExist ( strategy , options = { } ) {
63- return this . kuzzle . query ( {
59+ return this . query ( {
6460 strategy,
65- controller : 'auth' ,
6661 action : 'credentialsExist'
6762 } , options )
6863 . then ( response => response . result ) ;
@@ -76,9 +71,8 @@ class AuthController {
7671 * @returns {Promise|*|PromiseLike<T>|Promise<T> }
7772 */
7873 deleteMyCredentials ( strategy , options = { } ) {
79- return this . kuzzle . query ( {
74+ return this . query ( {
8075 strategy,
81- controller : 'auth' ,
8276 action : 'deleteMyCredentials'
8377 } , options )
8478 . then ( response => response . result . acknowledged ) ;
@@ -90,8 +84,7 @@ class AuthController {
9084 * @returns {Promise|*|PromiseLike<T>|Promise<T> }
9185 */
9286 getCurrentUser ( options = { } ) {
93- return this . kuzzle . query ( {
94- controller : 'auth' ,
87+ return this . query ( {
9588 action : 'getCurrentUser'
9689 } , options )
9790 . then ( response => new User ( this . kuzzle , response . result . _id , response . result . _source , response . result . _meta ) ) ;
@@ -104,9 +97,8 @@ class AuthController {
10497 * @returns {Promise|*|PromiseLike<T>|Promise<T> }
10598 */
10699 getMyCredentials ( strategy , options = { } ) {
107- return this . kuzzle . query ( {
100+ return this . query ( {
108101 strategy,
109- controller : 'auth' ,
110102 action : 'getMyCredentials'
111103 } , options )
112104 . then ( response => response . result ) ;
@@ -119,8 +111,7 @@ class AuthController {
119111 * @returns {Promise|*|PromiseLike<T>|Promise<T> }
120112 */
121113 getMyRights ( options = { } ) {
122- return this . kuzzle . query ( {
123- controller : 'auth' ,
114+ return this . query ( {
124115 action : 'getMyRights'
125116 } , options )
126117 . then ( response => response . result . hits ) ;
@@ -133,8 +124,7 @@ class AuthController {
133124 * @returns {Promise|*|PromiseLike<T>|Promise<T> }
134125 */
135126 getStrategies ( options = { } ) {
136- return this . kuzzle . query ( {
137- controller : 'auth' ,
127+ return this . query ( {
138128 action : 'getStrategies'
139129 } , options )
140130 . then ( response => response . result ) ;
@@ -159,11 +149,10 @@ class AuthController {
159149 strategy,
160150 expiresIn,
161151 body : credentials ,
162- controller : 'auth' ,
163152 action : 'login'
164153 } ;
165154
166- return this . kuzzle . query ( request , { queuable : false } )
155+ return this . query ( request , { queuable : false } )
167156 . then ( response => {
168157 try {
169158 this . kuzzle . jwt = response . result . jwt ;
@@ -186,8 +175,7 @@ class AuthController {
186175 * @returns {Promise|*|PromiseLike<T>|Promise<T> }
187176 */
188177 logout ( ) {
189- return this . kuzzle . query ( {
190- controller : 'auth' ,
178+ return this . query ( {
191179 action : 'logout'
192180 } , { queuable : false } )
193181 . then ( ( ) => {
@@ -204,10 +192,9 @@ class AuthController {
204192 * @returns {Promise|*|PromiseLike<T>|Promise<T> }
205193 */
206194 updateMyCredentials ( strategy , credentials , options = { } ) {
207- return this . kuzzle . query ( {
195+ return this . query ( {
208196 strategy,
209197 body : credentials ,
210- controller : 'auth' ,
211198 action : 'updateMyCredentials'
212199 } , options )
213200 . then ( response => response . result ) ;
@@ -221,9 +208,8 @@ class AuthController {
221208 * @returns {Promise|*|PromiseLike<T>|Promise<T> }
222209 */
223210 updateSelf ( body , options = { } ) {
224- return this . kuzzle . query ( {
211+ return this . query ( {
225212 body,
226- controller : 'auth' ,
227213 action : 'updateSelf'
228214 } , options )
229215 . then ( response => new User ( this . kuzzle , response . result . _id , response . result . _source , response . result . _meta ) ) ;
@@ -238,10 +224,9 @@ class AuthController {
238224 * @returns {Promise|*|PromiseLike<T>|Promise<T> }
239225 */
240226 validateMyCredentials ( strategy , credentials , options = { } ) {
241- return this . kuzzle . query ( {
227+ return this . query ( {
242228 strategy,
243229 body : credentials ,
244- controller : 'auth' ,
245230 action : 'validateMyCredentials'
246231 } , options )
247232 . then ( response => response . result ) ;
@@ -255,12 +240,11 @@ class AuthController {
255240 */
256241 refreshToken ( options = { } ) {
257242 const query = {
258- controller : 'auth' ,
259243 action : 'refreshToken' ,
260244 expiresIn : options . expiresIn
261245 } ;
262246
263- return this . kuzzle . query ( query , options )
247+ return this . query ( query , options )
264248 . then ( response => {
265249 this . kuzzle . jwt = response . result . jwt ;
266250
0 commit comments