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,
{
path: '/users/login',
name: 'UserLogin',
- component: UserLoginComponent
+ component: LoginComponent
},
{
path: '/videos/list',
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);
}
--- /dev/null
+export * from './login.component';
--- /dev/null
+<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>
--- /dev/null
+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}`);
+ }
+ }
+ );
+ }
+}
-export * from './search-field.type';
-export * from './search.component';
-export * from './search.model';
+export * from './search/index';
+export * from './users/index'
+++ /dev/null
-export type SearchField = "name" | "author" | "podUrl" | "magnetUri";
+++ /dev/null
-<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>
+++ /dev/null
-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];
- }
-}
+++ /dev/null
-import { SearchField } from './search-field.type';
-
-export interface Search {
- field: SearchField;
- value: string;
-}
--- /dev/null
+export * from './search-field.type';
+export * from './search.component';
+export * from './search.model';
--- /dev/null
+export type SearchField = "name" | "author" | "podUrl" | "magnetUri";
--- /dev/null
+<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>
--- /dev/null
+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];
+ }
+}
--- /dev/null
+import { SearchField } from './search-field.type';
+
+export interface Search {
+ field: SearchField;
+ value: string;
+}
--- /dev/null
+export enum AuthStatus {
+ LoggedIn,
+ LoggedOut
+}
--- /dev/null
+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' });
+ }
+}
--- /dev/null
+export * from './auth-status.model';
+export * from './auth.service';
+export * from './token.model';
+export * from './user.model';
--- /dev/null
+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);
+ }
+}
--- /dev/null
+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();
+ }
+}
+++ /dev/null
-export * from './login/index';
-export * from './shared/index';
+++ /dev/null
-export * from './login.component';
+++ /dev/null
-<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>
+++ /dev/null
-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}`);
- }
- }
- );
- }
-}
+++ /dev/null
-export enum AuthStatus {
- LoggedIn,
- LoggedOut
-}
+++ /dev/null
-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' });
- }
-}
+++ /dev/null
-export * from './auth-status.model';
-export * from './auth.service';
-export * from './token.model';
-export * from './user.model';
+++ /dev/null
-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);
- }
-}
+++ /dev/null
-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();
- }
-}
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()
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',
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';
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',
"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",