Чтобы сделать это с помощью встроенного в материал, вы можете отвес вместе существующего Accounts.sendEnrollmentEmail
- однако, это немного сложнее, чем другие решения данной.
Используя пример кода ниже, вызовите метод enroll
как таковой:
Meteor.call('enroll', 'john.smith', '[email protected]', {name: 'John Smith'});
Метеор будет затем отправить пользователю ссылку (Вы можете настроить шаблон с Accounts.emailTemplates
)
При нажатии на ссылку , meteor вызывает функцию, переданную в Accounts.onEnrollmentLink
- в этом случае вы можете перенести их на страницу настройки пароля; но вам нужно возиться со своим обратным вызовом done
.
Изменить следующий код, где сказано INSERT XXX HERE
; затем в вашем кодовом вызове SomeGlobalEnrollmentObjectThing.cancel()
, если пользователь отменяет или SomeGlobalEnrollmentObjectThing.complete(theUsersNewPassword)
, если они отправят новый пароль.
if (Meteor.isServer){
Meteor.methods({
"enroll": function(username, email, profile){
var userId;
check(username, String);
check(email, String); // Or email validator
check(profile, {
name: String
}); // your own schema
// check that the current user is privileged (using roles package)
if (!Roles.isInRole(this.userId, 'admin')){
throw new Meteor.Error(403);
}
userId = Accounts.createUser({
username: username,
email: email,
profile: profile
});
Accounts.sendEnrollmentEmail(userId);
}
});
} else {
// uses `underscore`, `reactive-var` and `tracker` packages
function Enrollment(){
this.computation = null;
this.token = new ReactiveVar(null);
this.password = new ReactiveVar(null);
this.cancelled = new ReactiveVar(false);
this.done = null;
this._bind();
}
_.extend(Enrollment.prototype, {
_bind: function(){
Accounts.onEnrollmentLink(_.bind(this.action, this));
},
reset: function(){
this.token.set(null);
this.password.set(null);
this.cancelled.set(false);
this.done = null;
if (this.computation !== null){
this.computation.stop();
this.computation = null;
}
},
cancel: function(){
this.cancelled.set(true);
},
complete: function(password){
this.password.set(password);
},
action: function(token, done){
this.reset();
this.token.set(token);
this.done = done;
this.computation = Tracker.autorun(_.bind(this._computation, this));
// --- INSERT REDIRECT LOGIC HERE [TAKE TO PASSWORD SETUP PAGE]--- //
},
_computation: function(){
var password;
if (this.cancelled.get()){
this.reset();
this.done();
// --- INSERT REDIRECT LOGIC HERE [USER CANCELLED]--- //
} else {
password = this.password.get();
if (password !== null){
Accounts.resetPassword(this.token.get(), password, _.bind(this._complete, this));
}
}
},
_complete: function(err){
// TODO - check if we were reset before callback completed
this.reset();
this.done();
if (err){
// --- INSERT REDIRECT LOGIC HERE [RESET FAILED] --- //
} else {
// --- INSERT REDIRECT LOGIC HERE [SUCCESS] --- //
}
}
});
SomeGlobalEnrollmentObjectThing = new Enrollment();
}
Благодарим вас за описание реализации для этого. Я надеялся, что для этого будет встроенный вариант, но прибегните к его реализации. – Tobold