signupCtrl
demoApp.controller('signupCtrl',function($scope,$http,$location,User) {
User=$scope.user;
$scope.verification = function(isValid,User) {
User=$scope.user;
if (isValid) {
$scope.message = "Submitted ";
console.log(User);
console.log(User.type);
if(User.type=="recruteur")
{
window.alert("bonjour recruteur "+ User.email);
$location.path("/auth");
}
else {
window.alert("bonjour condidat "+ User.email);
$location.path("/auth");
}
} else {
$scope.message = "There are still invalid fields below";
}
};
});
SINGUP.html
<body ng-controller="signupCtrl">
<form name="registrationForm" novalidate
ng-submit="submit(registrationForm.$valid)">
<div class="form-group">
<label>Email</label>
<input type="email" name="email" class="form-group"
ng-model="user.email"
required />
</div>
<div>
<label>Password</label>
<input type="password" name="password"
ng-model="user.password"
required/>
</div>
<div>
<button type="submit" ng-click="verification(registrationForm.$valid,registrationForm.user)">Register!</button>
</div>
</form>
</body>
controller authentificate:
demoApp.controller('personCtrl',function ($scope, $http,$location,User) {
console.log(User);
var person=User;
$scope.emaill=person.email;
$scope.pwd=person.password;
console.log(person);
});
验证页面:
<body>
<form>
<input type="text" ng-model="emaill">
<input type="password" ng-model="pwd">
<input type="submit" value="Connexion" ng-click="connexion(person)">
</form>
</body>
路线提供者
demoApp.config(['$routeProvider',
function($routeProvider){
//systeme de routage
console.log('rederction');
$routeProvider.when ('/auth',{templateUrl: 'authentficate.html',
controller: 'personCtrl'})
.otherwise({redirectTo: 'Signup.html'}
);
}
]);
答案 0 :(得分:1)
您可以将会话所需的数据放入服务中。
https://docs.angularjs.org/guide/services
但是不要把密码放在那里,只有用户名和身份验证令牌。
点击此处查看基于令牌的身份验证的完整示例