Help needed with signup controller code!
app.controller('SignupController', function ($scope, $http, $window) {
$scope.submitSignup = function () {
var newUser = {
username: $scope.username,
password: $scope.password
};
if (newUser.username == db.users.username) {
alert('Username already taken.');
}
if ($scope.submitsignup.$valid) {
$http.post('/users', newUser).then(function () {
$window.location.href = '/#';
alert('Account created successfully!');
});
}
else {
alert('Error during registration process.');
}
}});
Note: Error message says db is not defined.
Server.js snippet fetching users from database:
app.get('/users', function (req, res, next) {
db.collection('users', function (err, usersCollection) {
usersCollection.find().toArray(function (err, users) {
return res.json(users);
});
});
});