我正在创建一个小项目,如果用户角色是Sales,那么在登录后它会将用户重定向到销售表单页面.现在,如果用户Sales form通过在URL中输入其路径来尝试访问页面,并且用户未登录,我该如何将用户重定向到登录页面.这是我的Angular部分.
app.controller('LoginCtrl',function($scope,$http,$window){
$scope.login = function(){
data={
email:$scope.email,
pwd:$scope.pwd
}
$http.post("widget/login.php",data).success(function(data){
console.log(data);
if(!data.success){
$scope.errorMsg="username or password is incorrect";
}
else{
$scope.role=data.role;
$scope.id=data.id;
if(data.role == "admin"){
$window.location.href="AdminPage.html";
}
else if(data.role == "Sales"){
$window.location.href="sales_form.html";
}
else if(data.role == "Account"){
$window.location.href="account_form.html";
}
else if(data.role == "Technical"){
$window.location.href="Technical_Form.html";
}
else{
$scope.errorMsg="username or password is incorrect";
}
}
});
}
});
Run Code Online (Sandbox Code Playgroud)
如果用户未登录或尝试直接从URL访问页面,如何将用户重定向到登录页面.还有一件事我正在使用PHP作为后端,因为你可以$http.post部分地看到它,所以请相应地给出你的答案.感谢帮助,并提前感谢你.