Skip to content

Commit a91b194

Browse files
author
sachin-maheshwari
authored
Merge pull request #308 from topcoder-platform/dev
Plat 742, utm code underscore issue
2 parents b0e3143 + 57d3a34 commit a91b194

File tree

13 files changed

+261
-229
lines changed

13 files changed

+261
-229
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ workflows:
7070
branches:
7171
only:
7272
- dev
73+
- jira-plat-742
7374

7475
# Production builds are exectuted only on tagged commits to the
7576
# master branch.

web-assets/auth0/dev-tenant/database/create.js

Lines changed: 105 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -26,83 +26,97 @@
2626
'at https://manage.auth0.com/#/connections/database';
2727
return callback(new Error(msg)); */
2828
function create(user, callback) {
29-
//console.log("landed here...................................");
30-
var countryObj = JSON.parse(user.user_metadata.country);
31-
var regSource = user.user_metadata.regSource;
32-
var utmSource = user.user_metadata.utmSource;
33-
var utmMedium = user.user_metadata.utmMedium;
34-
var utmCampaign = user.user_metadata.utmCampaign;
35-
var retUrl = user.user_metadata.returnUrl;
36-
var afterActivationURL = retUrl != null ? retUrl : "https://" + configuration.DOMAIN + "/home";
37-
if (regSource === configuration.REG_BUSINESS) {
38-
afterActivationURL = "https://connect." + configuration.DOMAIN;
39-
}
40-
var data = {
41-
"param": {
42-
"handle": user.username,
43-
"email": user.email,
44-
"credential": {
45-
"password": user.password
46-
},
47-
"firstName": user.user_metadata.firstName,
48-
"lastName": user.user_metadata.lastName,
49-
"country": {
50-
"code": countryObj.code,
51-
"isoAlpha3Code": countryObj.alpha3,
52-
"isoAlpha2Code": countryObj.alpha2
53-
},
54-
"regSource": regSource,
55-
"utmSource": utmSource,
56-
"utmMedium": utmMedium,
57-
"utmCampaign": utmCampaign,
58-
},
59-
"options": {
60-
"afterActivationURL": encodeURIComponent(afterActivationURL)
61-
}
62-
};
63-
//console.log("SignUp....", user, data);
64-
request.post({
65-
url: "https://api." + configuration.DOMAIN + "/v3/users",
66-
json: data
67-
//for more options check:
68-
//https://github.com/mikeal/request#requestoptions-callback
69-
}, function (err, response, body) {
70-
71-
// console.log(err);
72-
// console.log(response.statusCode);
73-
// console.log(body.result.content);
74-
75-
if (err) return callback(err);
76-
console.log(body.result.content);
77-
if (response.statusCode !== 200) {
78-
//return callback(new ValidationError("lock.fallback",body.result.content));
79-
const error_message = body.result.content;
80-
let code = "lock.fallback";
81-
82-
if (error_message.search("Handle may not contain a space") !== -1) {
83-
code = "handle_invalid_space";
84-
} else if (error_message.search("Length of Handle in character should be between 2 and 15") !== -1) {
85-
code = "handle_invalid_length";
86-
} else if (error_message.search("Please choose another handle, not starting with admin") !== -1) {
87-
code = "handle_invalid_startwith_admin";
88-
} else if (error_message.search('Handle may contain only letters, numbers and') !== -1) {
89-
code = "handle_invalid_constains_forbidden_char";
90-
} else if (error_message.search("Handle may not contain only punctuation") !== -1) {
91-
code = "handle_invalid_conatins_only_punctuation";
92-
} else if (error_message.search("The user already exists") !== -1) {
93-
code = "user_exists";
94-
} else if (error_message.search("has already been taken") !== -1) {
95-
code = "user_exists";
96-
}
29+
//console.log("landed here...................................");
30+
var countryObj = JSON.parse(user.user_metadata.country);
31+
var regSource = user.user_metadata.reg_source;
32+
var utmSource = user.user_metadata.utm_source;
33+
var utmMedium = user.user_metadata.utm_medium;
34+
var utmCampaign = user.user_metadata.utm_campaign;
35+
var retUrl = user.user_metadata.returnUrl;
36+
var afterActivationURL =
37+
retUrl !== null ? retUrl : "https://" + configuration.DOMAIN + "/home";
38+
if (regSource === configuration.REG_BUSINESS) {
39+
afterActivationURL = "https://connect." + configuration.DOMAIN;
40+
}
41+
var data = {
42+
param: {
43+
handle: user.username,
44+
email: user.email,
45+
credential: {
46+
password: user.password,
47+
},
48+
firstName: user.user_metadata.firstName,
49+
lastName: user.user_metadata.lastName,
50+
country: {
51+
code: countryObj.code,
52+
isoAlpha3Code: countryObj.alpha3,
53+
isoAlpha2Code: countryObj.alpha2,
54+
},
55+
regSource: regSource,
56+
utmSource: utmSource,
57+
utmMedium: utmMedium,
58+
utmCampaign: utmCampaign,
59+
},
60+
options: {
61+
afterActivationURL: encodeURIComponent(afterActivationURL),
62+
},
63+
};
64+
//console.log("SignUp....", user, data);
65+
request.post(
66+
{
67+
url: "https://api." + configuration.DOMAIN + "/v3/users",
68+
json: data,
69+
//for more options check:
70+
//https://github.com/mikeal/request#requestoptions-callback
71+
},
72+
function (err, response, body) {
73+
// console.log(err);
74+
// console.log(response.statusCode);
75+
// console.log(body.result.content);
9776

77+
if (err) return callback(err);
78+
console.log(body.result.content);
79+
if (response.statusCode !== 200) {
80+
//return callback(new ValidationError("lock.fallback",body.result.content));
81+
const error_message = body.result.content;
82+
let code = "lock.fallback";
9883

84+
if (error_message.search("Handle may not contain a space") !== -1) {
85+
code = "handle_invalid_space";
86+
} else if (
87+
error_message.search(
88+
"Length of Handle in character should be between 2 and 15"
89+
) !== -1
90+
) {
91+
code = "handle_invalid_length";
92+
} else if (
93+
error_message.search(
94+
"Please choose another handle, not starting with admin"
95+
) !== -1
96+
) {
97+
code = "handle_invalid_startwith_admin";
98+
} else if (
99+
error_message.search(
100+
"Handle may contain only letters, numbers and"
101+
) !== -1
102+
) {
103+
code = "handle_invalid_constains_forbidden_char";
104+
} else if (
105+
error_message.search("Handle may not contain only punctuation") !== -1
106+
) {
107+
code = "handle_invalid_conatins_only_punctuation";
108+
} else if (error_message.search("The user already exists") !== -1) {
109+
code = "user_exists";
110+
} else if (error_message.search("has already been taken") !== -1) {
111+
code = "user_exists";
112+
}
99113

100-
return callback(new ValidationError(code, error_message));
114+
return callback(new ValidationError(code, error_message));
101115

102-
//return callback(new Error(body.result.content));
103-
}
104-
//if (response.statusCode === 401) return callback();
105-
/* const Analytics = require('analytics-node');
116+
//return callback(new Error(body.result.content));
117+
}
118+
//if (response.statusCode === 401) return callback();
119+
/* const Analytics = require('analytics-node');
106120
const _ = require('lodash');
107121
var analytics = new Analytics('bkPtWMUMTYDhww2zsJluzxtdhtmSsyd9');
108122
analytics.identify({
@@ -116,9 +130,24 @@ function create(user, callback) {
116130
event: 'signUp',
117131
properties: _.omit(user, ['credential', 'password'])
118132
});*/
119-
callback(null);
120-
}); //end post request
121-
//callback(null);
133+
/* const ua = require('universal-analytics');
134+
let visitor = ua('UA-6340959-1');
135+
visitor.pageview("/signup").send();
136+
var eParams = {
137+
ec: "utmCode",
138+
ea: "tracking",
139+
el: "tracking",
140+
cn: utmCampaign,
141+
cm: utmMedium,
142+
cs: utmSource,
143+
dp: "/signup"
144+
};
145+
146+
visitor.event(eParams).send(); */
147+
callback(null);
148+
}
149+
); //end post request
150+
//callback(null);
122151
}
123152

124153
//}
Lines changed: 72 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,78 @@
11

22
function (user, context, callback) {
3-
if (context.clientID === configuration.CLIENT_ACCOUNTS_LOGIN) { //
4-
const _ = require('lodash');
5-
6-
// TODO: implement your rule
7-
// if (context.protocol === "redirect-callback") {
8-
// User was redirected to the /continue endpoint
9-
if (context.redirect) {
10-
return callback(null, user, context);
11-
// returnning from here no need to check further
12-
}
13-
// otherwise to nothing
14-
15-
console.log("Enter Rule: Custom-Claims");
16-
let handle = _.get(user, "handle", null);
17-
const provider = _.get(user, "identities[0].provider", null);
18-
if (!handle && provider === "auth0") {
19-
handle = _.get(user, "nickname", null);
20-
}
21-
console.log("Fetch roles for email/handle: ", user.email, handle, provider);
22-
23-
global.AUTH0_CLAIM_NAMESPACE = "https://" + configuration.DOMAIN + "/";
24-
try {
25-
request.post({
26-
url: 'https://api.' + configuration.DOMAIN + '/v3/users/roles',
27-
form: {
28-
email: user.email,
29-
handle: handle
30-
}
31-
}, function (err, response, body) {
32-
console.log("called topcoder api for role: response status - ", response.statusCode);
33-
if (err) return callback(err, user, context);
34-
if (response.statusCode !== 200) {
35-
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:[email protected]">[email protected]</a>. Back to application ', user, context);
36-
}
37-
38-
let res = JSON.parse(body);
39-
// TODO need to double sure about multiple result or no result
40-
let userId = res.result.content.id;
41-
let handle = res.result.content.handle;
42-
let roles = res.result.content.roles.map(function (role) {
43-
return role.roleName;
44-
});
45-
let userStatus = res.result.content.active; // true/false
3+
if (context.clientID === configuration.CLIENT_ACCOUNTS_LOGIN) { //
4+
const _ = require('lodash');
5+
6+
// TODO: implement your rule
7+
// if (context.protocol === "redirect-callback") {
8+
// User was redirected to the /continue endpoint
9+
if (context.redirect) {
10+
return callback(null, user, context);
11+
// returnning from here no need to check further
12+
}
13+
// otherwise to nothing
14+
15+
console.log("Enter Rule: Custom-Claims");
16+
let handle = _.get(user, "handle", null);
17+
const provider = _.get(user, "identities[0].provider", null);
18+
if (!handle && provider === "auth0") {
19+
handle = _.get(user, "nickname", null);
20+
}
21+
console.log("Fetch roles for email/handle: ", user.email, handle, provider);
22+
23+
global.AUTH0_CLAIM_NAMESPACE = "https://" + configuration.DOMAIN + "/";
24+
try {
25+
request.post({
26+
url: 'https://api.' + configuration.DOMAIN + '/v3/users/roles',
27+
form: {
28+
email: user.email,
29+
handle: handle
30+
}
31+
}, function (err, response, body) {
32+
console.log("called topcoder api for role: response status - ", response.statusCode);
33+
if (err) return callback(err, user, context);
34+
if (response.statusCode !== 200) {
35+
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:[email protected]">[email protected]</a>. Back to application ', user, context);
36+
}
37+
38+
let res = JSON.parse(body);
39+
// TODO need to double sure about multiple result or no result
40+
let userId = res.result.content.id;
41+
let handle = res.result.content.handle;
42+
let roles = res.result.content.roles.map(function (role) {
43+
return role.roleName;
44+
});
45+
let userStatus = res.result.content.active; // true/false
4646

47-
// TEMP
48-
let tcsso = res.result.content.regSource || '';
47+
// TEMP
48+
let tcsso = res.result.content.regSource || '';
4949

50-
context.idToken[global.AUTH0_CLAIM_NAMESPACE + 'roles'] = roles;
51-
context.idToken[global.AUTH0_CLAIM_NAMESPACE + 'userId'] = userId;
52-
context.idToken[global.AUTH0_CLAIM_NAMESPACE + 'handle'] = handle;
53-
context.idToken[global.AUTH0_CLAIM_NAMESPACE + 'user_id'] = user.identities[0].provider + "|" + userId;
54-
context.idToken[global.AUTH0_CLAIM_NAMESPACE + 'tcsso'] = tcsso;
55-
context.idToken[global.AUTH0_CLAIM_NAMESPACE + 'active'] = userStatus;
56-
context.idToken.nickname = handle;
57-
//console.log(user, context);
58-
if (!userStatus) {
59-
context.redirect = {
60-
url: `https://accounts-auth0.${configuration.DOMAIN}/check_email.html`
61-
};
62-
return callback(null, user, context);
63-
}
64-
if (!userStatus && context.login_counts > 1) {
65-
return callback('Login Alert: Please verify your email first! Please connect to our support <a href="mailto:[email protected]">[email protected]</a>. Back to application ', user, context);
66-
}
50+
context.idToken[global.AUTH0_CLAIM_NAMESPACE + 'roles'] = roles;
51+
context.idToken[global.AUTH0_CLAIM_NAMESPACE + 'userId'] = userId;
52+
context.idToken[global.AUTH0_CLAIM_NAMESPACE + 'handle'] = handle;
53+
context.idToken[global.AUTH0_CLAIM_NAMESPACE + 'user_id'] = user.identities[0].provider + "|" + userId;
54+
context.idToken[global.AUTH0_CLAIM_NAMESPACE + 'tcsso'] = tcsso;
55+
context.idToken[global.AUTH0_CLAIM_NAMESPACE + 'active'] = userStatus;
56+
context.idToken.nickname = handle;
57+
//console.log(user, context);
58+
if (!userStatus) {
59+
context.redirect = {
60+
url: `https://accounts-auth0.${configuration.DOMAIN}/check_email.html`
61+
};
6762
return callback(null, user, context);
68-
}
69-
);
70-
} catch (e) {
71-
console.log("Error in calling user roles" + e);
72-
return callback("Something went worng!. Please retry.", user, context);
73-
}
74-
} else {
75-
// for other apps do nothing
76-
return callback(null, user, context);
77-
}
63+
}
64+
if (!userStatus && context.login_counts > 1) {
65+
return callback('Login Alert: Please verify your email first! Please connect to our support <a href="mailto:[email protected]">[email protected]</a>. Back to application ', user, context);
66+
}
67+
return callback(null, user, context);
68+
}
69+
);
70+
} catch (e) {
71+
console.log("Error in calling user roles" + e);
72+
return callback("Something went worng!. Please retry.", user, context);
73+
}
74+
} else {
75+
// for other apps do nothing
76+
return callback(null, user, context);
77+
}
7878
}

0 commit comments

Comments
 (0)