Add authentication tokens to make friends/quit friends
authorChocobozzz <florian.bigard@gmail.com>
Wed, 1 Jun 2016 18:36:27 +0000 (20:36 +0200)
committerChocobozzz <florian.bigard@gmail.com>
Wed, 1 Jun 2016 18:36:27 +0000 (20:36 +0200)
35 files changed:
client/app/app.component.ts
client/app/friends/friend.service.ts
client/app/login/index.ts [new file with mode: 0644]
client/app/login/login.component.html [new file with mode: 0644]
client/app/login/login.component.ts [new file with mode: 0644]
client/app/shared/index.ts
client/app/shared/search-field.type.ts [deleted file]
client/app/shared/search.component.html [deleted file]
client/app/shared/search.component.ts [deleted file]
client/app/shared/search.model.ts [deleted file]
client/app/shared/search/index.ts [new file with mode: 0644]
client/app/shared/search/search-field.type.ts [new file with mode: 0644]
client/app/shared/search/search.component.html [new file with mode: 0644]
client/app/shared/search/search.component.ts [new file with mode: 0644]
client/app/shared/search/search.model.ts [new file with mode: 0644]
client/app/shared/users/auth-status.model.ts [new file with mode: 0644]
client/app/shared/users/auth.service.ts [new file with mode: 0644]
client/app/shared/users/index.ts [new file with mode: 0644]
client/app/shared/users/token.model.ts [new file with mode: 0644]
client/app/shared/users/user.model.ts [new file with mode: 0644]
client/app/users/index.ts [deleted file]
client/app/users/login/index.ts [deleted file]
client/app/users/login/login.component.html [deleted file]
client/app/users/login/login.component.scss [deleted file]
client/app/users/login/login.component.ts [deleted file]
client/app/users/shared/auth-status.model.ts [deleted file]
client/app/users/shared/auth.service.ts [deleted file]
client/app/users/shared/index.ts [deleted file]
client/app/users/shared/token.model.ts [deleted file]
client/app/users/shared/user.model.ts [deleted file]
client/app/videos/shared/video.service.ts
client/app/videos/video-add/video-add.component.ts
client/app/videos/video-list/video-list.component.ts
client/app/videos/video-list/video-miniature.component.ts
client/tsconfig.json

index d29448296cdd2536d4f4c197c667135e6edcd763..94924a47aba2dedb0ad7be1bd02e085baa126cf8 100644 (file)
@@ -3,12 +3,13 @@ import { HTTP_PROVIDERS } from '@angular/http';
 import { RouteConfig, Router, ROUTER_DIRECTIVES, ROUTER_PROVIDERS } from '@angular/router-deprecated';
 
 import { FriendService } from './friends/index';
-import { Search, SearchComponent } from './shared/index';
+import { LoginComponent } from './login/index';
 import {
-  UserLoginComponent,
   AuthService,
-  AuthStatus
-} from './users/index';
+  AuthStatus,
+  Search,
+  SearchComponent
+} from './shared/index';
 import {
   VideoAddComponent,
   VideoListComponent,
@@ -20,7 +21,7 @@ import {
   {
     path: '/users/login',
     name: 'UserLogin',
-    component: UserLoginComponent
+    component: LoginComponent
   },
   {
     path: '/videos/list',
index bdfa7baeca1622057838874035e0655354adcaed..d3684f08db021785e4780b7fd2eca268496fd5d9 100644 (file)
@@ -2,20 +2,24 @@ import { Injectable } from '@angular/core';
 import { Http, Response } from '@angular/http';
 import { Observable } from 'rxjs/Rx';
 
+import { AuthService } from '../shared/index';
+
 @Injectable()
 export class FriendService {
   private static BASE_FRIEND_URL: string = '/api/v1/pods/';
 
-  constructor (private http: Http) {}
+  constructor (private http: Http, private authService: AuthService) {}
 
   makeFriends() {
-    return this.http.get(FriendService.BASE_FRIEND_URL + 'makefriends')
+    const headers = this.authService.getRequestHeader();
+    return this.http.get(FriendService.BASE_FRIEND_URL + 'makefriends', { headers })
                     .map(res => res.status)
                     .catch(this.handleError);
   }
 
   quitFriends() {
-    return this.http.get(FriendService.BASE_FRIEND_URL + 'quitfriends')
+    const headers = this.authService.getRequestHeader();
+    return this.http.get(FriendService.BASE_FRIEND_URL + 'quitfriends', { headers })
                     .map(res => res.status)
                     .catch(this.handleError);
   }
diff --git a/client/app/login/index.ts b/client/app/login/index.ts
new file mode 100644 (file)
index 0000000..69c1644
--- /dev/null
@@ -0,0 +1 @@
+export * from './login.component';
diff --git a/client/app/login/login.component.html b/client/app/login/login.component.html
new file mode 100644 (file)
index 0000000..9406945
--- /dev/null
@@ -0,0 +1,14 @@
+<h3>Login</h3>
+<form role="form" (submit)="login(username.value, password.value)">
+  <div class="form-group">
+    <label for="username">Username</label>
+    <input type="text" #username class="form-control" id="username" placeholder="Username">
+  </div>
+
+  <div class="form-group">
+    <label for="password">Password</label>
+    <input type="password" #password class="form-control" id="password" placeholder="Password">
+  </div>
+
+  <input type="submit" value="Login" class="btn btn-default">
+</form>
diff --git a/client/app/login/login.component.ts b/client/app/login/login.component.ts
new file mode 100644 (file)
index 0000000..50f598d
--- /dev/null
@@ -0,0 +1,36 @@
+import { Component } from '@angular/core';
+import { Router } from '@angular/router-deprecated';
+
+import { AuthService, AuthStatus, User } from '../shared/index';
+
+@Component({
+  selector: 'my-login',
+  templateUrl: 'client/app/login/login.component.html'
+})
+
+export class LoginComponent {
+  constructor(
+    private authService: AuthService,
+    private router: Router
+  ) {}
+
+  login(username: string, password: string) {
+    this.authService.login(username, password).subscribe(
+      result => {
+        const user = new User(username, result);
+        user.save();
+
+        this.authService.setStatus(AuthStatus.LoggedIn);
+
+        this.router.navigate(['VideosList']);
+      },
+      error => {
+        if (error.error === 'invalid_grant') {
+          alert('Credentials are invalid.');
+        } else {
+          alert(`${error.error}: ${error.error_description}`);
+        }
+      }
+    );
+  }
+}
index a49a4f1a95e9ee9caa82a07d3ac19d830e709bae..ad3ee0098124d660c0c8f88863ea06f84bd76fcb 100644 (file)
@@ -1,3 +1,2 @@
-export * from './search-field.type';
-export * from './search.component';
-export * from './search.model';
+export * from './search/index';
+export * from './users/index'
diff --git a/client/app/shared/search-field.type.ts b/client/app/shared/search-field.type.ts
deleted file mode 100644 (file)
index 8462362..0000000
+++ /dev/null
@@ -1 +0,0 @@
-export type SearchField = "name" | "author" | "podUrl" | "magnetUri";
diff --git a/client/app/shared/search.component.html b/client/app/shared/search.component.html
deleted file mode 100644 (file)
index fb13ac7..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-<div class="input-group">
-  <div class="input-group-btn" dropdown>
-    <button id="simple-btn-keyboard-nav" type="button" class="btn btn-default" dropdownToggle>
-      {{ getStringChoice(searchCriterias.field) }} <span class="caret"></span>
-    </button>
-    <ul class="dropdown-menu" role="menu" aria-labelledby="simple-btn-keyboard-nav">
-      <li *ngFor="let choice of choiceKeys" class="dropdown-item">
-        <a class="dropdown-item" href="#" (click)="choose($event, choice)">{{ getStringChoice(choice) }}</a>
-      </li>
-    </ul>
-  </div>
-
-  <input
-    type="text" id="search-video" name="search-video" class="form-control" placeholder="Search a video..." class="form-control"
-    [(ngModel)]="searchCriterias.value" (keyup.enter)="doSearch()"
-  >
-</div>
diff --git a/client/app/shared/search.component.ts b/client/app/shared/search.component.ts
deleted file mode 100644 (file)
index e1e30b9..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-import { Component, EventEmitter, Output } from '@angular/core';
-
-import { DROPDOWN_DIRECTIVES} from  'ng2-bootstrap/components/dropdown';
-
-import { Search } from './search.model';
-import { SearchField } from './search-field.type';
-
-@Component({
-    selector: 'my-search',
-    templateUrl: 'client/app/shared/search.component.html',
-    directives: [ DROPDOWN_DIRECTIVES ]
-})
-
-export class SearchComponent {
-  @Output() search = new EventEmitter<Search>();
-
-  fieldChoices = {
-    name: 'Name',
-    author: 'Author',
-    podUrl: 'Pod Url',
-    magnetUri: 'Magnet Uri'
-  };
-  searchCriterias: Search = {
-    field: 'name',
-    value: ''
-  };
-
-  get choiceKeys() {
-    return Object.keys(this.fieldChoices);
-  }
-
-  choose($event: MouseEvent, choice: SearchField) {
-    $event.preventDefault();
-    $event.stopPropagation();
-
-    this.searchCriterias.field = choice;
-  }
-
-  doSearch() {
-    this.search.emit(this.searchCriterias);
-  }
-
-  getStringChoice(choiceKey: SearchField) {
-    return this.fieldChoices[choiceKey];
-  }
-}
diff --git a/client/app/shared/search.model.ts b/client/app/shared/search.model.ts
deleted file mode 100644 (file)
index 932a656..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-import { SearchField } from './search-field.type';
-
-export interface Search {
-  field: SearchField;
-  value: string;
-}
diff --git a/client/app/shared/search/index.ts b/client/app/shared/search/index.ts
new file mode 100644 (file)
index 0000000..a49a4f1
--- /dev/null
@@ -0,0 +1,3 @@
+export * from './search-field.type';
+export * from './search.component';
+export * from './search.model';
diff --git a/client/app/shared/search/search-field.type.ts b/client/app/shared/search/search-field.type.ts
new file mode 100644 (file)
index 0000000..8462362
--- /dev/null
@@ -0,0 +1 @@
+export type SearchField = "name" | "author" | "podUrl" | "magnetUri";
diff --git a/client/app/shared/search/search.component.html b/client/app/shared/search/search.component.html
new file mode 100644 (file)
index 0000000..fb13ac7
--- /dev/null
@@ -0,0 +1,17 @@
+<div class="input-group">
+  <div class="input-group-btn" dropdown>
+    <button id="simple-btn-keyboard-nav" type="button" class="btn btn-default" dropdownToggle>
+      {{ getStringChoice(searchCriterias.field) }} <span class="caret"></span>
+    </button>
+    <ul class="dropdown-menu" role="menu" aria-labelledby="simple-btn-keyboard-nav">
+      <li *ngFor="let choice of choiceKeys" class="dropdown-item">
+        <a class="dropdown-item" href="#" (click)="choose($event, choice)">{{ getStringChoice(choice) }}</a>
+      </li>
+    </ul>
+  </div>
+
+  <input
+    type="text" id="search-video" name="search-video" class="form-control" placeholder="Search a video..." class="form-control"
+    [(ngModel)]="searchCriterias.value" (keyup.enter)="doSearch()"
+  >
+</div>
diff --git a/client/app/shared/search/search.component.ts b/client/app/shared/search/search.component.ts
new file mode 100644 (file)
index 0000000..d541cd0
--- /dev/null
@@ -0,0 +1,46 @@
+import { Component, EventEmitter, Output } from '@angular/core';
+
+import { DROPDOWN_DIRECTIVES} from  'ng2-bootstrap/components/dropdown';
+
+import { Search } from './search.model';
+import { SearchField } from './search-field.type';
+
+@Component({
+    selector: 'my-search',
+    templateUrl: 'client/app/shared/search/search.component.html',
+    directives: [ DROPDOWN_DIRECTIVES ]
+})
+
+export class SearchComponent {
+  @Output() search = new EventEmitter<Search>();
+
+  fieldChoices = {
+    name: 'Name',
+    author: 'Author',
+    podUrl: 'Pod Url',
+    magnetUri: 'Magnet Uri'
+  };
+  searchCriterias: Search = {
+    field: 'name',
+    value: ''
+  };
+
+  get choiceKeys() {
+    return Object.keys(this.fieldChoices);
+  }
+
+  choose($event: MouseEvent, choice: SearchField) {
+    $event.preventDefault();
+    $event.stopPropagation();
+
+    this.searchCriterias.field = choice;
+  }
+
+  doSearch() {
+    this.search.emit(this.searchCriterias);
+  }
+
+  getStringChoice(choiceKey: SearchField) {
+    return this.fieldChoices[choiceKey];
+  }
+}
diff --git a/client/app/shared/search/search.model.ts b/client/app/shared/search/search.model.ts
new file mode 100644 (file)
index 0000000..932a656
--- /dev/null
@@ -0,0 +1,6 @@
+import { SearchField } from './search-field.type';
+
+export interface Search {
+  field: SearchField;
+  value: string;
+}
diff --git a/client/app/shared/users/auth-status.model.ts b/client/app/shared/users/auth-status.model.ts
new file mode 100644 (file)
index 0000000..f646bd4
--- /dev/null
@@ -0,0 +1,4 @@
+export enum AuthStatus {
+  LoggedIn,
+  LoggedOut
+}
diff --git a/client/app/shared/users/auth.service.ts b/client/app/shared/users/auth.service.ts
new file mode 100644 (file)
index 0000000..d63fe38
--- /dev/null
@@ -0,0 +1,108 @@
+import { Injectable } from '@angular/core';
+import { Headers, Http, RequestOptions, Response, URLSearchParams } from '@angular/http';
+import { Observable, Subject } from 'rxjs/Rx';
+
+import { AuthStatus } from './auth-status.model';
+import { User } from './user.model';
+
+@Injectable()
+export class AuthService {
+  private static BASE_CLIENT_URL = '/api/v1/users/client';
+  private static BASE_LOGIN_URL = '/api/v1/users/token';
+
+  loginChangedSource: Observable<AuthStatus>;
+
+  private clientId: string;
+  private clientSecret: string;
+  private loginChanged: Subject<AuthStatus>;
+
+  constructor(private http: Http) {
+    this.loginChanged = new Subject<AuthStatus>();
+    this.loginChangedSource = this.loginChanged.asObservable();
+
+    // Fetch the client_id/client_secret
+    // FIXME: save in local storage?
+    this.http.get(AuthService.BASE_CLIENT_URL)
+      .map(res => res.json())
+      .catch(this.handleError)
+      .subscribe(
+        result => {
+          this.clientId = result.client_id;
+          this.clientSecret = result.client_secret;
+          console.log('Client credentials loaded.');
+        },
+        error => {
+          alert(error);
+        }
+      );
+  }
+
+  getAuthRequestOptions(): RequestOptions {
+    return new RequestOptions({ headers: this.getRequestHeader() });
+  }
+
+  getRequestHeader() {
+    return new Headers({ 'Authorization': `${this.getTokenType()} ${this.getToken()}` });
+  }
+
+  getToken() {
+    return localStorage.getItem('access_token');
+  }
+
+  getTokenType() {
+    return localStorage.getItem('token_type');
+  }
+
+  getUser(): User {
+    if (this.isLoggedIn() === false) {
+      return null;
+    }
+
+    const user = User.load();
+
+    return user;
+  }
+
+  isLoggedIn() {
+    if (this.getToken()) {
+      return true;
+    } else {
+      return false;
+    }
+  }
+
+  login(username: string, password: string) {
+    let body = new URLSearchParams();
+    body.set('client_id', this.clientId);
+    body.set('client_secret', this.clientSecret);
+    body.set('response_type', 'code');
+    body.set('grant_type', 'password');
+    body.set('scope', 'upload');
+    body.set('username', username);
+    body.set('password', password);
+
+    let headers = new Headers();
+    headers.append('Content-Type', 'application/x-www-form-urlencoded');
+
+    let options = {
+      headers: headers
+    };
+
+    return this.http.post(AuthService.BASE_LOGIN_URL, body.toString(), options)
+                    .map(res => res.json())
+                    .catch(this.handleError);
+  }
+
+  logout() {
+    // TODO make HTTP request
+  }
+
+  setStatus(status: AuthStatus) {
+    this.loginChanged.next(status);
+  }
+
+  private handleError (error: Response) {
+    console.error(error);
+    return Observable.throw(error.json() || { error: 'Server error' });
+  }
+}
diff --git a/client/app/shared/users/index.ts b/client/app/shared/users/index.ts
new file mode 100644 (file)
index 0000000..c6816b3
--- /dev/null
@@ -0,0 +1,4 @@
+export * from './auth-status.model';
+export * from './auth.service';
+export * from './token.model';
+export * from './user.model';
diff --git a/client/app/shared/users/token.model.ts b/client/app/shared/users/token.model.ts
new file mode 100644 (file)
index 0000000..021c83f
--- /dev/null
@@ -0,0 +1,32 @@
+export class Token {
+  access_token: string;
+  refresh_token: string;
+  token_type: string;
+
+  static load() {
+    return new Token({
+      access_token: localStorage.getItem('access_token'),
+      refresh_token: localStorage.getItem('refresh_token'),
+      token_type: localStorage.getItem('token_type')
+    });
+  }
+
+  constructor(hash?: any) {
+    if (hash) {
+      this.access_token = hash.access_token;
+      this.refresh_token = hash.refresh_token;
+
+      if (hash.token_type === 'bearer') {
+        this.token_type = 'Bearer';
+      } else {
+        this.token_type = hash.token_type;
+      }
+    }
+  }
+
+  save() {
+    localStorage.setItem('access_token', this.access_token);
+    localStorage.setItem('refresh_token', this.refresh_token);
+    localStorage.setItem('token_type', this.token_type);
+  }
+}
diff --git a/client/app/shared/users/user.model.ts b/client/app/shared/users/user.model.ts
new file mode 100644 (file)
index 0000000..ca0a5f2
--- /dev/null
@@ -0,0 +1,20 @@
+import { Token } from './token.model';
+
+export class User {
+  username: string;
+  token: Token;
+
+  static load() {
+    return new User(localStorage.getItem('username'), Token.load());
+  }
+
+  constructor(username: string, hash_token: any) {
+    this.username = username;
+    this.token = new Token(hash_token);
+  }
+
+  save() {
+    localStorage.setItem('username', this.username);
+    this.token.save();
+  }
+}
diff --git a/client/app/users/index.ts b/client/app/users/index.ts
deleted file mode 100644 (file)
index 4f08b8b..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-export * from './login/index';
-export * from './shared/index';
diff --git a/client/app/users/login/index.ts b/client/app/users/login/index.ts
deleted file mode 100644 (file)
index 69c1644..0000000
+++ /dev/null
@@ -1 +0,0 @@
-export * from './login.component';
diff --git a/client/app/users/login/login.component.html b/client/app/users/login/login.component.html
deleted file mode 100644 (file)
index 9406945..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-<h3>Login</h3>
-<form role="form" (submit)="login(username.value, password.value)">
-  <div class="form-group">
-    <label for="username">Username</label>
-    <input type="text" #username class="form-control" id="username" placeholder="Username">
-  </div>
-
-  <div class="form-group">
-    <label for="password">Password</label>
-    <input type="password" #password class="form-control" id="password" placeholder="Password">
-  </div>
-
-  <input type="submit" value="Login" class="btn btn-default">
-</form>
diff --git a/client/app/users/login/login.component.scss b/client/app/users/login/login.component.scss
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/client/app/users/login/login.component.ts b/client/app/users/login/login.component.ts
deleted file mode 100644 (file)
index 09c5f1a..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-import { Component } from '@angular/core';
-import { Router } from '@angular/router-deprecated';
-
-import { AuthService, AuthStatus, User } from '../shared/index';
-
-@Component({
-  selector: 'my-user-login',
-  styleUrls: [ 'client/app/users/login/login.component.css' ],
-  templateUrl: 'client/app/users/login/login.component.html'
-})
-
-export class UserLoginComponent {
-  constructor(
-    private authService: AuthService,
-    private router: Router
-  ) {}
-
-  login(username: string, password: string) {
-    this.authService.login(username, password).subscribe(
-      result => {
-        const user = new User(username, result);
-        user.save();
-
-        this.authService.setStatus(AuthStatus.LoggedIn);
-
-        this.router.navigate(['VideosList']);
-      },
-      error => {
-        if (error.error === 'invalid_grant') {
-          alert('Credentials are invalid.');
-        } else {
-          alert(`${error.error}: ${error.error_description}`);
-        }
-      }
-    );
-  }
-}
diff --git a/client/app/users/shared/auth-status.model.ts b/client/app/users/shared/auth-status.model.ts
deleted file mode 100644 (file)
index f646bd4..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-export enum AuthStatus {
-  LoggedIn,
-  LoggedOut
-}
diff --git a/client/app/users/shared/auth.service.ts b/client/app/users/shared/auth.service.ts
deleted file mode 100644 (file)
index d63fe38..0000000
+++ /dev/null
@@ -1,108 +0,0 @@
-import { Injectable } from '@angular/core';
-import { Headers, Http, RequestOptions, Response, URLSearchParams } from '@angular/http';
-import { Observable, Subject } from 'rxjs/Rx';
-
-import { AuthStatus } from './auth-status.model';
-import { User } from './user.model';
-
-@Injectable()
-export class AuthService {
-  private static BASE_CLIENT_URL = '/api/v1/users/client';
-  private static BASE_LOGIN_URL = '/api/v1/users/token';
-
-  loginChangedSource: Observable<AuthStatus>;
-
-  private clientId: string;
-  private clientSecret: string;
-  private loginChanged: Subject<AuthStatus>;
-
-  constructor(private http: Http) {
-    this.loginChanged = new Subject<AuthStatus>();
-    this.loginChangedSource = this.loginChanged.asObservable();
-
-    // Fetch the client_id/client_secret
-    // FIXME: save in local storage?
-    this.http.get(AuthService.BASE_CLIENT_URL)
-      .map(res => res.json())
-      .catch(this.handleError)
-      .subscribe(
-        result => {
-          this.clientId = result.client_id;
-          this.clientSecret = result.client_secret;
-          console.log('Client credentials loaded.');
-        },
-        error => {
-          alert(error);
-        }
-      );
-  }
-
-  getAuthRequestOptions(): RequestOptions {
-    return new RequestOptions({ headers: this.getRequestHeader() });
-  }
-
-  getRequestHeader() {
-    return new Headers({ 'Authorization': `${this.getTokenType()} ${this.getToken()}` });
-  }
-
-  getToken() {
-    return localStorage.getItem('access_token');
-  }
-
-  getTokenType() {
-    return localStorage.getItem('token_type');
-  }
-
-  getUser(): User {
-    if (this.isLoggedIn() === false) {
-      return null;
-    }
-
-    const user = User.load();
-
-    return user;
-  }
-
-  isLoggedIn() {
-    if (this.getToken()) {
-      return true;
-    } else {
-      return false;
-    }
-  }
-
-  login(username: string, password: string) {
-    let body = new URLSearchParams();
-    body.set('client_id', this.clientId);
-    body.set('client_secret', this.clientSecret);
-    body.set('response_type', 'code');
-    body.set('grant_type', 'password');
-    body.set('scope', 'upload');
-    body.set('username', username);
-    body.set('password', password);
-
-    let headers = new Headers();
-    headers.append('Content-Type', 'application/x-www-form-urlencoded');
-
-    let options = {
-      headers: headers
-    };
-
-    return this.http.post(AuthService.BASE_LOGIN_URL, body.toString(), options)
-                    .map(res => res.json())
-                    .catch(this.handleError);
-  }
-
-  logout() {
-    // TODO make HTTP request
-  }
-
-  setStatus(status: AuthStatus) {
-    this.loginChanged.next(status);
-  }
-
-  private handleError (error: Response) {
-    console.error(error);
-    return Observable.throw(error.json() || { error: 'Server error' });
-  }
-}
diff --git a/client/app/users/shared/index.ts b/client/app/users/shared/index.ts
deleted file mode 100644 (file)
index c6816b3..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-export * from './auth-status.model';
-export * from './auth.service';
-export * from './token.model';
-export * from './user.model';
diff --git a/client/app/users/shared/token.model.ts b/client/app/users/shared/token.model.ts
deleted file mode 100644 (file)
index 021c83f..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-export class Token {
-  access_token: string;
-  refresh_token: string;
-  token_type: string;
-
-  static load() {
-    return new Token({
-      access_token: localStorage.getItem('access_token'),
-      refresh_token: localStorage.getItem('refresh_token'),
-      token_type: localStorage.getItem('token_type')
-    });
-  }
-
-  constructor(hash?: any) {
-    if (hash) {
-      this.access_token = hash.access_token;
-      this.refresh_token = hash.refresh_token;
-
-      if (hash.token_type === 'bearer') {
-        this.token_type = 'Bearer';
-      } else {
-        this.token_type = hash.token_type;
-      }
-    }
-  }
-
-  save() {
-    localStorage.setItem('access_token', this.access_token);
-    localStorage.setItem('refresh_token', this.refresh_token);
-    localStorage.setItem('token_type', this.token_type);
-  }
-}
diff --git a/client/app/users/shared/user.model.ts b/client/app/users/shared/user.model.ts
deleted file mode 100644 (file)
index ca0a5f2..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-import { Token } from './token.model';
-
-export class User {
-  username: string;
-  token: Token;
-
-  static load() {
-    return new User(localStorage.getItem('username'), Token.load());
-  }
-
-  constructor(username: string, hash_token: any) {
-    this.username = username;
-    this.token = new Token(hash_token);
-  }
-
-  save() {
-    localStorage.setItem('username', this.username);
-    this.token.save();
-  }
-}
index 7b6519f007a01f807f7c4f9a83ff6b377a1b9106..a786b2ab26984ab601a10cc56f4e291b7b1226ee 100644 (file)
@@ -5,7 +5,7 @@ import { Observable } from 'rxjs/Rx';
 import { Pagination } from './pagination.model';
 import { Search } from '../../shared/index';
 import { SortField } from './sort-field.type';
-import { AuthService } from '../../users/index';
+import { AuthService } from '../../shared/index';
 import { Video } from './video.model';
 
 @Injectable()
index 619a4f4d868ee330b9622a6e0103531768633d89..e17b1b0f6b389027acf9ed9dd9911fc11eed417e 100644 (file)
@@ -7,7 +7,7 @@ import { Router } from '@angular/router-deprecated';
 import { BytesPipe } from 'angular-pipes/src/math/bytes.pipe';
 import { PROGRESSBAR_DIRECTIVES } from 'ng2-bootstrap/components/progressbar';
 
-import { AuthService, User } from '../../users/index';
+import { AuthService, User } from '../../shared/index';
 
 @Component({
   selector: 'my-videos-add',
index 6322860be8b0e8f3cd8d9a8f4df1a649af4fd9f3..baca00deb10877ffdccb1dadc11a857061f67e44 100644 (file)
@@ -10,8 +10,7 @@ import {
   Video,
   VideoService
 } from '../shared/index';
-import { Search, SearchField } from '../../shared/index';
-import { AuthService, User } from '../../users/index';
+import { AuthService, Search, SearchField, User } from '../../shared/index';
 import { VideoMiniatureComponent } from './video-miniature.component';
 import { VideoSortComponent } from './video-sort.component';
 
index 3baa1ddd648a6210063907819232c25857533af7..11b828ca6a17a0c624976412e137ed2ea7327380 100644 (file)
@@ -3,7 +3,7 @@ import { Component, Input, Output, EventEmitter } from '@angular/core';
 import { ROUTER_DIRECTIVES } from '@angular/router-deprecated';
 
 import { Video, VideoService } from '../shared/index';
-import { User } from '../../users/index';
+import { User } from '../../shared/index';
 
 @Component({
   selector: 'my-video-miniature',
index 24583f6c3e57168a8c54da3178a5c8f5c553aa02..a8b8269a49ee66ea71d8008a59d2df512ce2d2a1 100644 (file)
     "app/app.component.ts",
     "app/friends/friend.service.ts",
     "app/friends/index.ts",
+    "app/login/index.ts",
+    "app/login/login.component.ts",
     "app/shared/index.ts",
-    "app/shared/search-field.type.ts",
-    "app/shared/search.component.ts",
-    "app/shared/search.model.ts",
-    "app/users/index.ts",
-    "app/users/login/index.ts",
-    "app/users/login/login.component.ts",
-    "app/users/shared/auth-status.model.ts",
-    "app/users/shared/auth.service.ts",
-    "app/users/shared/index.ts",
-    "app/users/shared/token.model.ts",
-    "app/users/shared/user.model.ts",
+    "app/shared/search/index.ts",
+    "app/shared/search/search-field.type.ts",
+    "app/shared/search/search.component.ts",
+    "app/shared/search/search.model.ts",
+    "app/shared/users/auth-status.model.ts",
+    "app/shared/users/auth.service.ts",
+    "app/shared/users/index.ts",
+    "app/shared/users/token.model.ts",
+    "app/shared/users/user.model.ts",
     "app/videos/index.ts",
     "app/videos/shared/index.ts",
     "app/videos/shared/loader/index.ts",