diff --git a/actions/user.js b/actions/user.js index fd72b92ac..46ebe2682 100644 --- a/actions/user.js +++ b/actions/user.js @@ -322,3 +322,89 @@ exports.getUserIdentity = { } } }; + +/** + * Get user identity information api. + * @param {Object} api - The api object. + * @param {Object} connection - The database connection map object. + * @param {Function} next - The callback function. + * @since 1.2 + */ +function getUserIdentityByAuth0Id(api, connection, next) { + var helper = api.helper, + auth0id = connection.params.id, + userid = 0, + dbConnectionMap = connection.dbConnectionMap, + response; + + async.waterfall([ + function (cb) { + var splits = auth0id.split('|'); + if (splits[0] == 'ad') { + cb(null, [{ user_id: Number(splits[1]) }]); + } else { + api.helper.getProviderId(splits[0], function(err, provider) { + if (err) { + cb(err); + } else { + api.dataAccess.executeQuery("get_user_by_social_login", + { + social_user_id: splits[1], + provider_id: provider + }, + dbConnectionMap, cb); + } + }); + } + }, + function (result, cb) { + userid = result[0].user_id + api.dataAccess.executeQuery('get_user_email_and_handle', + { userId: userid }, + dbConnectionMap, cb); + }, + function (rs, cb) { + response = { + uid: userid, + handle: rs[0].handle, + email: rs[0].address + }; + cb(); + } + ], function (err) { + if (err) { + helper.handleError(api, connection, err); + } else { + connection.response = response; + } + next(connection, true); + }); + +} + +/** + * The API for activate user + * @since 1.2 + */ +exports.getUserIdentityByAuth0Id = { + name: 'getUserIdentityByAuth0Id', + description: 'Get user identity information', + inputs: { + required: ['id'], + optional: [] + }, + blockedConnectionTypes: [], + outputExample: {}, + version: 'v2', + transaction: 'read', + databases: ['common_oltp'], + cacheEnabled: false, + run: function (api, connection, next) { + if (connection.dbConnectionMap) { + api.log('getUserIdentityByAuth0Id#run', 'debug'); + getUserIdentityByAuth0Id(api, connection, next); + } else { + api.helper.handleNoConnection(api, connection, next); + } + } +}; diff --git a/routes.js b/routes.js index f2f94f0a4..4ae482296 100755 --- a/routes.js +++ b/routes.js @@ -258,6 +258,7 @@ exports.routes = { { path: "/:apiVersion/user/challenges", action: "getMyChallenges" }, { path: "/:apiVersion/user/activation-email", action: "userActivationEmail" }, + { path: "/:apiVersion/user/identity/:id", action: "getUserIdentityByAuth0Id" }, { path: "/:apiVersion/user/identity", action: "getUserIdentity" }, { path: "/:apiVersion/users/tops/:trackType", action: "getTopTrackMembers" },