Commit fa922ca922739b5160eca42977b8d2ef8a1d85de
Exists in
master
and in
1 other branch
Merge branch 'ngforward' of softwarepublico.gov.br:noosfero-themes/angular-theme into ngforward
Showing
6 changed files
with
26 additions
and
10 deletions
Show diff stats
src/app/components/auth/auth_controller.spec.ts
src/app/components/auth/auth_service.spec.ts
| ... | ... | @@ -57,11 +57,21 @@ describe("Auth Service", () => { |
| 57 | 57 | |
| 58 | 58 | expect(eventEmmited).toBeTruthy(AUTH_EVENTS.loginSuccess + " was not emmited!"); |
| 59 | 59 | }); |
| 60 | + | |
| 61 | + it("should return the current logged in user", () => { | |
| 62 | + authService.login(credentials); | |
| 63 | + $httpBackend.flush(); | |
| 64 | + let actual: User = authService.currentUser(); | |
| 65 | + expect(actual).toEqual(user, "The returned user must be present"); | |
| 66 | + }); | |
| 60 | 67 | |
| 68 | + it("should not return the current user after logout", () => { | |
| 69 | + authService.logout(); | |
| 70 | + let actual: any = authService.currentUser(); | |
| 71 | + expect(actual).toEqual(undefined, "The returned user must not be defined"); | |
| 72 | + }); | |
| 61 | 73 | }); |
| 62 | - | |
| 63 | - | |
| 64 | - | |
| 74 | + | |
| 65 | 75 | |
| 66 | 76 | }); |
| 67 | 77 | |
| 68 | 78 | \ No newline at end of file | ... | ... |
src/app/components/auth/auth_service.ts
| ... | ... | @@ -53,13 +53,17 @@ export class AuthService { |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | public isAuthenticated() { |
| 56 | - return !!this.session.getCurrentUser(); | |
| 56 | + return !!this.session.currentUser(); | |
| 57 | + } | |
| 58 | + | |
| 59 | + public currentUser(): User { | |
| 60 | + return this.session.currentUser(); | |
| 57 | 61 | } |
| 58 | 62 | |
| 59 | 63 | public isAuthorized(authorizedRoles: string | string[]) { |
| 60 | 64 | if (!angular.isArray(authorizedRoles)) { |
| 61 | 65 | authorizedRoles = [<string>authorizedRoles]; |
| 62 | 66 | } |
| 63 | - return (this.isAuthenticated() && authorizedRoles.indexOf(this.session.getCurrentUser().userRole) !== -1); | |
| 67 | + return (this.isAuthenticated() && authorizedRoles.indexOf(this.session.currentUser().userRole) !== -1); | |
| 64 | 68 | } |
| 65 | 69 | } |
| 66 | 70 | \ No newline at end of file | ... | ... |
src/app/components/auth/session.ts
src/app/index.run.ts
| ... | ... | @@ -3,8 +3,8 @@ import {Session} from "./components/auth/session"; |
| 3 | 3 | /** @ngInject */ |
| 4 | 4 | export function noosferoAngularRunBlock($log: ng.ILogService, Restangular: restangular.IService, Session: Session) { |
| 5 | 5 | Restangular.addFullRequestInterceptor((element: any, operation: string, route: string, url: string, headers: string) => { |
| 6 | - if (Session.getCurrentUser()) { | |
| 7 | - (<any>headers)["Private-Token"] = Session.getCurrentUser().private_token; | |
| 6 | + if (Session.currentUser()) { | |
| 7 | + (<any>headers)["Private-Token"] = Session.currentUser().private_token; | |
| 8 | 8 | } |
| 9 | 9 | return <any>{ headers: <any>headers }; |
| 10 | 10 | }); | ... | ... |
src/app/main/main.component.ts
| ... | ... | @@ -45,8 +45,9 @@ export class MainContent { |
| 45 | 45 | component: MainContent, |
| 46 | 46 | name: 'main', |
| 47 | 47 | resolve: { |
| 48 | - currentUser: function(AuthService: AuthService) { | |
| 49 | - return AuthService.loginFromCookie(); | |
| 48 | + currentUser: function(AuthService: AuthService, $log: ng.ILogService) { | |
| 49 | + $log.debug("Main URL service..."); | |
| 50 | + return AuthService.currentUser(); | |
| 50 | 51 | } |
| 51 | 52 | } |
| 52 | 53 | }, | ... | ... |