21
21
// callback(new ValidationError("user_exists", "my error message"));
22
22
// 3. Something went wrong while trying to reach your database
23
23
// callback(new Error("my error message"));
24
-
25
24
const msg = 'Please implement the Create script for this database connection ' +
26
25
'at https://manage.auth0.com/#/connections/database';
27
26
return callback(new Error(msg)); */
28
- function create ( user , callback ) {
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
- primaryRole : user . user_metadata . primaryRole ,
56
- regSource : regSource ,
57
- utmSource : utmSource ,
58
- utmMedium : utmMedium ,
59
- utmCampaign : utmCampaign ,
60
- } ,
61
- options : {
62
- afterActivationURL : encodeURIComponent ( afterActivationURL ) ,
63
- } ,
64
- } ;
65
- //console.log("SignUp....", user, data);
66
- request . post (
67
- {
68
- url : "https://api." + configuration . DOMAIN + "/v3/users" ,
69
- json : data ,
70
- //for more options check:
71
- //https://github.com/mikeal/request#requestoptions-callback
72
- } ,
73
- function ( err , response , body ) {
74
- // console.log(err);
75
- // console.log(response.statusCode);
76
- // console.log(body.result.content);
77
-
78
- if ( err ) return callback ( err ) ;
79
- console . log ( body . result . content ) ;
80
- if ( response . statusCode !== 200 ) {
81
- //return callback(new ValidationError("lock.fallback",body.result.content));
82
- const error_message = body . result . content ;
83
- let code = "lock.fallback" ;
27
+ function create ( user , callback ) {
84
28
85
- if ( error_message . search ( "Handle may not contain a space" ) !== - 1 ) {
86
- code = "handle_invalid_space" ;
87
- } else if (
88
- error_message . search (
89
- "Length of Handle in character should be between 2 and 15"
90
- ) !== - 1
91
- ) {
92
- code = "handle_invalid_length" ;
93
- } else if (
94
- error_message . search (
95
- "Please choose another handle, not starting with admin"
96
- ) !== - 1
97
- ) {
98
- code = "handle_invalid_startwith_admin" ;
99
- } else if (
100
- error_message . search (
101
- "Handle may contain only letters, numbers and"
102
- ) !== - 1
103
- ) {
104
- code = "handle_invalid_constains_forbidden_char" ;
105
- } else if (
106
- error_message . search ( "Handle may not contain only punctuation" ) !== - 1
107
- ) {
108
- code = "handle_invalid_conatins_only_punctuation" ;
109
- } else if ( error_message . search ( "The user already exists" ) !== - 1 ) {
110
- code = "user_exists" ;
111
- } else if ( error_message . search ( "has already been taken" ) !== - 1 ) {
112
- code = "user_exists" ;
29
+ var countryObj = JSON . parse ( user . user_metadata . country ) ;
30
+ var regSource = user . user_metadata . regSource ;
31
+ var utmSource = user . user_metadata . utmSource ;
32
+ var utmMedium = user . user_metadata . utmMedium ;
33
+ var utmCampaign = user . user_metadata . utmCampaign ;
34
+ var retUrl = user . user_metadata . returnUrl ;
35
+ var afterActivationURL = retUrl ? retUrl : "https://www." + configuration . DOMAIN + "/start" ;
36
+ if ( regSource === configuration . REG_BUSINESS ) {
37
+ afterActivationURL = "https://connect." + configuration . DOMAIN ;
38
+ }
39
+ var data = {
40
+ "param" : {
41
+ "handle" : user . username ,
42
+ "email" : user . email ,
43
+ "credential" : {
44
+ "password" : user . password
45
+ } ,
46
+ "firstName" : user . user_metadata . firstName ,
47
+ "lastName" : user . user_metadata . lastName ,
48
+ "country" : {
49
+ "code" : countryObj . code ,
50
+ "isoAlpha3Code" : countryObj . alpha3 ,
51
+ "isoAlpha2Code" : countryObj . alpha2
52
+ } ,
53
+ "primaryRole" : user . user_metadata . primaryRole ,
54
+ "regSource" : regSource ,
55
+ "utmSource" : utmSource ,
56
+ "utmMedium" : utmMedium ,
57
+ "utmCampaign" : utmCampaign ,
58
+ } ,
59
+ "options" : {
60
+ "afterActivationURL" : encodeURIComponent ( afterActivationURL )
113
61
}
62
+ } ;
63
+ console . log ( "SignUp...." , user , data ) ;
64
+ request . post ( {
65
+ url : "http://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 ) {
114
70
115
- return callback ( new ValidationError ( code , error_message ) ) ;
71
+ console . log ( err ) ;
72
+ console . log ( response . statusCode ) ;
73
+ console . log ( body ) ;
116
74
117
- //return callback(new Error(body.result.content));
118
- }
119
- //if (response.statusCode === 401) return callback();
120
- /* const Analytics = require('analytics-node');
121
- const _ = require('lodash');
122
- var analytics = new Analytics('bkPtWMUMTYDhww2zsJluzxtdhtmSsyd9');
123
- analytics.identify({
124
- anonymousId: 'signup',
125
- traits: {
126
- user: _.omit(user, ['credential', 'password'])
127
- }
128
- });
129
- analytics.track({
130
- anonymousId: 'BXWXUWnilVUPdN01t2Se29Tw2ZYNGZvH',
131
- event: 'signUp',
132
- properties: _.omit(user, ['credential', 'password'])
133
- });*/
134
- /* const ua = require('universal-analytics');
135
- let visitor = ua('UA-6340959-1');
136
- visitor.pageview("/signup").send();
137
- var eParams = {
138
- ec: "utmCode",
139
- ea: "tracking",
140
- el: "tracking",
141
- cn: utmCampaign,
142
- cm: utmMedium,
143
- cs: utmSource,
144
- dp: "/signup"
145
- };
75
+ if ( err ) return callback ( err ) ;
146
76
147
- visitor.event(eParams).send(); */
148
- callback ( null ) ;
149
- }
150
- ) ; //end post request
151
- //callback(null);
77
+ if ( response . statusCode !== 200 ) {
78
+ return callback ( new ValidationError ( 'user_exists' , body . result . content ) ) ;
79
+ }
80
+ //if (response.statusCode === 401) return callback();
81
+ callback ( null ) ;
82
+ } ) ; //end post request
83
+ //callback(null);
152
84
}
153
85
154
- //}
86
+ //}
0 commit comments