Skip to content
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
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ workflows:
branches:
only:
- dev
- jira-plat-742

# Production builds are exectuted only on tagged commits to the
# master branch.
Expand Down
181 changes: 105 additions & 76 deletions web-assets/auth0/dev-tenant/database/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,83 +26,97 @@
'at https://manage.auth0.com/#/connections/database';
return callback(new Error(msg)); */
function create(user, callback) {
//console.log("landed here...................................");
var countryObj = JSON.parse(user.user_metadata.country);
var regSource = user.user_metadata.regSource;
var utmSource = user.user_metadata.utmSource;
var utmMedium = user.user_metadata.utmMedium;
var utmCampaign = user.user_metadata.utmCampaign;
var retUrl = user.user_metadata.returnUrl;
var afterActivationURL = retUrl != null ? retUrl : "https://" + configuration.DOMAIN + "/home";
if (regSource === configuration.REG_BUSINESS) {
afterActivationURL = "https://connect." + configuration.DOMAIN;
}
var data = {
"param": {
"handle": user.username,
"email": user.email,
"credential": {
"password": user.password
},
"firstName": user.user_metadata.firstName,
"lastName": user.user_metadata.lastName,
"country": {
"code": countryObj.code,
"isoAlpha3Code": countryObj.alpha3,
"isoAlpha2Code": countryObj.alpha2
},
"regSource": regSource,
"utmSource": utmSource,
"utmMedium": utmMedium,
"utmCampaign": utmCampaign,
},
"options": {
"afterActivationURL": encodeURIComponent(afterActivationURL)
}
};
//console.log("SignUp....", user, data);
request.post({
url: "https://api." + configuration.DOMAIN + "/v3/users",
json: data
//for more options check:
//https://github.com/mikeal/request#requestoptions-callback
}, function (err, response, body) {

// console.log(err);
// console.log(response.statusCode);
// console.log(body.result.content);

if (err) return callback(err);
console.log(body.result.content);
if (response.statusCode !== 200) {
//return callback(new ValidationError("lock.fallback",body.result.content));
const error_message = body.result.content;
let code = "lock.fallback";

if (error_message.search("Handle may not contain a space") !== -1) {
code = "handle_invalid_space";
} else if (error_message.search("Length of Handle in character should be between 2 and 15") !== -1) {
code = "handle_invalid_length";
} else if (error_message.search("Please choose another handle, not starting with admin") !== -1) {
code = "handle_invalid_startwith_admin";
} else if (error_message.search('Handle may contain only letters, numbers and') !== -1) {
code = "handle_invalid_constains_forbidden_char";
} else if (error_message.search("Handle may not contain only punctuation") !== -1) {
code = "handle_invalid_conatins_only_punctuation";
} else if (error_message.search("The user already exists") !== -1) {
code = "user_exists";
} else if (error_message.search("has already been taken") !== -1) {
code = "user_exists";
}
//console.log("landed here...................................");
var countryObj = JSON.parse(user.user_metadata.country);
var regSource = user.user_metadata.reg_source;
var utmSource = user.user_metadata.utm_source;
var utmMedium = user.user_metadata.utm_medium;
var utmCampaign = user.user_metadata.utm_campaign;
var retUrl = user.user_metadata.returnUrl;
var afterActivationURL =
retUrl !== null ? retUrl : "https://" + configuration.DOMAIN + "/home";
if (regSource === configuration.REG_BUSINESS) {
afterActivationURL = "https://connect." + configuration.DOMAIN;
}
var data = {
param: {
handle: user.username,
email: user.email,
credential: {
password: user.password,
},
firstName: user.user_metadata.firstName,
lastName: user.user_metadata.lastName,
country: {
code: countryObj.code,
isoAlpha3Code: countryObj.alpha3,
isoAlpha2Code: countryObj.alpha2,
},
regSource: regSource,
utmSource: utmSource,
utmMedium: utmMedium,
utmCampaign: utmCampaign,
},
options: {
afterActivationURL: encodeURIComponent(afterActivationURL),
},
};
//console.log("SignUp....", user, data);
request.post(
{
url: "https://api." + configuration.DOMAIN + "/v3/users",
json: data,
//for more options check:
//https://github.com/mikeal/request#requestoptions-callback
},
function (err, response, body) {
// console.log(err);
// console.log(response.statusCode);
// console.log(body.result.content);

if (err) return callback(err);
console.log(body.result.content);
if (response.statusCode !== 200) {
//return callback(new ValidationError("lock.fallback",body.result.content));
const error_message = body.result.content;
let code = "lock.fallback";

if (error_message.search("Handle may not contain a space") !== -1) {
code = "handle_invalid_space";
} else if (
error_message.search(
"Length of Handle in character should be between 2 and 15"
) !== -1
) {
code = "handle_invalid_length";
} else if (
error_message.search(
"Please choose another handle, not starting with admin"
) !== -1
) {
code = "handle_invalid_startwith_admin";
} else if (
error_message.search(
"Handle may contain only letters, numbers and"
) !== -1
) {
code = "handle_invalid_constains_forbidden_char";
} else if (
error_message.search("Handle may not contain only punctuation") !== -1
) {
code = "handle_invalid_conatins_only_punctuation";
} else if (error_message.search("The user already exists") !== -1) {
code = "user_exists";
} else if (error_message.search("has already been taken") !== -1) {
code = "user_exists";
}

return callback(new ValidationError(code, error_message));
return callback(new ValidationError(code, error_message));

//return callback(new Error(body.result.content));
}
//if (response.statusCode === 401) return callback();
/* const Analytics = require('analytics-node');
//return callback(new Error(body.result.content));
}
//if (response.statusCode === 401) return callback();
/* const Analytics = require('analytics-node');
const _ = require('lodash');
var analytics = new Analytics('bkPtWMUMTYDhww2zsJluzxtdhtmSsyd9');
analytics.identify({
Expand All @@ -116,9 +130,24 @@ function create(user, callback) {
event: 'signUp',
properties: _.omit(user, ['credential', 'password'])
});*/
callback(null);
}); //end post request
//callback(null);
/* const ua = require('universal-analytics');
let visitor = ua('UA-6340959-1');
visitor.pageview("/signup").send();
var eParams = {
ec: "utmCode",
ea: "tracking",
el: "tracking",
cn: utmCampaign,
cm: utmMedium,
cs: utmSource,
dp: "/signup"
};

visitor.event(eParams).send(); */
callback(null);
}
); //end post request
//callback(null);
}

//}
144 changes: 72 additions & 72 deletions web-assets/auth0/dev-tenant/rules/custom.js
Original file line number Diff line number Diff line change
@@ -1,78 +1,78 @@

function (user, context, callback) {
if (context.clientID === configuration.CLIENT_ACCOUNTS_LOGIN) { //
const _ = require('lodash');
// TODO: implement your rule
// if (context.protocol === "redirect-callback") {
// User was redirected to the /continue endpoint
if (context.redirect) {
return callback(null, user, context);
// returnning from here no need to check further
}
// otherwise to nothing
console.log("Enter Rule: Custom-Claims");
let handle = _.get(user, "handle", null);
const provider = _.get(user, "identities[0].provider", null);
if (!handle && provider === "auth0") {
handle = _.get(user, "nickname", null);
}
console.log("Fetch roles for email/handle: ", user.email, handle, provider);
global.AUTH0_CLAIM_NAMESPACE = "https://" + configuration.DOMAIN + "/";
try {
request.post({
url: 'https://api.' + configuration.DOMAIN + '/v3/users/roles',
form: {
email: user.email,
handle: handle
}
}, function (err, response, body) {
console.log("called topcoder api for role: response status - ", response.statusCode);
if (err) return callback(err, user, context);
if (response.statusCode !== 200) {
return callback('Login Error: Whoops! Something went wrong. Looks like your registered email has discrepancy with Authentication. Please connect to our support <a href="mailto:support@topcoder.com">support@topcoder.com</a>. Back to application ', user, context);
}
let res = JSON.parse(body);
// TODO need to double sure about multiple result or no result
let userId = res.result.content.id;
let handle = res.result.content.handle;
let roles = res.result.content.roles.map(function (role) {
return role.roleName;
});
let userStatus = res.result.content.active; // true/false
if (context.clientID === configuration.CLIENT_ACCOUNTS_LOGIN) { //
const _ = require('lodash');

// TODO: implement your rule
// if (context.protocol === "redirect-callback") {
// User was redirected to the /continue endpoint
if (context.redirect) {
return callback(null, user, context);
// returnning from here no need to check further
}
// otherwise to nothing

console.log("Enter Rule: Custom-Claims");
let handle = _.get(user, "handle", null);
const provider = _.get(user, "identities[0].provider", null);
if (!handle && provider === "auth0") {
handle = _.get(user, "nickname", null);
}
console.log("Fetch roles for email/handle: ", user.email, handle, provider);

global.AUTH0_CLAIM_NAMESPACE = "https://" + configuration.DOMAIN + "/";
try {
request.post({
url: 'https://api.' + configuration.DOMAIN + '/v3/users/roles',
form: {
email: user.email,
handle: handle
}
}, function (err, response, body) {
console.log("called topcoder api for role: response status - ", response.statusCode);
if (err) return callback(err, user, context);
if (response.statusCode !== 200) {
return callback('Login Error: Whoops! Something went wrong. Looks like your registered email has discrepancy with Authentication. Please connect to our support <a href="mailto:support@topcoder.com">support@topcoder.com</a>. Back to application ', user, context);
}

let res = JSON.parse(body);
// TODO need to double sure about multiple result or no result
let userId = res.result.content.id;
let handle = res.result.content.handle;
let roles = res.result.content.roles.map(function (role) {
return role.roleName;
});
let userStatus = res.result.content.active; // true/false

// TEMP
let tcsso = res.result.content.regSource || '';
// TEMP
let tcsso = res.result.content.regSource || '';

context.idToken[global.AUTH0_CLAIM_NAMESPACE + 'roles'] = roles;
context.idToken[global.AUTH0_CLAIM_NAMESPACE + 'userId'] = userId;
context.idToken[global.AUTH0_CLAIM_NAMESPACE + 'handle'] = handle;
context.idToken[global.AUTH0_CLAIM_NAMESPACE + 'user_id'] = user.identities[0].provider + "|" + userId;
context.idToken[global.AUTH0_CLAIM_NAMESPACE + 'tcsso'] = tcsso;
context.idToken[global.AUTH0_CLAIM_NAMESPACE + 'active'] = userStatus;
context.idToken.nickname = handle;
//console.log(user, context);
if (!userStatus) {
context.redirect = {
url: `https://accounts-auth0.${configuration.DOMAIN}/check_email.html`
};
return callback(null, user, context);
}
if (!userStatus && context.login_counts > 1) {
return callback('Login Alert: Please verify your email first! Please connect to our support <a href="mailto:support@topcoder.com">support@topcoder.com</a>. Back to application ', user, context);
}
context.idToken[global.AUTH0_CLAIM_NAMESPACE + 'roles'] = roles;
context.idToken[global.AUTH0_CLAIM_NAMESPACE + 'userId'] = userId;
context.idToken[global.AUTH0_CLAIM_NAMESPACE + 'handle'] = handle;
context.idToken[global.AUTH0_CLAIM_NAMESPACE + 'user_id'] = user.identities[0].provider + "|" + userId;
context.idToken[global.AUTH0_CLAIM_NAMESPACE + 'tcsso'] = tcsso;
context.idToken[global.AUTH0_CLAIM_NAMESPACE + 'active'] = userStatus;
context.idToken.nickname = handle;
//console.log(user, context);
if (!userStatus) {
context.redirect = {
url: `https://accounts-auth0.${configuration.DOMAIN}/check_email.html`
};
return callback(null, user, context);
}
);
} catch (e) {
console.log("Error in calling user roles" + e);
return callback("Something went worng!. Please retry.", user, context);
}
} else {
// for other apps do nothing
return callback(null, user, context);
}
}
if (!userStatus && context.login_counts > 1) {
return callback('Login Alert: Please verify your email first! Please connect to our support <a href="mailto:support@topcoder.com">support@topcoder.com</a>. Back to application ', user, context);
}
return callback(null, user, context);
}
);
} catch (e) {
console.log("Error in calling user roles" + e);
return callback("Something went worng!. Please retry.", user, context);
}
} else {
// for other apps do nothing
return callback(null, user, context);
}
}
Loading