当我尝试注册为新用户时,我收到一条错误消息,指出无效的用户名或密码,这让我觉得该应用正在尝试登录时应该尝试注册。
表格:
form(class='form-auth' ng-submit='register()')
p(class='text-warning'){{error_message}}
label(for='email') Email
input(type="email", ng-model='users.email', name="email", placeholder='Email')
label(for='password') Password
input(type="password", ng-model='users.password', name="password", placeholder='Password')
input(type="submit" class='submitBtn' value='Go')
'注册'控制器(在文件' myApp.js'在公共Javascript目录中)
app.controller('authController', function($scope, $rootScope, $http, $location){
$scope.user = {email: '', password: ''};
$scope.error_message = '';
$scope.register = function(){
$http.post('/auth/signup', $scope.user).success(function(data){
if(data.state == 'success'){
$rootScope.authenticated = true;
$rootScope.current_user = data.user.username;
$location.path('/');
}
else{
$scope.error_message = data.message;
}
});
};
});
我在主app.js文件中有auth和passport。我在寄存器1上面有一个登录功能,但它似乎正确关闭。这里有什么问题吗?
答案 0 :(得分:1)
输入的ng模型应为" user.email,user.password"而不是" users.email,users.password"喜欢它在你的控制器$scope.user
中。
与$ scope.users不存在一样,空值将发送到后端。