-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add navDataService methods to handle current user load - Add current user fecthed from real API throught Restangular decorator - Update style when user is not logged in - Update specs to match new functionality - Update LoginCtrl.spec - Update NavbarDirective.spec - Update navDataService.spec - Update BodyCtrl.spec - Other changes - Fix responsive meta tag missing - Fix codestat issues
- Loading branch information
1 parent
77f5498
commit 68ea41d
Showing
16 changed files
with
307 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,61 @@ | ||
'use strict'; | ||
|
||
define(['paw', 'services/memoryFactory'], function(paw) { | ||
paw.service('navDataService', ['memoryFactory', function(memoryFactory) { | ||
return memoryFactory.newMemory(); | ||
}]); | ||
}); | ||
define( | ||
['paw', | ||
'services/memoryFactory', | ||
'services/Authentication', | ||
'services/AuthenticatedRestangular'], | ||
function(paw) { | ||
paw.service('navDataService', | ||
['memoryFactory', | ||
'Authentication', | ||
'AuthenticatedRestangular', | ||
'Paths', | ||
function(memoryFactory, Authentication, AuthenticatedRestangular, Paths) { | ||
var memory = memoryFactory.newMemory(); | ||
var userKey = 'user'; | ||
|
||
var rest = AuthenticatedRestangular.withConfig(function(RestangularConfigurer) { | ||
RestangularConfigurer.extendModel('user', function(user) { | ||
user.fullName = user.firstName + ' ' + user.lastName; | ||
|
||
user.authorities = { | ||
students: true, | ||
courses: true | ||
}; | ||
|
||
if (user.role === 'ADMIN') { | ||
user.authorities.admins = true; | ||
user.profileUrl = Paths.get().admins(user).path; | ||
} else { // role === 'STUDENT' | ||
user.authorities.admins = false; | ||
user.profileUrl = Paths.get().students(user).path; | ||
}; | ||
|
||
return user; | ||
}); | ||
}); | ||
|
||
memory.fetchUser = function() { | ||
var user = memory.get(userKey); | ||
if (user !== undefined || !Authentication.isLoggedIn()) { | ||
// user already fetched or not yet logged in => nothing to fetch | ||
return; | ||
} | ||
|
||
// user === undefined but it is logged in ==> we should fetch the user for the first time | ||
// | ||
// This case can be reached when the user closes all navigation tabs, but token cookie | ||
// is still stored, and the user directly access an endpoint rather than '/login' | ||
|
||
// fetch the user | ||
rest.one('user').get().then(function(fetchedUser) { | ||
// and set it on the navDataService | ||
memory.set(userKey, fetchedUser); | ||
}); | ||
}; | ||
|
||
return memory; | ||
}]); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.