U4-10175 User avatar should refresh in top left corner when it's changed
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
angular.module('umbraco.security.interceptor')
|
||||
// This http interceptor listens for authentication successes and failures
|
||||
.factory('securityInterceptor', ['$injector', 'securityRetryQueue', 'notificationsService', 'requestInterceptorFilter', function ($injector, queue, notifications, requestInterceptorFilter) {
|
||||
.factory('securityInterceptor', ['$injector', 'securityRetryQueue', 'notificationsService', 'eventsService', 'requestInterceptorFilter', function ($injector, queue, notifications, eventsService, requestInterceptorFilter) {
|
||||
return function(promise) {
|
||||
|
||||
return promise.then(
|
||||
@@ -16,6 +16,12 @@ angular.module('umbraco.security.interceptor')
|
||||
userService.setUserTimeout(headers["x-umb-user-seconds"]);
|
||||
}
|
||||
|
||||
//this checks if the user's values have changed, in which case we need to update the user details throughout
|
||||
//the back office similar to how we do when a user logs in
|
||||
if (headers["x-umb-user-modified"]) {
|
||||
eventsService.emit("app.userRefresh");
|
||||
}
|
||||
|
||||
return promise;
|
||||
}, function(originalResponse) {
|
||||
// Intercept failed requests
|
||||
|
||||
@@ -6,7 +6,10 @@
|
||||
app.ready
|
||||
app.authenticated
|
||||
app.notAuthenticated
|
||||
app.closeDialogs
|
||||
app.closeDialogs
|
||||
app.ysod
|
||||
app.reInitialize
|
||||
app.userRefresh
|
||||
*/
|
||||
|
||||
function eventsService($q, $rootScope) {
|
||||
|
||||
@@ -225,6 +225,26 @@ angular.module('umbraco.services')
|
||||
});
|
||||
},
|
||||
|
||||
/** Refreshes the current user data with the data stored for the user on the server and returns it */
|
||||
refreshCurrentUser: function() {
|
||||
var deferred = $q.defer();
|
||||
|
||||
authResource.getCurrentUser()
|
||||
.then(function (data) {
|
||||
|
||||
var result = { user: data, authenticated: true, lastUserId: lastUserId, loginType: "implicit" };
|
||||
|
||||
setCurrentUser(data);
|
||||
|
||||
deferred.resolve(currentUser);
|
||||
}, function () {
|
||||
//it failed, so they are not logged in
|
||||
deferred.reject();
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
},
|
||||
|
||||
/** Returns the current user object in a promise */
|
||||
getCurrentUser: function (args) {
|
||||
var deferred = $q.defer();
|
||||
|
||||
@@ -54,7 +54,27 @@ function MainController($scope, $rootScope, $location, $routeParams, $timeout, $
|
||||
$scope.user = null;
|
||||
}));
|
||||
|
||||
//when the app is read/user is logged in, setup the data
|
||||
evts.push(eventsService.on("app.userRefresh", function(evt) {
|
||||
userService.refreshCurrentUser().then(function(data) {
|
||||
$scope.user = data;
|
||||
|
||||
//Load locale file
|
||||
if ($scope.user.locale) {
|
||||
tmhDynamicLocale.set($scope.user.locale);
|
||||
}
|
||||
|
||||
if ($scope.user.avatars) {
|
||||
$scope.avatar = [];
|
||||
if (angular.isArray($scope.user.avatars)) {
|
||||
for (var i = 0; i < $scope.user.avatars.length; i++) {
|
||||
$scope.avatar.push({ value: $scope.user.avatars[i] });
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
//when the app is ready/user is logged in, setup the data
|
||||
evts.push(eventsService.on("app.ready", function (evt, data) {
|
||||
|
||||
$scope.authenticated = data.authenticated;
|
||||
|
||||
Reference in New Issue
Block a user