【发布时间】:2014-05-17 11:05:30
【问题描述】:
我在我的流星应用程序的首页添加了一个表单,其中包含电子邮件和用户姓名。它会发送一封注册电子邮件,其中包含一个链接,供他们创建密码。创建帐户时需要添加许多后台配置文件设置,并且它从 {{loginButtons}} 帐户创建中起作用。出于某种原因,从 createUser 调用时 onCreateUser 不起作用。我哪里出错了?提前致谢。
注册表:
<form role="form" class="form-horiztonal" id="signup">
<div class="form-group">
<label for="name" class="col-sm-3 control-label">Name</label>
<div class="col-sm-9">
<input name="name" id="name" class="form-control" type="text" placeholder="Name"/>
</div>
</div>
<div class="form-group">
<label for="email" class="col-sm-3 control-label">Email</label>
<div class="col-sm-9">
<input name="email" class="form-control" type="email" placeholder="example@gmail.com"/>
</div>
</div>
<div class="form-group">
<div class="col-sm-9 col-sm-offset-3">
<input type="submit" value="Get Started!" class="btn btn-success"/>
</div>
</div>
</form>
页面事件:
Template.landing.events({
'submit form#signup' : function(e) {
e.preventDefault();
var user = {
name: $(e.target).find('[name=name]').val(),
email: $(e.target).find('[name=email]').val()
}
Meteor.call('signup', user, function(error, id) {
if (error) {
// display the error to the user
console.log(error);
} else {
Router.go('awesome');
}
});
}
});
注册方法(在服务器中):
Meteor.methods({
signup: function(user) {
// ensure the user is logged in
if (!user)
throw new Meteor.Error(401, "Can't make a user without a user object");
// ensure the user has a name
if (!user.name)
throw new Meteor.Error(422, 'Please fill in a name');
// ensure there is an email
if (!user.email)
throw new Meteor.Error(424, 'Please fill in an email address');
var userId = Accounts.createUser(user);
if(userId) {
Accounts.sendEnrollmentEmail(userId);
return userId;
}
}
});
onCreateUser(在服务器中):
Accounts.onCreateUser(function(options, user) {
if (options.profile) {
user.profile = options.profile; //Copy initial profile settings
//Set roles
user.roles = ["User"];
//Account settings
user.profile.active = false; //Account is not active on creation
user.profile.trial = true; //Accounts have 1 month trial
user.profile.expiration = moment().add('M', 1); //No expiration date on unactivated accounts
user.profile.bill = null; //Bill monthly, yearly
user.profile.ppId = null; //Paypal Id for associated credit card
user.profile.resources = 0; //Number of resources an account has created
user.profile.resourceLimit = 2; //Limit for the number of resources an account can have
//User settings
user.profile.name = null; //Name is blank when created
user.profile.phone = null; //Phone is blank when created
user.profile.createdOn = moment().toISOString(); //Createdon tracks when account created
}
return user;
});
【问题讨论】:
-
你没有发布你的
onCreateUser函数。您是否在节点控制台中收到任何错误? -
@Cuberto 已发布,抱歉我忘记了。在浏览器控制台中没有收到任何节点控制台错误或错误。
标签: meteor user-accounts