Remove enrollAccount as a separate method and token. Just use resetPassword.

This commit is contained in:
Nick Martin
2012-09-26 16:55:46 -07:00
parent 5def0ac65f
commit 72b327f196
4 changed files with 6 additions and 50 deletions

View File

@@ -172,7 +172,7 @@
getEnrollAccountToken(email4, test, expect);
},
function (test, expect) {
Meteor.enrollAccount(enrollAccountToken, 'password', expect(function(error) {
Meteor.resetPassword(enrollAccountToken, 'password', expect(function(error) {
test.isFalse(error);
}));
},

View File

@@ -163,32 +163,6 @@
});
};
// Sets a user's first password based on a token originally created by
// Meteor.enrollAccount, and then logs in the matching user.
//
// @param token {String}
// @param password {String}
// @param callback (optional) {Function(error|undefined)}
Meteor.enrollAccount = function(token, password, callback) {
if (!token)
throw new Error("Need to pass token");
if (!password)
throw new Error("Need to pass password");
var verifier = Meteor._srp.generateVerifier(password);
Meteor.apply(
"enrollAccount", [token, verifier], {wait: true},
function (error, result) {
if (error || !result) {
error = error || new Error("No result from call to enrollAccount");
callback && callback(error);
}
Meteor.accounts.makeClientLoggedIn(result.id, result.token);
callback && callback();
});
};
// Validates a user's email address based on a token originally
// created by Meteor.accounts.sendValidationEmail
//

View File

@@ -138,35 +138,17 @@
var user = Meteor.users.findOne({"services.password.reset.token": token});
if (!user)
throw new Meteor.Error(403, "Reset password link expired");
throw new Meteor.Error(403, "Token expired");
Meteor.users.update({_id: user._id}, {
$set: {'services.password.srp': newVerifier},
$unset: {'services.password.reset': 1}
});
var loginToken = Meteor.accounts._loginTokens.insert({userId: user._id});
this.setUserId(user._id);
return {token: loginToken, id: user._id};
},
enrollAccount: function (token, newVerifier) {
if (!token)
throw new Meteor.Error(400, "Need to pass token");
if (!newVerifier)
throw new Meteor.Error(400, "Need to pass newVerifier");
var user = Meteor.users.findOne({"services.password.enroll.token": token});
if (!user)
throw new Meteor.Error(403, "Enroll account link expired");
Meteor.users.update({_id: user._id}, {
$set: {'services.password.srp': newVerifier},
$unset: {'services.password.enroll': 1}
});
// verify their email. they got the password reset email.
Meteor.users.update({_id: user._id},
{$set: {"emails.0.validated": true}});
var loginToken = Meteor.accounts._loginTokens.insert({userId: user._id});
this.setUserId(user._id);
return {token: loginToken, id: user._id};
@@ -229,7 +211,7 @@
var token = Meteor.uuid();
var when = +(new Date);
Meteor.users.update(userId, {$set: {
"services.password.enroll": {
"services.password.reset": {
token: token,
when: when
}

View File

@@ -424,7 +424,7 @@
if (!validatePassword(password))
return;
Meteor.enrollAccount(
Meteor.resetPassword(
Session.get(ENROLL_ACCOUNT_TOKEN_KEY), password,
function (error) {
if (error) {