【发布时间】:2016-05-04 17:51:04
【问题描述】:
我有一个 angularjs 应用程序,在这个应用程序中我有一个登录表单,当我提交它时我调用了一个休息服务来验证用户到我的服务器应用程序,如下所示:
$http.get('http://localhost:8080/user', {
headers : credentials ? {
authorization : "Basic "
+ btoa(credentials.username + ":"
+ credentials.password)
} : {};
}).then(function(response) {
if (response.data.name) {
$rootScope.authenticated = true;
$rootScope.username=response.data.name;
$rootScope.roles=response.data.authorities;
$rootScope.sessionid=response.data.details.sessionId;
} else {
$rootScope.authenticated = false;
}
}, function() {
$rootScope.authenticated = false;
});
因此 $rootScope 将包含有关经过身份验证的用户的所有信息,但是当我刷新我的应用程序时,我附加到 $rootScope 的所有这些信息都将被删除。
请注意,http://localhost:8080/user 将始终保持会话。
我该如何解决?
【问题讨论】:
标签: angularjs