【发布时间】:2014-10-01 02:07:07
【问题描述】:
我试图在第三方登录后将我的用户重定向到仪表板。但是当成功回调被触发时,应用程序仍然在登录页面上,什么也没发生。如果我刷新浏览器,我的拦截器捕获已经登录并更改为仪表板...我的登录控制器如下所示:
ThirdParty.login(function(result){
callbackSUCCESS(result);
},function(){});
function callbackSUCCESS(result){
AuthenticationService.login(result).then(
callbackServerSUCCESS(), function(reject) {
callbackServerERROR(reject);
});
}
function callbackServerSUCCESS() {
$scope.$apply(function() {
$state.go('dashboard');
});
}
我在 app.js 中的路线
$stateProvider
.state('dashboard', {
url: '/dashboard',
views: {
'': {
templateUrl: 'views/dashboard/dashboard.html',
controller: 'DashboardCtrl'
}
}
});
我的标题控制器
.controller('HeaderCtrl', ['$scope', 'AuthenticationService', '$state',
function($scope, AuthenticationService, $state) {
$scope.logout = function() {
AuthenticationService.logout().then(callbackServer(), callbackServer());
};
function callbackServer() {
$state.go('login');
}
}
]);
身份验证控制器 Angular 工厂
var headersConfig = {
'Cache-Control': 'no-cache',
'Pragma': 'no-cache'
};
return {
login: function(credentials) {
var deferred = $q.defer();
$http.post('/api/users/sign_in', sanitizeCredentials(credentials), {
headers: headersConfig,
timeout: deferred.promise
}).then(function(result) {
if (result.status === 200) {
UserSessionService.cacheSession(result.data);
deferred.resolve();
} else {
deferred.reject();
}
}, function(reject) {
UserSessionService.clean();
deferred.reject(reject);
});
$timeout(function() {
deferred.resolve();
}, 15000);
return deferred.promise;
}
};
【问题讨论】:
-
我的第三方例如。 github。通量:登录页面->git auth->我的服务器登录->仪表板
-
如果您在地址栏中输入 url,您会看到您的仪表板页面吗?
-
不,当我重新加载页面时,然后更改为localhost:9000/dashboard
-
我不认为你想要
then(callbackServer(), callbackServer())中的()
标签: angularjs angular-ui-router