-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdrupal-server.js
34 lines (26 loc) · 1.15 KB
/
drupal-server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Meteor.methods({
drupalCreateNewUserByEmail: function (email, subscribed_to_mailing_list) {
var return_obj = {};
// first let's see if it's a validly formatted email address
if (validateEmail(email) == false) {
return_obj.reason = "Whoops! It appears that you've entered an invalid email address.";
throw new Meteor.Error(-1, return_obj.reason);
}
// validate profile info
if (typeof(subscribed_to_mailing_list) != "boolean") {
return_obj.reason = "Whoops! Subscribed must be true or false.";
throw new Meteor.Error(-1, return_obj.reason);
}
// create user
profile = {};
profile.subscribed_to_mailing_list = subscribed_to_mailing_list;
var uid = Accounts.createUser({email: email, profile: profile});
Accounts.sendEnrollmentEmail(uid);
return_obj.confirmation = "Success! Please check your email for further instructions.";
return return_obj;
}
});
this.validateEmail = function(email) {
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
};