Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions actions/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
};
1 change: 1 addition & 0 deletions routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down