"@types/uglify-js": "^2.0.27",
"@types/videojs": "0.0.30",
"@types/webpack": "^1.12.29",
- "angular-pipes": "^4.0.0",
+ "angular-pipes": "^5.0.0",
"angular2-template-loader": "^0.6.0",
"assets-webpack-plugin": "^3.4.0",
"awesome-typescript-loader": "^2.2.1",
"json-loader": "^0.5.4",
"ng2-bootstrap": "1.1.16",
"ng2-file-upload": "^1.1.0",
- "ng2-meta": "github:chocobozzz/ng2-meta",
+ "ng2-meta": "^2.0.0",
"node-sass": "^3.10.0",
"normalize.css": "^5.0.0",
"raw-loader": "^0.5.1",
--- /dev/null
+import { NgModule } from '@angular/core';
+import { RouterModule, Routes } from '@angular/router';
+
+import { AccountComponent } from './account.component';
+
+const accountRoutes: Routes = [
+ {
+ path: 'account',
+ component: AccountComponent,
+ data: {
+ meta: {
+ titleSuffix: ' - My account'
+ }
+ }
+ }
+];
+
+@NgModule({
+ imports: [ RouterModule.forChild(accountRoutes) ],
+ exports: [ RouterModule ]
+})
+export class AccountRoutingModule {}
--- /dev/null
+import { NgModule } from '@angular/core';
+
+import { AccountRoutingModule } from './account-routing.module';
+import { AccountComponent } from './account.component';
+import { AccountService } from './account.service';
+import { SharedModule } from '../shared';
+
+@NgModule({
+ imports: [
+ AccountRoutingModule,
+ SharedModule
+ ],
+
+ declarations: [
+ AccountComponent
+ ],
+
+ exports: [
+ AccountComponent
+ ],
+
+ providers: [
+ AccountService
+ ]
+})
+export class AccountModule { }
+++ /dev/null
-import { AccountComponent } from './account.component';
-
-export const AccountRoutes = [
- {
- path: 'account',
- component: AccountComponent,
- data: {
- meta: {
- titleSuffix: ' - My account'
- }
- }
- }
-];
import { Injectable } from '@angular/core';
-import { AuthHttp, AuthService, RestExtractor } from '../shared';
+import { AuthService } from '../core';
+import { AuthHttp, RestExtractor } from '../shared';
@Injectable()
export class AccountService {
+export * from './account-routing.module';
export * from './account.component';
-export * from './account.routes';
+export * from './account.module';
export * from './account.service';
--- /dev/null
+import { NgModule } from '@angular/core';
+import { RouterModule, Routes } from '@angular/router';
+
+import { AdminComponent } from './admin.component';
+import { FriendsRoutes } from './friends';
+import { RequestsRoutes } from './requests';
+import { UsersRoutes } from './users';
+
+const adminRoutes: Routes = [
+ {
+ path: 'admin',
+ component: AdminComponent,
+ children: [
+ {
+ path: '',
+ redirectTo: 'users',
+ pathMatch: 'full'
+ },
+ ...FriendsRoutes,
+ ...RequestsRoutes,
+ ...UsersRoutes
+ ]
+ }
+];
+
+@NgModule({
+ imports: [ RouterModule.forChild(adminRoutes) ],
+ exports: [ RouterModule ]
+})
+export class AdminRoutingModule {}
--- /dev/null
+import { NgModule } from '@angular/core';
+
+import { AdminComponent } from './admin.component';
+import { AdminRoutingModule } from './admin-routing.module';
+import { FriendsComponent, FriendAddComponent, FriendListComponent, FriendService } from './friends';
+import { RequestsComponent, RequestStatsComponent, RequestService } from './requests';
+import { UsersComponent, UserAddComponent, UserListComponent, UserService } from './users';
+import { MenuAdminComponent } from './menu-admin.component';
+import { SharedModule } from '../shared';
+
+@NgModule({
+ imports: [
+ AdminRoutingModule,
+ SharedModule
+ ],
+
+ declarations: [
+ AdminComponent,
+
+ FriendsComponent,
+ FriendAddComponent,
+ FriendListComponent,
+
+ RequestsComponent,
+ RequestStatsComponent,
+
+ UsersComponent,
+ UserAddComponent,
+ UserListComponent,
+
+ MenuAdminComponent
+ ],
+
+ exports: [
+ AdminComponent,
+ MenuAdminComponent
+ ],
+
+ providers: [
+ FriendService,
+ RequestService,
+ UserService
+ ]
+})
+export class AdminModule { }
+++ /dev/null
-import { Routes } from '@angular/router';
-
-import { AdminComponent } from './admin.component';
-import { FriendsRoutes } from './friends';
-import { RequestsRoutes } from './requests';
-import { UsersRoutes } from './users';
-
-export const AdminRoutes: Routes = [
- {
- path: 'admin',
- component: AdminComponent,
- children: [
- {
- path: '',
- redirectTo: 'users',
- pathMatch: 'full'
- },
- ...FriendsRoutes,
- ...RequestsRoutes,
- ...UsersRoutes
- ]
- }
-];
export * from './friends';
export * from './requests';
export * from './users';
+export * from './admin-routing.module';
+export * from './admin.module';
export * from './admin.component';
-export * from './admin.routes';
export * from './menu-admin.component';
--- /dev/null
+import { NgModule } from '@angular/core';
+import { Routes, RouterModule } from '@angular/router';
+
+const routes: Routes = [
+ {
+ path: '',
+ redirectTo: '/videos/list',
+ pathMatch: 'full'
+ }
+];
+
+@NgModule({
+ imports: [ RouterModule.forRoot(routes) ],
+ exports: [ RouterModule ]
+})
+export class AppRoutingModule {}
+
import { ApplicationRef, NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
-import { FormsModule, ReactiveFormsModule } from '@angular/forms';
-import { HttpModule, RequestOptions, XHRBackend } from '@angular/http';
-import { RouterModule } from '@angular/router';
import { removeNgStyles, createNewHosts } from '@angularclass/hmr';
-import { BytesPipe } from 'angular-pipes/src/math/bytes.pipe';
+import { MetaModule, MetaConfig } from 'ng2-meta';
-import { DropdownModule } from 'ng2-bootstrap/components/dropdown';
-import { ProgressbarModule } from 'ng2-bootstrap/components/progressbar';
-import { PaginationModule } from 'ng2-bootstrap/components/pagination';
-import { ModalModule } from 'ng2-bootstrap/components/modal';
-
-import { FileUploadModule } from 'ng2-file-upload/ng2-file-upload';
-
-import { MetaConfig, MetaModule } from 'ng2-meta';
-
-/*
- * Platform and Environment providers/directives/pipes
- */
import { ENV_PROVIDERS } from './environment';
-import { routes } from './app.routes';
-// App is our top level component
+import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { AppState } from './app.service';
-import {
- AdminComponent,
- FriendsComponent,
- FriendAddComponent,
- FriendListComponent,
- FriendService,
- MenuAdminComponent,
- RequestsComponent,
- RequestStatsComponent,
- RequestService,
- UsersComponent,
- UserAddComponent,
- UserListComponent,
- UserService
-} from './admin';
-import { AccountComponent, AccountService } from './account';
-import { LoginComponent } from './login';
+import { AccountModule } from './account';
+import { AdminModule } from './admin';
+import { CoreModule } from './core';
+import { LoginModule } from './login';
+import { SharedModule } from './shared';
+import { VideosModule } from './videos';
+
import { MenuComponent } from './menu.component';
-import { AuthService, AuthHttp, RestExtractor, RestService, SearchComponent, SearchService } from './shared';
-import {
- LoaderComponent,
- VideosComponent,
- VideoAddComponent,
- VideoListComponent,
- VideoMiniatureComponent,
- VideoSortComponent,
- VideoWatchComponent,
- VideoShareComponent,
- VideoMagnetComponent,
- VideoService,
- WebTorrentService
-} from './videos';
const metaConfig: MetaConfig = {
//Append a title suffix such as a site name to all titles
// Application wide providers
const APP_PROVIDERS = [
- AppState,
-
- {
- provide: AuthHttp,
- useFactory: (backend: XHRBackend, defaultOptions: RequestOptions, authService: AuthService) => {
- return new AuthHttp(backend, defaultOptions, authService);
- },
- deps: [ XHRBackend, RequestOptions, AuthService ]
- },
-
- AuthService,
- RestExtractor,
- RestService,
-
- VideoService,
- SearchService,
- FriendService,
- RequestService,
- UserService,
- AccountService,
- WebTorrentService
+ AppState
];
-/**
- * `AppModule` is the main entry point into Angular2's bootstraping process
- */
+
@NgModule({
bootstrap: [ AppComponent ],
declarations: [
- AccountComponent,
- AdminComponent,
AppComponent,
- BytesPipe,
- FriendAddComponent,
- FriendListComponent,
- FriendsComponent,
- LoaderComponent,
- LoginComponent,
- MenuAdminComponent,
- MenuComponent,
- RequestsComponent,
- RequestStatsComponent,
- SearchComponent,
- UserAddComponent,
- UserListComponent,
- UsersComponent,
- VideoAddComponent,
- VideoListComponent,
- VideoMiniatureComponent,
- VideosComponent,
- VideoSortComponent,
- VideoWatchComponent,
- VideoShareComponent,
- VideoMagnetComponent
+ MenuComponent
],
- imports: [ // import Angular's modules
+ imports: [
BrowserModule,
- FormsModule,
- ReactiveFormsModule,
- HttpModule,
- RouterModule.forRoot(routes),
- DropdownModule,
- ProgressbarModule,
- PaginationModule,
- ModalModule,
+ CoreModule,
+ SharedModule,
+
+ AppRoutingModule,
- FileUploadModule,
+ MetaModule.forRoot(metaConfig),
- MetaModule.forRoot(metaConfig)
+ AccountModule,
+ AdminModule,
+ CoreModule,
+ LoginModule,
+ SharedModule,
+ VideosModule
],
providers: [ // expose our Services and Providers into Angular's dependency injection
ENV_PROVIDERS,
+++ /dev/null
-import { Routes } from '@angular/router';
-
-import { AccountRoutes } from './account';
-import { LoginRoutes } from './login';
-import { AdminRoutes } from './admin';
-import { VideosRoutes } from './videos';
-
-export const routes: Routes = [
- {
- path: '',
- redirectTo: '/videos/list',
- pathMatch: 'full'
- },
- ...AdminRoutes,
- ...AccountRoutes,
- ...LoginRoutes,
- ...VideosRoutes
-];
--- /dev/null
+import { Injectable } from '@angular/core';
+import { Headers, Http, Response, URLSearchParams } from '@angular/http';
+import { Router } from '@angular/router';
+import { Observable } from 'rxjs/Observable';
+import { Subject } from 'rxjs/Subject';
+
+// 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 class AuthService {
+ private static BASE_CLIENT_URL = '/api/v1/clients/local';
+ private static BASE_TOKEN_URL = '/api/v1/users/token';
+ private static BASE_USER_INFORMATIONS_URL = '/api/v1/users/me';
+
+ loginChangedSource: Observable<AuthStatus>;
+
+ private clientId: string;
+ private clientSecret: string;
+ private loginChanged: Subject<AuthStatus>;
+ private user: AuthUser = null;
+
+ constructor(
+ private http: Http,
+ private restExtractor: RestExtractor,
+ private router: Router
+ ) {
+ 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(this.restExtractor.extractDataGet)
+ .catch((res) => this.restExtractor.handleError(res))
+ .subscribe(
+ result => {
+ this.clientId = result.client_id;
+ this.clientSecret = result.client_secret;
+ console.log('Client credentials loaded.');
+ },
+ error => {
+ alert(
+ `Cannot retrieve OAuth Client credentials: ${error.text}. \n` +
+ 'Ensure you have correctly configured PeerTube (config/ directory), in particular the "webserver" section.'
+ );
+ }
+ );
+
+ // Return null if there is nothing to load
+ this.user = AuthUser.load();
+ }
+
+ getRefreshToken() {
+ if (this.user === null) return null;
+
+ return this.user.getRefreshToken();
+ }
+
+ getRequestHeaderValue() {
+ return `${this.getTokenType()} ${this.getAccessToken()}`;
+ }
+
+ getAccessToken() {
+ if (this.user === null) return null;
+
+ return this.user.getAccessToken();
+ }
+
+ getTokenType() {
+ if (this.user === null) return null;
+
+ return this.user.getTokenType();
+ }
+
+ getUser(): AuthUser {
+ return this.user;
+ }
+
+ isAdmin() {
+ if (this.user === null) return false;
+
+ return this.user.isAdmin();
+ }
+
+ isLoggedIn() {
+ if (this.getAccessToken()) {
+ 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_TOKEN_URL, body.toString(), options)
+ .map(this.restExtractor.extractDataGet)
+ .map(res => {
+ res.username = username;
+ return res;
+ })
+ .flatMap(res => this.fetchUserInformations(res))
+ .map(res => this.handleLogin(res))
+ .catch((res) => this.restExtractor.handleError(res));
+ }
+
+ logout() {
+ // TODO: make an HTTP request to revoke the tokens
+ this.user = null;
+
+ AuthUser.flush();
+
+ this.setStatus(AuthStatus.LoggedOut);
+ }
+
+ refreshAccessToken() {
+ console.log('Refreshing token...');
+
+ const refreshToken = this.getRefreshToken();
+
+ let body = new URLSearchParams();
+ body.set('refresh_token', refreshToken);
+ body.set('client_id', this.clientId);
+ body.set('client_secret', this.clientSecret);
+ body.set('response_type', 'code');
+ body.set('grant_type', 'refresh_token');
+
+ let headers = new Headers();
+ headers.append('Content-Type', 'application/x-www-form-urlencoded');
+
+ let options = {
+ headers: headers
+ };
+
+ return this.http.post(AuthService.BASE_TOKEN_URL, body.toString(), options)
+ .map(this.restExtractor.extractDataGet)
+ .map(res => this.handleRefreshToken(res))
+ .catch((res: Response) => {
+ // The refresh token is invalid?
+ if (res.status === 400 && res.json() && res.json().error === 'invalid_grant') {
+ console.error('Cannot refresh token -> logout...');
+ this.logout();
+ this.router.navigate(['/login']);
+
+ return Observable.throw({
+ json: () => '',
+ text: () => 'You need to reconnect.'
+ });
+ }
+
+ return this.restExtractor.handleError(res);
+ });
+ }
+
+ private fetchUserInformations (obj: any) {
+ // Do not call authHttp here to avoid circular dependencies headaches
+
+ const headers = new Headers();
+ headers.set('Authorization', `Bearer ${obj.access_token}`);
+
+ return this.http.get(AuthService.BASE_USER_INFORMATIONS_URL, { headers })
+ .map(res => res.json())
+ .map(res => {
+ obj.id = res.id;
+ obj.role = res.role;
+ return obj;
+ }
+ );
+ }
+
+ private handleLogin (obj: any) {
+ const id = obj.id;
+ const username = obj.username;
+ const role = obj.role;
+ const hashTokens = {
+ access_token: obj.access_token,
+ token_type: obj.token_type,
+ refresh_token: obj.refresh_token
+ };
+
+ this.user = new AuthUser({ id, username, role }, hashTokens);
+ this.user.save();
+
+ this.setStatus(AuthStatus.LoggedIn);
+ }
+
+ private handleRefreshToken (obj: any) {
+ this.user.refreshTokens(obj.access_token, obj.refresh_token);
+ this.user.save();
+ }
+
+ private setStatus(status: AuthStatus) {
+ this.loginChanged.next(status);
+ }
+
+}
--- /dev/null
+export * from './auth.service'
--- /dev/null
+import { NgModule, Optional, SkipSelf } from '@angular/core';
+import { CommonModule } from '@angular/common';
+import { HttpModule } from '@angular/http';
+
+import { AuthService } from './auth';
+import { throwIfAlreadyLoaded } from './module-import-guard';
+
+@NgModule({
+ imports: [
+ CommonModule,
+ HttpModule
+ ],
+ declarations: [ ],
+ exports: [ ],
+ providers: [ AuthService ]
+})
+export class CoreModule {
+ constructor( @Optional() @SkipSelf() parentModule: CoreModule) {
+ throwIfAlreadyLoaded(parentModule, 'CoreModule');
+ }
+}
--- /dev/null
+export * from './auth';
+export * from './core.module'
--- /dev/null
+export function throwIfAlreadyLoaded(parentModule: any, moduleName: string) {
+ if (parentModule) {
+ throw new Error(`${moduleName} has already been loaded. Import Core modules in the AppModule only.`);
+ }
+}
+export * from './login-routing.module';
export * from './login.component';
-export * from './login.routes';
+export * from './login.module';
--- /dev/null
+import { NgModule } from '@angular/core';
+import { RouterModule, Routes } from '@angular/router';
+
+import { LoginComponent } from './login.component';
+
+const loginRoutes: Routes = [
+ {
+ path: 'login',
+ component: LoginComponent,
+ data: {
+ meta: {
+ titleSuffix: ' - Login'
+ }
+ }
+ }
+];
+
+@NgModule({
+ imports: [ RouterModule.forChild(loginRoutes) ],
+ exports: [ RouterModule ]
+})
+export class LoginRoutingModule {}
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Router } from '@angular/router';
-import { AuthService, FormReactive } from '../shared';
+import { AuthService } from '../core';
+import { FormReactive } from '../shared';
@Component({
selector: 'my-login',
--- /dev/null
+import { NgModule } from '@angular/core';
+
+import { LoginRoutingModule } from './login-routing.module';
+import { LoginComponent } from './login.component';
+import { SharedModule } from '../shared';
+
+@NgModule({
+ imports: [
+ LoginRoutingModule,
+ SharedModule
+ ],
+
+ declarations: [
+ LoginComponent
+ ],
+
+ exports: [
+ LoginComponent
+ ],
+
+ providers: [
+ ]
+})
+export class LoginModule { }
+++ /dev/null
-import { LoginComponent } from './login.component';
-
-export const LoginRoutes = [
- {
- path: 'login',
- component: LoginComponent,
- data: {
- meta: {
- titleSuffix: ' - Login'
- }
- }
- }
-];
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
-import { AuthService, AuthStatus } from './shared';
+import { AuthService } from './core';
+import { AuthStatus } from './shared';
@Component({
selector: 'my-menu',
RequestMethod,
RequestOptions,
RequestOptionsArgs,
- Response
+ Response,
+ XHRBackend
} from '@angular/http';
import { Observable } from 'rxjs/Observable';
-import { AuthService } from './auth.service';
+import { AuthService } from '../../core';
@Injectable()
export class AuthHttp extends Http {
headers.set('Authorization', this.authService.getRequestHeaderValue());
}
}
+
+export const AUTH_HTTP_PROVIDERS = [
+ {
+ provide: AuthHttp,
+ useFactory: (backend: XHRBackend, defaultOptions: RequestOptions, authService: AuthService) => {
+ return new AuthHttp(backend, defaultOptions, authService);
+ },
+ deps: [ XHRBackend, RequestOptions, AuthService ]
+ },
+];
+++ /dev/null
-import { Injectable } from '@angular/core';
-import { Headers, Http, Response, URLSearchParams } from '@angular/http';
-import { Router } from '@angular/router';
-import { Observable } from 'rxjs/Observable';
-import { Subject } from 'rxjs/Subject';
-
-import { AuthStatus } from './auth-status.model';
-import { AuthUser } from './auth-user.model';
-import { RestExtractor } from '../rest';
-
-@Injectable()
-export class AuthService {
- private static BASE_CLIENT_URL = '/api/v1/clients/local';
- private static BASE_TOKEN_URL = '/api/v1/users/token';
- private static BASE_USER_INFORMATIONS_URL = '/api/v1/users/me';
-
- loginChangedSource: Observable<AuthStatus>;
-
- private clientId: string;
- private clientSecret: string;
- private loginChanged: Subject<AuthStatus>;
- private user: AuthUser = null;
-
- constructor(
- private http: Http,
- private restExtractor: RestExtractor,
- private router: Router
- ) {
- 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(this.restExtractor.extractDataGet)
- .catch((res) => this.restExtractor.handleError(res))
- .subscribe(
- result => {
- this.clientId = result.client_id;
- this.clientSecret = result.client_secret;
- console.log('Client credentials loaded.');
- },
- error => {
- alert(
- `Cannot retrieve OAuth Client credentials: ${error.text}. \n` +
- 'Ensure you have correctly configured PeerTube (config/ directory), in particular the "webserver" section.'
- );
- }
- );
-
- // Return null if there is nothing to load
- this.user = AuthUser.load();
- }
-
- getRefreshToken() {
- if (this.user === null) return null;
-
- return this.user.getRefreshToken();
- }
-
- getRequestHeaderValue() {
- return `${this.getTokenType()} ${this.getAccessToken()}`;
- }
-
- getAccessToken() {
- if (this.user === null) return null;
-
- return this.user.getAccessToken();
- }
-
- getTokenType() {
- if (this.user === null) return null;
-
- return this.user.getTokenType();
- }
-
- getUser(): AuthUser {
- return this.user;
- }
-
- isAdmin() {
- if (this.user === null) return false;
-
- return this.user.isAdmin();
- }
-
- isLoggedIn() {
- if (this.getAccessToken()) {
- 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_TOKEN_URL, body.toString(), options)
- .map(this.restExtractor.extractDataGet)
- .map(res => {
- res.username = username;
- return res;
- })
- .flatMap(res => this.fetchUserInformations(res))
- .map(res => this.handleLogin(res))
- .catch((res) => this.restExtractor.handleError(res));
- }
-
- logout() {
- // TODO: make an HTTP request to revoke the tokens
- this.user = null;
-
- AuthUser.flush();
-
- this.setStatus(AuthStatus.LoggedOut);
- }
-
- refreshAccessToken() {
- console.log('Refreshing token...');
-
- const refreshToken = this.getRefreshToken();
-
- let body = new URLSearchParams();
- body.set('refresh_token', refreshToken);
- body.set('client_id', this.clientId);
- body.set('client_secret', this.clientSecret);
- body.set('response_type', 'code');
- body.set('grant_type', 'refresh_token');
-
- let headers = new Headers();
- headers.append('Content-Type', 'application/x-www-form-urlencoded');
-
- let options = {
- headers: headers
- };
-
- return this.http.post(AuthService.BASE_TOKEN_URL, body.toString(), options)
- .map(this.restExtractor.extractDataGet)
- .map(res => this.handleRefreshToken(res))
- .catch((res: Response) => {
- // The refresh token is invalid?
- if (res.status === 400 && res.json() && res.json().error === 'invalid_grant') {
- console.error('Cannot refresh token -> logout...');
- this.logout();
- this.router.navigate(['/login']);
-
- return Observable.throw({
- json: () => '',
- text: () => 'You need to reconnect.'
- });
- }
-
- return this.restExtractor.handleError(res);
- });
- }
-
- private fetchUserInformations (obj: any) {
- // Do not call authHttp here to avoid circular dependencies headaches
-
- const headers = new Headers();
- headers.set('Authorization', `Bearer ${obj.access_token}`);
-
- return this.http.get(AuthService.BASE_USER_INFORMATIONS_URL, { headers })
- .map(res => res.json())
- .map(res => {
- obj.id = res.id;
- obj.role = res.role;
- return obj;
- }
- );
- }
-
- private handleLogin (obj: any) {
- const id = obj.id;
- const username = obj.username;
- const role = obj.role;
- const hashTokens = {
- access_token: obj.access_token,
- token_type: obj.token_type,
- refresh_token: obj.refresh_token
- };
-
- this.user = new AuthUser({ id, username, role }, hashTokens);
- this.user.save();
-
- this.setStatus(AuthStatus.LoggedIn);
- }
-
- private handleRefreshToken (obj: any) {
- this.user.refreshTokens(obj.access_token, obj.refresh_token);
- this.user.save();
- }
-
- private setStatus(status: AuthStatus) {
- this.loginChanged.next(status);
- }
-
-}
export * from './auth-http.service';
export * from './auth-status.model';
-export * from './auth.service';
export * from './auth-user.model';
export * from './rest';
export * from './search';
export * from './users';
+export * from './shared.module';
--- /dev/null
+import { NgModule } from '@angular/core';
+import { CommonModule } from '@angular/common';
+import { HttpModule } from '@angular/http';
+import { FormsModule, ReactiveFormsModule } from '@angular/forms';
+import { RouterModule } from '@angular/router';
+
+import { BytesPipe } from 'angular-pipes/src/math/bytes.pipe';
+import { DropdownModule } from 'ng2-bootstrap/components/dropdown';
+import { ProgressbarModule } from 'ng2-bootstrap/components/progressbar';
+import { PaginationModule } from 'ng2-bootstrap/components/pagination';
+import { ModalModule } from 'ng2-bootstrap/components/modal';
+import { FileUploadModule } from 'ng2-file-upload/ng2-file-upload';
+
+import { AUTH_HTTP_PROVIDERS } from './auth';
+import { RestExtractor, RestService } from './rest';
+import { SearchComponent, SearchService } from './search';
+
+@NgModule({
+ imports: [
+ CommonModule,
+ FormsModule,
+ ReactiveFormsModule,
+ HttpModule,
+ RouterModule,
+
+ DropdownModule,
+ FileUploadModule,
+ ModalModule,
+ PaginationModule,
+ ProgressbarModule
+ ],
+
+ declarations: [
+ BytesPipe,
+ SearchComponent
+ ],
+
+ exports: [
+ CommonModule,
+ FormsModule,
+ ReactiveFormsModule,
+ HttpModule,
+ RouterModule,
+
+ DropdownModule,
+ FileUploadModule,
+ ModalModule,
+ PaginationModule,
+ ProgressbarModule,
+ BytesPipe,
+
+ SearchComponent
+ ],
+
+ providers: [
+ AUTH_HTTP_PROVIDERS,
+ RestExtractor,
+ RestService,
+ SearchService
+ ]
+})
+export class SharedModule { }
export * from './video-add';
export * from './video-list';
export * from './video-watch';
+export * from './videos-routing.module';
export * from './videos.component';
-export * from './videos.routes';
+export * from './videos.module';
import { Search } from '../../shared';
import { SortField } from './sort-field.type';
-import { AuthHttp, AuthService, RestExtractor, RestPagination, RestService, ResultList } from '../../shared';
+import { AuthService } from '../../core';
+import { AuthHttp, RestExtractor, RestPagination, RestService, ResultList } from '../../shared';
import { Video } from './video.model';
@Injectable()
import { FileUploader } from 'ng2-file-upload/ng2-file-upload';
-import { AuthService, FormReactive, VIDEO_NAME, VIDEO_DESCRIPTION, VIDEO_TAGS } from '../../shared';
+import { AuthService } from '../../core';
+import { FormReactive, VIDEO_NAME, VIDEO_DESCRIPTION, VIDEO_TAGS } from '../../shared';
@Component({
selector: 'my-videos-add',
Video,
VideoService
} from '../shared';
-import { AuthService, AuthUser, RestPagination, Search, SearchField } from '../../shared';
+import { AuthService } from '../../core';
+import { AuthUser, RestPagination, Search, SearchField } from '../../shared';
import { SearchService } from '../../shared';
@Component({
--- /dev/null
+import { NgModule } from '@angular/core';
+import { RouterModule, Routes } from '@angular/router';
+
+import { VideoAddComponent } from './video-add';
+import { VideoListComponent } from './video-list';
+import { VideosComponent } from './videos.component';
+import { VideoWatchComponent } from './video-watch';
+
+const videosRoutes: Routes = [
+ {
+ path: 'videos',
+ component: VideosComponent,
+ children: [
+ {
+ path: 'list',
+ component: VideoListComponent,
+ data: {
+ meta: {
+ titleSuffix: ' - Videos list'
+ }
+ }
+ },
+ {
+ path: 'add',
+ component: VideoAddComponent,
+ data: {
+ meta: {
+ titleSuffix: ' - Add a video'
+ }
+ }
+ },
+ {
+ path: 'watch/:id',
+ component: VideoWatchComponent
+ }
+ ]
+ }
+];
+
+@NgModule({
+ imports: [ RouterModule.forChild(videosRoutes) ],
+ exports: [ RouterModule ]
+})
+export class VideosRoutingModule {}
--- /dev/null
+import { NgModule } from '@angular/core';
+
+import { VideosRoutingModule } from './videos-routing.module';
+import { VideosComponent } from './videos.component';
+import { VideoAddComponent } from './video-add';
+import { VideoListComponent, VideoMiniatureComponent, VideoSortComponent } from './video-list';
+import { VideoWatchComponent, VideoMagnetComponent, VideoShareComponent, WebTorrentService } from './video-watch';
+import { LoaderComponent, VideoService } from './shared';
+import { SharedModule } from '../shared';
+
+@NgModule({
+ imports: [
+ VideosRoutingModule,
+ SharedModule
+ ],
+
+ declarations: [
+ VideosComponent,
+
+ VideoAddComponent,
+
+ VideoListComponent,
+ VideoMiniatureComponent,
+ VideoSortComponent,
+
+ VideoWatchComponent,
+ VideoMagnetComponent,
+ VideoShareComponent,
+
+ LoaderComponent
+ ],
+
+ exports: [
+ VideosComponent
+ ],
+
+ providers: [
+ VideoService,
+ WebTorrentService
+ ]
+})
+export class VideosModule { }
+++ /dev/null
-import { Routes } from '@angular/router';
-
-import { VideoAddComponent } from './video-add';
-import { VideoListComponent } from './video-list';
-import { VideosComponent } from './videos.component';
-import { VideoWatchComponent } from './video-watch';
-
-export const VideosRoutes: Routes = [
- {
- path: 'videos',
- component: VideosComponent,
- children: [
- {
- path: 'list',
- component: VideoListComponent,
- data: {
- meta: {
- titleSuffix: ' - Videos list'
- }
- }
- },
- {
- path: 'add',
- component: VideoAddComponent,
- data: {
- meta: {
- titleSuffix: ' - Add a video'
- }
- }
- },
- {
- path: 'watch/:id',
- component: VideoWatchComponent
- }
- ]
- }
-];