这是我的register.js
:
register.js
'use strict';
myApp.controller('RegisterCtrl', function ($scope, $location, alert, $state, $auth, $timeout) {
$scope.submit = function () {
$auth.signup({
email: $scope.email,
password: $scope.password
})
.then(function (res) {
alert('success', 'Account Created!', 'Welcome, ' + res.data.user.email + '! Please email activate your account in the next several days.');
$auth.logout();
$location.path('/')
return null;
})
.catch(function (err) {
alert('warning', 'Unable to create account :(! The email is already registered.', err.message);
});
};
});
和
localStrategy.js
exports.register = new LocalStrategy(strategyOptions, function (email, password, done) {
User.findOne({email: email}, function (err, user) {
if(err) {return done(err);}
if(user) { return done(null, false, {message: 'This email is duplicate in the database.'});}
var newUser = new User({
email: email,
password: password
});
newUser.save(function (err) {
done(null, newUser);
})
});
});
我想使用localStrategy.js
上的错误消息,它们是用于传递错误消息的done
的第三个参数。这些消息不会被护照中间件使用:
app.post('/register', passport.authenticate('local-register'), function (req, res) {
emailVerification.send(req.user.email);
createSendToken(req.user, res);
});
如何强制将错误信息用于护照?