import { NotificationsService } from 'angular2-notifications';
-import { AccountService } from './account.service';
-import { FormReactive, USER_PASSWORD } from '../shared';
+import { FormReactive, UserService, USER_PASSWORD } from '../shared';
@Component({
selector: 'my-account',
private formBuilder: FormBuilder,
private router: Router,
private notificationsService: NotificationsService,
- private accountService: AccountService
+ private userService: UserService
) {
super();
}
return;
}
- this.accountService.changePassword(newPassword).subscribe(
+ this.userService.changePassword(newPassword).subscribe(
() => this.notificationsService.success('Success', 'Password updated.'),
err => this.error = err
AccountComponent
],
- providers: [
- AccountService
- ]
+ providers: []
})
export class AccountModule { }
export * from './account-routing.module';
export * from './account.component';
export * from './account.module';
-export * from './account.service';
-import { Component, ViewContainerRef } from '@angular/core';
+import { Component, OnInit, ViewContainerRef } from '@angular/core';
import { Router } from '@angular/router';
import { MetaService } from 'ng2-meta';
+
+import { AuthService } from './core';
+import { UserService } from './shared';
+
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.scss' ]
})
-
-export class AppComponent {
+export class AppComponent implements OnInit {
notificationOptions = {
timeOut: 3000,
lastOnBottom: true,
constructor(
private router: Router,
private metaService: MetaService,
+ private authService: AuthService,
+ private userService: UserService,
viewContainerRef: ViewContainerRef
) {}
+ ngOnInit() {
+ if (this.authService.isLoggedIn()) {
+ // The service will automatically redirect to the login page if the token is not valid anymore
+ this.userService.checkTokenValidity();
+ }
+ }
+
isInAdmin() {
return this.router.url.indexOf('/admin/') !== -1;
}
-import { User } from '../users';
+// Do not use the barrel (dependency loop)
+import { User } from '../../shared/users/user.model';
export class AuthUser extends User {
private static KEYS = {
import { NotificationsService } from 'angular2-notifications';
+import { AuthStatus } from './auth-status.model';
+import { AuthUser } from './auth-user.model';
// Do not use the barrel (dependency loop)
-import { AuthStatus } from '../../shared/auth/auth-status.model';
-import { AuthUser } from '../../shared/auth/auth-user.model';
import { RestExtractor } from '../../shared/rest';
@Injectable()
+export * from './auth-status.model';
+export * from './auth-user.model';
export * from './auth.service'
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
-import { AuthService } from '../auth';
-import { AuthStatus } from '../../shared';
+import { AuthService, AuthStatus } from '../auth';
@Component({
selector: 'my-menu',
export * from './auth-http.service';
-export * from './auth-status.model';
-export * from './auth-user.model';
import { AUTH_HTTP_PROVIDERS } from './auth';
import { RestExtractor, RestService } from './rest';
import { SearchComponent, SearchService } from './search';
+import { UserService } from './users';
import { VideoAbuseService } from './video-abuse';
@NgModule({
RestExtractor,
RestService,
SearchService,
- VideoAbuseService
+ VideoAbuseService,
+ UserService
]
})
export class SharedModule { }
export * from './user.model';
+export * from './user.service';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';
-import { AuthService } from '../core';
-import { AuthHttp, RestExtractor } from '../shared';
+import { AuthService } from '../../core';
+import { AuthHttp } from '../auth';
+import { RestExtractor } from '../rest';
@Injectable()
-export class AccountService {
+export class UserService {
private static BASE_USERS_URL = '/api/v1/users/';
constructor(
private restExtractor: RestExtractor
) {}
+ checkTokenValidity() {
+ const url = UserService.BASE_USERS_URL + 'me';
+
+ // AuthHttp will redirect us to the login page if the oken is not valid anymore
+ this.authHttp.get(url).subscribe(() => { ; });
+ }
+
changePassword(newPassword: string) {
- const url = AccountService.BASE_USERS_URL + this.authService.getUser().id;
+ const url = UserService.BASE_USERS_URL + this.authService.getUser().id;
const body = {
password: newPassword
};
Video,
VideoService
} from '../shared';
-import { AuthService } from '../../core';
-import { AuthUser, RestPagination, Search, SearchField } from '../../shared';
+import { AuthService, AuthUser } from '../../core';
+import { RestPagination, Search, SearchField } from '../../shared';
import { SearchService } from '../../shared';
@Component({