@@ -440,6 +440,72 @@ exports.getUserIdentityByAuth0Id = {
440440 }
441441} ;
442442
443+ function getEmailByHandle ( api , connection , next ) {
444+ var helper = api . helper ,
445+ handle = connection . params . handle ,
446+ dbConnectionMap = connection . dbConnectionMap ,
447+ apikey = connection . params . apiKey ,
448+ notfound = new NotFoundError ( 'Feelin lucky, punk?' ) ,
449+ response ;
450+
451+ async . waterfall ( [
452+ function ( cb ) {
453+ if ( process . env . ADMIN_API_KEY && apikey === process . env . ADMIN_API_KEY ) {
454+ api . dataAccess . executeQuery ( 'get_user_email_by_handle' ,
455+ { handle : handle } ,
456+ dbConnectionMap , cb ) ;
457+ } else {
458+ cb ( notfound ) ;
459+ }
460+ } ,
461+ function ( rs , cb ) {
462+ if ( ! rs [ 0 ] ) {
463+ cb ( notfound ) ;
464+ } else {
465+ response = {
466+ email : rs [ 0 ] . address
467+ } ;
468+ cb ( ) ;
469+ }
470+ }
471+ ] , function ( err ) {
472+ if ( err ) {
473+ helper . handleError ( api , connection , err ) ;
474+ } else {
475+ connection . response = response ;
476+ }
477+ next ( connection , true ) ;
478+ } ) ;
479+
480+ }
481+
482+ /**
483+ * The API for activate user
484+ * @since 1.2
485+ */
486+ exports . getEmailByHandle = {
487+ name : 'getEmailByHandle' ,
488+ description : 'Get email for user (private)' ,
489+ inputs : {
490+ required : [ 'handle' ] ,
491+ optional : [ 'apiKey' ]
492+ } ,
493+ blockedConnectionTypes : [ ] ,
494+ outputExample : { } ,
495+ version : 'v2' ,
496+ transaction : 'read' ,
497+ databases : [ 'common_oltp' ] ,
498+ cacheEnabled : false ,
499+ run : function ( api , connection , next ) {
500+ if ( connection . dbConnectionMap ) {
501+ api . log ( 'getEmailByHandle#run' , 'debug' ) ;
502+ getEmailByHandle ( api , connection , next ) ;
503+ } else {
504+ api . helper . handleNoConnection ( api , connection , next ) ;
505+ }
506+ }
507+ } ;
508+
443509/**
444510 * Handle the get marathon matches that user participated to.
445511 * @param {Object } api - The api object.
0 commit comments