Advertisement
Guest User

Untitled

a guest
Sep 24th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.86 KB | None | 0 0
  1. diff --git a/ui/src/app/app.component.ts b/ui/src/app/app.component.ts
  2. index 3cfdf2d..f4ca676 100644
  3. --- a/ui/src/app/app.component.ts
  4. +++ b/ui/src/app/app.component.ts
  5. @@ -55,11 +55,8 @@ import {EmployeeVariablesService} from './payrolls/prepare/employee-variables.se
  6. FiqlService,
  7. PayResultsService,
  8. EmployeeVariablesService,
  9. - AuthenticationService,
  10. - ApiService,
  11. UserService,
  12. - LocalizationService,
  13. - { provide: 'GP_API_HOST', useFactory: () => window.GPConfig.API_HOST },
  14. + LocalizationService
  15. ]
  16. })
  17.  
  18. diff --git a/ui/src/app/app.module.ts b/ui/src/app/app.module.ts
  19. index 858b4be..241b61f 100644
  20. --- a/ui/src/app/app.module.ts
  21. +++ b/ui/src/app/app.module.ts
  22. @@ -68,7 +68,8 @@ import {ApiService} from './shared/api/api.service';
  23. PayrollsModule,
  24. EmployeesModule,
  25. AdministrationModule,
  26. - DashboardModule
  27. + DashboardModule,
  28. + BootstrapModalModule
  29. ],
  30. declarations: [
  31. AppComponent,
  32. @@ -89,9 +90,6 @@ import {ApiService} from './shared/api/api.service';
  33. bootstrap: [AppComponent],
  34. providers: [
  35. { provide: 'GP_API_HOST', useFactory: () => window.GPConfig.API_HOST },
  36. - BootstrapModalModule,
  37. - MomentModule,
  38. - ApiService
  39. ],
  40. entryComponents: []
  41. })
  42. diff --git a/ui/src/app/login/login.component.ts b/ui/src/app/login/login.component.ts
  43. index 6c7f60c..f0e9a43 100644
  44. --- a/ui/src/app/login/login.component.ts
  45. +++ b/ui/src/app/login/login.component.ts
  46. @@ -40,7 +40,7 @@ export class LoginComponent {
  47.  
  48. login() {
  49. this.authenticationService.login(this.user.username, this.user.password).subscribe(user => {
  50. - this.router.navigate(['/dashboard']);
  51. + this.router.navigate(['dashboard']);
  52. }, error => {
  53. this.invalidCredentials = true;
  54. setTimeout(() => {
  55. diff --git a/ui/src/app/shared/authentication/authentication-guard.ts b/ui/src/app/shared/authentication/authentication-guard.ts
  56. index 0cc444a..044566a 100644
  57. --- a/ui/src/app/shared/authentication/authentication-guard.ts
  58. +++ b/ui/src/app/shared/authentication/authentication-guard.ts
  59. @@ -14,7 +14,7 @@
  60. */
  61.  
  62. import {Injectable} from '@angular/core';
  63. -import {CanActivate} from '@angular/router';
  64. +import {CanActivate, Router} from '@angular/router';
  65. import {AuthenticationService} from './authentication.service.ts';
  66. import {LocalizationService} from '../localization';
  67. import {Observable} from 'rxjs';
  68. @@ -30,13 +30,15 @@ export class AuthenticationGuard implements CanActivate {
  69. publicRoutes: any;
  70.  
  71. constructor(private l10n: LocalizationService,
  72. - private authenticationService: AuthenticationService) {
  73. + private authenticationService: AuthenticationService,
  74. + private router: Router) {
  75. }
  76.  
  77. canActivate() {
  78. return this.authenticationService.isAuthenticated().then(authenticated => {
  79.  
  80. if (!authenticated) {
  81. + this.router.navigate(['/login']);
  82. return false;
  83. }
  84.  
  85. diff --git a/ui/src/app/shared/authentication/authentication.service.ts b/ui/src/app/shared/authentication/authentication.service.ts
  86. index 7e1a28d..5e8ca63 100644
  87. --- a/ui/src/app/shared/authentication/authentication.service.ts
  88. +++ b/ui/src/app/shared/authentication/authentication.service.ts
  89. @@ -15,6 +15,7 @@
  90. import {Injectable, EventEmitter, Inject} from '@angular/core';
  91. import {Http, Headers} from '@angular/http';
  92. import {Observable} from 'rxjs/Rx';
  93. +import {isPresent} from '../utils/lang';
  94.  
  95. /**
  96. * Possible authentication events streamed by the authentication service
  97. @@ -49,7 +50,7 @@ export class AuthenticationService {
  98. if (this.userLoggedIn !== null) {
  99. return Promise.resolve(this.userLoggedIn);
  100. }
  101. - if (this.userLoggedInPromise === null) {
  102. + if (!isPresent(this.userLoggedInPromise)) {
  103. this.userLoggedInPromise = this.checkAuthentication();
  104. }
  105. return this.userLoggedInPromise;
  106. @@ -61,7 +62,8 @@ export class AuthenticationService {
  107. const headers = new Headers();
  108. headers.append('Authorization', `Bearer ${this.getToken()}`);
  109. // TODO: have a service just for verifying the token ?
  110. - return this.http.get(`${this.apiHost}/authent/api/v1/cliUser/me`, { headers }).toPromise().then(result => {
  111. + const promise = this.http.get(`${this.apiHost}/authent/api/v1/cliUser/me`, { headers }).toPromise()
  112. + return promise.then(result => {
  113. if (result.status === 200) {
  114. this.userLoggedIn = true;
  115. this.authenticationEvents.emit(AuthenticationEvent.TOKEN_VERIFIED);
  116. @@ -114,7 +116,6 @@ export class AuthenticationService {
  117. * of failed login
  118. */
  119. login(username: string, password: string, remember: Boolean = false): Observable<any> {
  120. -
  121. const headers = new Headers();
  122. headers.append('Content-Type', 'application/x-www-form-urlencoded');
  123.  
  124. diff --git a/ui/src/app/shared/shared.module.ts b/ui/src/app/shared/shared.module.ts
  125. index b1c7d93..8c9aa1c 100644
  126. --- a/ui/src/app/shared/shared.module.ts
  127. +++ b/ui/src/app/shared/shared.module.ts
  128. @@ -27,6 +27,7 @@ import { ChartsModule } from './charts/charts.module';
  129. import { TablesModule } from './tables/tables.module';
  130. import { FilesModule } from './files/files.module';
  131. import { CanDeactivateGuard } from './routing/can-deactivate-guard';
  132. +import {ApiModule} from './api/api.module';
  133.  
  134. @NgModule({
  135. imports: [
  136. @@ -40,7 +41,8 @@ import { CanDeactivateGuard } from './routing/can-deactivate-guard';
  137. UiModule,
  138. ChartsModule,
  139. TablesModule,
  140. - FilesModule
  141. + FilesModule,
  142. + ApiModule
  143. ],
  144. declarations: [],
  145. exports: [
  146. @@ -53,7 +55,8 @@ import { CanDeactivateGuard } from './routing/can-deactivate-guard';
  147. UiModule,
  148. ChartsModule,
  149. TablesModule,
  150. - FilesModule
  151. + FilesModule,
  152. + ApiModule
  153. ],
  154. providers: [CanDeactivateGuard]
  155. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement