@@ -13,6 +13,7 @@ var async = require('async');
1313var _ = require ( 'underscore' ) ;
1414var BadRequestError = require ( '../errors/BadRequestError' ) ;
1515var ForbiddenError = require ( '../errors/ForbiddenError' ) ;
16+ var NotFoundError = require ( '../errors/NotFoundError' ) ;
1617var UnauthorizedError = require ( '../errors/UnauthorizedError' ) ;
1718var IllegalArgumentError = require ( '../errors/IllegalArgumentError' ) ;
1819
@@ -322,3 +323,98 @@ exports.getUserIdentity = {
322323 }
323324 }
324325} ;
326+
327+ /**
328+ * Get user identity information api.
329+ * @param {Object } api - The api object.
330+ * @param {Object } connection - The database connection map object.
331+ * @param {Function } next - The callback function.
332+ * @since 1.2
333+ */
334+ function getUserIdentityByAuth0Id ( api , connection , next ) {
335+ var helper = api . helper ,
336+ auth0id = connection . params . id ,
337+ userid = 0 ,
338+ dbConnectionMap = connection . dbConnectionMap ,
339+ notfound = new NotFoundError ( 'Feelin lucky, punk?' ) ,
340+ response ;
341+
342+ async . waterfall ( [
343+ function ( cb ) {
344+ try {
345+ var splits = auth0id . split ( '|' ) ;
346+ if ( splits [ 0 ] == 'ad' ) {
347+ cb ( null , [ { user_id : Number ( splits [ 1 ] ) } ] ) ;
348+ } else {
349+ api . helper . getProviderId ( splits [ 0 ] , function ( err , provider ) {
350+ if ( err ) {
351+ cb ( notfound ) ;
352+ } else {
353+ api . dataAccess . executeQuery ( "get_user_by_social_login" ,
354+ {
355+ social_user_id : splits [ 1 ] ,
356+ provider_id : provider
357+ } ,
358+ dbConnectionMap , cb ) ;
359+ }
360+ } ) ;
361+ }
362+ }
363+ catch ( exc ) {
364+ cb ( notfound ) ;
365+ }
366+ } ,
367+ function ( result , cb ) {
368+ userid = result [ 0 ] . user_id
369+ api . dataAccess . executeQuery ( 'get_user_email_and_handle' ,
370+ { userId : userid } ,
371+ dbConnectionMap , cb ) ;
372+ } ,
373+ function ( rs , cb ) {
374+ if ( ! rs [ 0 ] ) {
375+ cb ( notfound ) ;
376+ } else {
377+ response = {
378+ uid : userid ,
379+ handle : rs [ 0 ] . handle
380+ } ;
381+ cb ( ) ;
382+ }
383+ }
384+ ] , function ( err ) {
385+ if ( err ) {
386+ helper . handleError ( api , connection , err ) ;
387+ } else {
388+ connection . response = response ;
389+ }
390+ next ( connection , true ) ;
391+ } ) ;
392+
393+ }
394+
395+ /**
396+ * The API for activate user
397+ * @since 1.2
398+ */
399+ exports . getUserIdentityByAuth0Id = {
400+ name : 'getUserIdentityByAuth0Id' ,
401+ description : 'Get user identity information' ,
402+ inputs : {
403+ required : [ 'id' ] ,
404+ optional : [ ]
405+ } ,
406+ blockedConnectionTypes : [ ] ,
407+ outputExample : { } ,
408+ version : 'v2' ,
409+ transaction : 'read' ,
410+ databases : [ 'common_oltp' ] ,
411+ cacheEnabled : false ,
412+ run : function ( api , connection , next ) {
413+ if ( connection . dbConnectionMap ) {
414+ api . log ( 'getUserIdentityByAuth0Id#run' , 'debug' ) ;
415+ getUserIdentityByAuth0Id ( api , connection , next ) ;
416+ } else {
417+ api . helper . handleNoConnection ( api , connection , next ) ;
418+ }
419+ }
420+ } ;
0 commit comments