Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Commit f5b5628

Browse files
committed
get email by handle using ADMIN_API_KEY
1 parent d25e025 commit f5b5628

File tree

6 files changed

+83
-1
lines changed

6 files changed

+83
-1
lines changed

actions/user.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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.

config/api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ exports.default = {
2828
// disables the whitelisting of client params
2929
disableParamScrubbing: false,
3030
// params you would like hidden from any logs
31-
filteredParams: ['password', 'oldPassword', 'newPassword', 'fileData'],
31+
filteredParams: ['password', 'oldPassword', 'newPassword', 'fileData', 'apiKey'],
3232
// The default filetype to server when a user requests a directory
3333
directoryFileType : 'index.html',
3434
// configuration for your actionhero project structure

deploy/development.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,5 @@ export WKHTMLTOIMAGE_IMAGE_WIDTH=1024
9898
export HIGHLIGHT_STYLE_LINK=http://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/styles/%OVERRIDE_STYLE_NAME%.min.css
9999

100100
export JWT_TOKEN_COOKIE_KEY="tcjwt_vm"
101+
102+
export ADMIN_API_KEY=1234567

queries/get_user_email_by_handle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
SELECT
2+
u.handle
3+
, e.address
4+
FROM user u
5+
, email e
6+
WHERE u.handle = '@handle@'
7+
AND e.primary_ind = 1
8+
AND u.user_id = e.user_id

queries/get_user_email_by_handle.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name" : "get_user_email_by_handle",
3+
"db" : "common_oltp",
4+
"sqlfile" : "get_user_email_by_handle"
5+
}

routes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ exports.routes = {
277277
{ path: "/:apiVersion/user/challenges", action: "getMyChallenges" },
278278
{ path: "/:apiVersion/user/activation-email", action: "userActivationEmail" },
279279
{ path: "/:apiVersion/user/tcid/:id", action: "getUserIdentityByAuth0Id" },
280+
{ path: "/:apiVersion/user/email/:handle", action: "getEmailByHandle" },
280281
{ path: "/:apiVersion/user/identity", action: "getUserIdentity" },
281282
{ path: "/:apiVersion/user/:handle/challenges/marathon", action: "getUserMarathonMatches" },
282283
{ path: "/:apiVersion/user/:handle/challenges/algo", action: "getUserAlgorithmChallenges" },

0 commit comments

Comments
 (0)