From df98563e2104b82b119c00a3cd83cd0dc1242d25 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jun 2017 14:32:15 +0200 Subject: Use typescript standard and lint all files --- client/src/app/core/auth/auth-user.model.ts | 180 ++++++++--------- client/src/app/core/auth/auth.service.ts | 236 +++++++++++------------ client/src/app/core/auth/index.ts | 4 +- client/src/app/core/config/config.service.ts | 24 +-- client/src/app/core/config/index.ts | 2 +- client/src/app/core/confirm/confirm.component.ts | 48 ++--- client/src/app/core/confirm/confirm.service.ts | 16 +- client/src/app/core/confirm/index.ts | 4 +- client/src/app/core/core.module.ts | 26 +-- client/src/app/core/index.ts | 8 +- client/src/app/core/menu/index.ts | 4 +- client/src/app/core/menu/menu-admin.component.ts | 2 +- client/src/app/core/menu/menu.component.ts | 40 ++-- client/src/app/core/module-import-guard.ts | 4 +- 14 files changed, 302 insertions(+), 296 deletions(-) (limited to 'client/src/app/core') diff --git a/client/src/app/core/auth/auth-user.model.ts b/client/src/app/core/auth/auth-user.model.ts index 1a31a7834..65c37bcfa 100644 --- a/client/src/app/core/auth/auth-user.model.ts +++ b/client/src/app/core/auth/auth-user.model.ts @@ -1,6 +1,66 @@ // Do not use the barrel (dependency loop) import { UserRole } from '../../../../../shared/models/user.model' -import { User } from '../../shared/users/user.model'; +import { User } from '../../shared/users/user.model' + +export type TokenOptions = { + accessToken: string + refreshToken: string + tokenType: string +} + +// Private class only used by User +class Tokens { + private static KEYS = { + ACCESS_TOKEN: 'access_token', + REFRESH_TOKEN: 'refresh_token', + TOKEN_TYPE: 'token_type' + } + + accessToken: string + refreshToken: string + tokenType: string + + static load () { + const accessTokenLocalStorage = localStorage.getItem(this.KEYS.ACCESS_TOKEN) + const refreshTokenLocalStorage = localStorage.getItem(this.KEYS.REFRESH_TOKEN) + const tokenTypeLocalStorage = localStorage.getItem(this.KEYS.TOKEN_TYPE) + + if (accessTokenLocalStorage && refreshTokenLocalStorage && tokenTypeLocalStorage) { + return new Tokens({ + accessToken: accessTokenLocalStorage, + refreshToken: refreshTokenLocalStorage, + tokenType: tokenTypeLocalStorage + }) + } + + return null + } + + static flush () { + localStorage.removeItem(this.KEYS.ACCESS_TOKEN) + localStorage.removeItem(this.KEYS.REFRESH_TOKEN) + localStorage.removeItem(this.KEYS.TOKEN_TYPE) + } + + constructor (hash?: TokenOptions) { + if (hash) { + this.accessToken = hash.accessToken + this.refreshToken = hash.refreshToken + + if (hash.tokenType === 'bearer') { + this.tokenType = 'Bearer' + } else { + this.tokenType = hash.tokenType + } + } + } + + save () { + localStorage.setItem(Tokens.KEYS.ACCESS_TOKEN, this.accessToken) + localStorage.setItem(Tokens.KEYS.REFRESH_TOKEN, this.refreshToken) + localStorage.setItem(Tokens.KEYS.TOKEN_TYPE, this.tokenType) + } +} export class AuthUser extends User { private static KEYS = { @@ -9,123 +69,69 @@ export class AuthUser extends User { EMAIL: 'email', USERNAME: 'username', DISPLAY_NSFW: 'display_nsfw' - }; + } - tokens: Tokens; + tokens: Tokens - static load() { - const usernameLocalStorage = localStorage.getItem(this.KEYS.USERNAME); + static load () { + const usernameLocalStorage = localStorage.getItem(this.KEYS.USERNAME) if (usernameLocalStorage) { return new AuthUser( { - id: parseInt(localStorage.getItem(this.KEYS.ID)), + id: parseInt(localStorage.getItem(this.KEYS.ID), 10), username: localStorage.getItem(this.KEYS.USERNAME), email: localStorage.getItem(this.KEYS.EMAIL), role: localStorage.getItem(this.KEYS.ROLE) as UserRole, displayNSFW: localStorage.getItem(this.KEYS.DISPLAY_NSFW) === 'true' }, Tokens.load() - ); + ) } - return null; + return null } - static flush() { - localStorage.removeItem(this.KEYS.USERNAME); - localStorage.removeItem(this.KEYS.ID); - localStorage.removeItem(this.KEYS.ROLE); - localStorage.removeItem(this.KEYS.DISPLAY_NSFW); - Tokens.flush(); + static flush () { + localStorage.removeItem(this.KEYS.USERNAME) + localStorage.removeItem(this.KEYS.ID) + localStorage.removeItem(this.KEYS.ROLE) + localStorage.removeItem(this.KEYS.DISPLAY_NSFW) + Tokens.flush() } - constructor(userHash: { + constructor (userHash: { id: number, username: string, role: UserRole, email: string, displayNSFW: boolean - }, hashTokens: any) { - super(userHash); - this.tokens = new Tokens(hashTokens); - } - - getAccessToken() { - return this.tokens.access_token; - } - - getRefreshToken() { - return this.tokens.refresh_token; - } - - getTokenType() { - return this.tokens.token_type; - } - - refreshTokens(access_token: string, refresh_token: string) { - this.tokens.access_token = access_token; - this.tokens.refresh_token = refresh_token; + }, hashTokens: TokenOptions) { + super(userHash) + this.tokens = new Tokens(hashTokens) } - save() { - localStorage.setItem(AuthUser.KEYS.ID, this.id.toString()); - localStorage.setItem(AuthUser.KEYS.USERNAME, this.username); - localStorage.setItem(AuthUser.KEYS.ROLE, this.role); - localStorage.setItem(AuthUser.KEYS.DISPLAY_NSFW, JSON.stringify(this.displayNSFW)); - this.tokens.save(); + getAccessToken () { + return this.tokens.accessToken } -} - -// Private class only used by User -class Tokens { - private static KEYS = { - ACCESS_TOKEN: 'access_token', - REFRESH_TOKEN: 'refresh_token', - TOKEN_TYPE: 'token_type', - }; - - access_token: string; - refresh_token: string; - token_type: string; - - static load() { - const accessTokenLocalStorage = localStorage.getItem(this.KEYS.ACCESS_TOKEN); - const refreshTokenLocalStorage = localStorage.getItem(this.KEYS.REFRESH_TOKEN); - const tokenTypeLocalStorage = localStorage.getItem(this.KEYS.TOKEN_TYPE); - - if (accessTokenLocalStorage && refreshTokenLocalStorage && tokenTypeLocalStorage) { - return new Tokens({ - access_token: accessTokenLocalStorage, - refresh_token: refreshTokenLocalStorage, - token_type: tokenTypeLocalStorage - }); - } - return null; + getRefreshToken () { + return this.tokens.refreshToken } - static flush() { - localStorage.removeItem(this.KEYS.ACCESS_TOKEN); - localStorage.removeItem(this.KEYS.REFRESH_TOKEN); - localStorage.removeItem(this.KEYS.TOKEN_TYPE); + getTokenType () { + return this.tokens.tokenType } - 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; - } - } + refreshTokens (accessToken: string, refreshToken: string) { + this.tokens.accessToken = accessToken + this.tokens.refreshToken = refreshToken } - save() { - localStorage.setItem('access_token', this.access_token); - localStorage.setItem('refresh_token', this.refresh_token); - localStorage.setItem('token_type', this.token_type); + save () { + localStorage.setItem(AuthUser.KEYS.ID, this.id.toString()) + localStorage.setItem(AuthUser.KEYS.USERNAME, this.username) + localStorage.setItem(AuthUser.KEYS.ROLE, this.role) + localStorage.setItem(AuthUser.KEYS.DISPLAY_NSFW, JSON.stringify(this.displayNSFW)) + this.tokens.save() } } diff --git a/client/src/app/core/auth/auth.service.ts b/client/src/app/core/auth/auth.service.ts index 4c75df1ca..32f7a5503 100644 --- a/client/src/app/core/auth/auth.service.ts +++ b/client/src/app/core/auth/auth.service.ts @@ -1,40 +1,40 @@ -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 'rxjs/add/operator/map'; -import 'rxjs/add/operator/mergeMap'; -import 'rxjs/add/observable/throw'; - -import { NotificationsService } from 'angular2-notifications'; - -import { AuthStatus } from './auth-status.model'; -import { AuthUser } from './auth-user.model'; +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 'rxjs/add/operator/map' +import 'rxjs/add/operator/mergeMap' +import 'rxjs/add/observable/throw' + +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 { RestExtractor } from '../../shared/rest'; +import { RestExtractor } from '../../shared/rest' @Injectable() export class AuthService { - private static BASE_CLIENT_URL = API_URL + '/api/v1/clients/local'; - private static BASE_TOKEN_URL = API_URL + '/api/v1/users/token'; - private static BASE_USER_INFORMATIONS_URL = API_URL + '/api/v1/users/me'; + private static BASE_CLIENT_URL = API_URL + '/api/v1/clients/local' + private static BASE_TOKEN_URL = API_URL + '/api/v1/users/token' + private static BASE_USER_INFORMATIONS_URL = API_URL + '/api/v1/users/me' - loginChangedSource: Observable; + loginChangedSource: Observable - private clientId: string; - private clientSecret: string; - private loginChanged: Subject; - private user: AuthUser = null; + private clientId: string + private clientSecret: string + private loginChanged: Subject + private user: AuthUser = null - constructor( + constructor ( private http: Http, private notificationsService: NotificationsService, private restExtractor: RestExtractor, private router: Router ) { - this.loginChanged = new Subject(); - this.loginChangedSource = this.loginChanged.asObservable(); + this.loginChanged = new Subject() + this.loginChangedSource = this.loginChanged.asObservable() // Fetch the client_id/client_secret // FIXME: save in local storage? @@ -43,120 +43,120 @@ export class AuthService { .catch((res) => this.restExtractor.handleError(res)) .subscribe( result => { - this.clientId = result.client_id; - this.clientSecret = result.client_secret; - console.log('Client credentials loaded.'); + this.clientId = result.client_id + this.clientSecret = result.client_secret + console.log('Client credentials loaded.') }, error => { - let errorMessage = `Cannot retrieve OAuth Client credentials: ${error.text}. \n`; - errorMessage += 'Ensure you have correctly configured PeerTube (config/ directory), in particular the "webserver" section.'; + let errorMessage = `Cannot retrieve OAuth Client credentials: ${error.text}. \n` + errorMessage += 'Ensure you have correctly configured PeerTube (config/ directory), in particular the "webserver" section.' // We put a bigger timeout // This is an important message - this.notificationsService.error('Error', errorMessage, { timeOut: 7000 }); + this.notificationsService.error('Error', errorMessage, { timeOut: 7000 }) } - ); + ) // Return null if there is nothing to load - this.user = AuthUser.load(); + this.user = AuthUser.load() } - getRefreshToken() { - if (this.user === null) return null; + getRefreshToken () { + if (this.user === null) return null - return this.user.getRefreshToken(); + return this.user.getRefreshToken() } - getRequestHeaderValue() { - return `${this.getTokenType()} ${this.getAccessToken()}`; + getRequestHeaderValue () { + return `${this.getTokenType()} ${this.getAccessToken()}` } - getAccessToken() { - if (this.user === null) return null; + getAccessToken () { + if (this.user === null) return null - return this.user.getAccessToken(); + return this.user.getAccessToken() } - getTokenType() { - if (this.user === null) return null; + getTokenType () { + if (this.user === null) return null - return this.user.getTokenType(); + return this.user.getTokenType() } - getUser(): AuthUser { - return this.user; + getUser () { + return this.user } - isAdmin() { - if (this.user === null) return false; + isAdmin () { + if (this.user === null) return false - return this.user.isAdmin(); + return this.user.isAdmin() } - isLoggedIn() { + isLoggedIn () { if (this.getAccessToken()) { - return true; + return true } else { - return false; + 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); + 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 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; + res.username = username + return res }) .flatMap(res => this.mergeUserInformations(res)) .map(res => this.handleLogin(res)) - .catch((res) => this.restExtractor.handleError(res)); + .catch((res) => this.restExtractor.handleError(res)) } - logout() { + logout () { // TODO: make an HTTP request to revoke the tokens - this.user = null; + this.user = null - AuthUser.flush(); + AuthUser.flush() - this.setStatus(AuthStatus.LoggedOut); + this.setStatus(AuthStatus.LoggedOut) } - refreshAccessToken() { - console.log('Refreshing token...'); + refreshAccessToken () { + console.log('Refreshing token...') - const refreshToken = this.getRefreshToken(); + 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 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 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) @@ -164,41 +164,41 @@ export class AuthService { .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']); + 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); - }); + return this.restExtractor.handleError(res) + }) } - refreshUserInformations() { + refreshUserInformations () { const obj = { access_token: this.user.getAccessToken() - }; + } - this.mergeUserInformations(obj) + this.mergeUserInformations (obj) .subscribe( res => { - this.user.displayNSFW = res.displayNSFW; - this.user.role = res.role; + this.user.displayNSFW = res.displayNSFW + this.user.role = res.role - this.user.save(); + this.user.save() } - ); + ) } - private mergeUserInformations(obj: { access_token: string }) { + private mergeUserInformations (obj: { access_token: string }) { // Do not call authHttp here to avoid circular dependencies headaches - const headers = new Headers(); - headers.set('Authorization', `Bearer ${obj.access_token}`); + 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()) @@ -207,38 +207,38 @@ export class AuthService { id: res.id, role: res.role, displayNSFW: res.displayNSFW - }; + } - return Object.assign(obj, newProperties); + return Object.assign(obj, newProperties) } - ); + ) } private handleLogin (obj: any) { - const id = obj.id; - const username = obj.username; - const role = obj.role; - const email = obj.email; - const displayNSFW = obj.displayNSFW; + const id = obj.id + const username = obj.username + const role = obj.role + const email = obj.email + const displayNSFW = obj.displayNSFW const hashTokens = { - access_token: obj.access_token, - token_type: obj.token_type, - refresh_token: obj.refresh_token - }; + accessToken: obj.access_token, + tokenType: obj.token_type, + refreshToken: obj.refresh_token + } - this.user = new AuthUser({ id, username, role, displayNSFW, email }, hashTokens); - this.user.save(); + this.user = new AuthUser({ id, username, role, displayNSFW, email }, hashTokens) + this.user.save() - this.setStatus(AuthStatus.LoggedIn); + this.setStatus(AuthStatus.LoggedIn) } private handleRefreshToken (obj: any) { - this.user.refreshTokens(obj.access_token, obj.refresh_token); - this.user.save(); + this.user.refreshTokens(obj.access_token, obj.refresh_token) + this.user.save() } - private setStatus(status: AuthStatus) { - this.loginChanged.next(status); + private setStatus (status: AuthStatus) { + this.loginChanged.next(status) } } diff --git a/client/src/app/core/auth/index.ts b/client/src/app/core/auth/index.ts index 67a18cfbb..8e5caa7ed 100644 --- a/client/src/app/core/auth/index.ts +++ b/client/src/app/core/auth/index.ts @@ -1,3 +1,3 @@ -export * from './auth-status.model'; -export * from './auth-user.model'; +export * from './auth-status.model' +export * from './auth-user.model' export * from './auth.service' diff --git a/client/src/app/core/config/config.service.ts b/client/src/app/core/config/config.service.ts index 407dca083..a83ec61d2 100644 --- a/client/src/app/core/config/config.service.ts +++ b/client/src/app/core/config/config.service.ts @@ -1,11 +1,11 @@ -import { Injectable } from '@angular/core'; -import { Http } from '@angular/http'; +import { Injectable } from '@angular/core' +import { Http } from '@angular/http' -import { RestExtractor } from '../../shared/rest'; +import { RestExtractor } from '../../shared/rest' @Injectable() export class ConfigService { - private static BASE_CONFIG_URL = API_URL + '/api/v1/config/'; + private static BASE_CONFIG_URL = API_URL + '/api/v1/config/' private config: { signup: { @@ -15,22 +15,22 @@ export class ConfigService { signup: { enabled: false } - }; + } - constructor( + constructor ( private http: Http, - private restExtractor: RestExtractor, + private restExtractor: RestExtractor ) {} - loadConfig() { + loadConfig () { this.http.get(ConfigService.BASE_CONFIG_URL) .map(this.restExtractor.extractDataGet) .subscribe(data => { - this.config = data; - }); + this.config = data + }) } - getConfig() { - return this.config; + getConfig () { + return this.config } } diff --git a/client/src/app/core/config/index.ts b/client/src/app/core/config/index.ts index 90392254a..3724e12f2 100644 --- a/client/src/app/core/config/index.ts +++ b/client/src/app/core/config/index.ts @@ -1 +1 @@ -export * from './config.service'; +export * from './config.service' diff --git a/client/src/app/core/confirm/confirm.component.ts b/client/src/app/core/confirm/confirm.component.ts index ae42ff68a..066e3fc5f 100644 --- a/client/src/app/core/confirm/confirm.component.ts +++ b/client/src/app/core/confirm/confirm.component.ts @@ -1,12 +1,12 @@ -import { Component, HostListener, OnInit, ViewChild } from '@angular/core'; +import { Component, HostListener, OnInit, ViewChild } from '@angular/core' -import { ModalDirective } from 'ngx-bootstrap/modal'; +import { ModalDirective } from 'ngx-bootstrap/modal' -import { ConfirmService } from './confirm.service'; +import { ConfirmService } from './confirm.service' export interface ConfigChangedEvent { - columns: { [id: string]: { isDisplayed: boolean }; }; - config: { resultsPerPage: number }; + columns: { [id: string]: { isDisplayed: boolean } } + config: { resultsPerPage: number } } @Component({ @@ -14,48 +14,48 @@ export interface ConfigChangedEvent { templateUrl: './confirm.component.html' }) export class ConfirmComponent implements OnInit { - @ViewChild('confirmModal') confirmModal: ModalDirective; + @ViewChild('confirmModal') confirmModal: ModalDirective - title = ''; - message = ''; + title = '' + message = '' constructor (private confirmService: ConfirmService) { // Empty } - ngOnInit() { + ngOnInit () { this.confirmModal.config = { backdrop: 'static', keyboard: false - }; + } this.confirmService.showConfirm.subscribe( ({ title, message }) => { - this.title = title; - this.message = message; + this.title = title + this.message = message - this.showModal(); + this.showModal() } - ); + ) } @HostListener('keydown.enter') - confirm() { - this.confirmService.confirmResponse.next(true); - this.hideModal(); + confirm () { + this.confirmService.confirmResponse.next(true) + this.hideModal() } @HostListener('keydown.esc') - abort() { - this.confirmService.confirmResponse.next(false); - this.hideModal(); + abort () { + this.confirmService.confirmResponse.next(false) + this.hideModal() } - showModal() { - this.confirmModal.show(); + showModal () { + this.confirmModal.show() } - hideModal() { - this.confirmModal.hide(); + hideModal () { + this.confirmModal.hide() } } diff --git a/client/src/app/core/confirm/confirm.service.ts b/client/src/app/core/confirm/confirm.service.ts index 08127a66f..f12ff1848 100644 --- a/client/src/app/core/confirm/confirm.service.ts +++ b/client/src/app/core/confirm/confirm.service.ts @@ -1,15 +1,15 @@ -import { Injectable } from '@angular/core'; -import { Subject } from 'rxjs/Subject'; -import 'rxjs/add/operator/first'; +import { Injectable } from '@angular/core' +import { Subject } from 'rxjs/Subject' +import 'rxjs/add/operator/first' @Injectable() export class ConfirmService { - showConfirm = new Subject<{ title, message }>(); - confirmResponse = new Subject(); + showConfirm = new Subject<{ title, message }>() + confirmResponse = new Subject() - confirm(message = '', title = '') { - this.showConfirm.next({ title, message }); + confirm (message = '', title = '') { + this.showConfirm.next({ title, message }) - return this.confirmResponse.asObservable().first(); + return this.confirmResponse.asObservable().first() } } diff --git a/client/src/app/core/confirm/index.ts b/client/src/app/core/confirm/index.ts index 789e7e547..44aabfc13 100644 --- a/client/src/app/core/confirm/index.ts +++ b/client/src/app/core/confirm/index.ts @@ -1,2 +1,2 @@ -export * from './confirm.component'; -export * from './confirm.service'; +export * from './confirm.component' +export * from './confirm.service' diff --git a/client/src/app/core/core.module.ts b/client/src/app/core/core.module.ts index 81c8f2da6..382febe5c 100644 --- a/client/src/app/core/core.module.ts +++ b/client/src/app/core/core.module.ts @@ -1,16 +1,16 @@ -import { NgModule, Optional, SkipSelf } from '@angular/core'; -import { CommonModule } from '@angular/common'; -import { HttpModule } from '@angular/http'; -import { RouterModule } from '@angular/router'; +import { NgModule, Optional, SkipSelf } from '@angular/core' +import { CommonModule } from '@angular/common' +import { HttpModule } from '@angular/http' +import { RouterModule } from '@angular/router' -import { SimpleNotificationsModule } from 'angular2-notifications'; -import { ModalModule } from 'ngx-bootstrap/modal'; +import { SimpleNotificationsModule } from 'angular2-notifications' +import { ModalModule } from 'ngx-bootstrap/modal' -import { AuthService } from './auth'; -import { ConfigService } from './config'; -import { ConfirmComponent, ConfirmService } from './confirm'; -import { MenuComponent, MenuAdminComponent } from './menu'; -import { throwIfAlreadyLoaded } from './module-import-guard'; +import { AuthService } from './auth' +import { ConfigService } from './config' +import { ConfirmComponent, ConfirmService } from './confirm' +import { MenuComponent, MenuAdminComponent } from './menu' +import { throwIfAlreadyLoaded } from './module-import-guard' @NgModule({ imports: [ @@ -43,7 +43,7 @@ import { throwIfAlreadyLoaded } from './module-import-guard'; ] }) export class CoreModule { - constructor( @Optional() @SkipSelf() parentModule: CoreModule) { - throwIfAlreadyLoaded(parentModule, 'CoreModule'); + constructor ( @Optional() @SkipSelf() parentModule: CoreModule) { + throwIfAlreadyLoaded(parentModule, 'CoreModule') } } diff --git a/client/src/app/core/index.ts b/client/src/app/core/index.ts index 96b28658b..01b12ce7e 100644 --- a/client/src/app/core/index.ts +++ b/client/src/app/core/index.ts @@ -1,5 +1,5 @@ -export * from './auth'; -export * from './config'; -export * from './confirm'; -export * from './menu'; +export * from './auth' +export * from './config' +export * from './confirm' +export * from './menu' export * from './core.module' diff --git a/client/src/app/core/menu/index.ts b/client/src/app/core/menu/index.ts index ff40f26e1..c905ed20a 100644 --- a/client/src/app/core/menu/index.ts +++ b/client/src/app/core/menu/index.ts @@ -1,2 +1,2 @@ -export * from './menu.component'; -export * from './menu-admin.component'; +export * from './menu.component' +export * from './menu-admin.component' diff --git a/client/src/app/core/menu/menu-admin.component.ts b/client/src/app/core/menu/menu-admin.component.ts index 236161fce..f6cc6554c 100644 --- a/client/src/app/core/menu/menu-admin.component.ts +++ b/client/src/app/core/menu/menu-admin.component.ts @@ -1,4 +1,4 @@ -import { Component } from '@angular/core'; +import { Component } from '@angular/core' @Component({ selector: 'my-menu-admin', diff --git a/client/src/app/core/menu/menu.component.ts b/client/src/app/core/menu/menu.component.ts index 5ab8bf464..b725f64a7 100644 --- a/client/src/app/core/menu/menu.component.ts +++ b/client/src/app/core/menu/menu.component.ts @@ -1,8 +1,8 @@ -import { Component, OnInit } from '@angular/core'; -import { Router } from '@angular/router'; +import { Component, OnInit } from '@angular/core' +import { Router } from '@angular/router' -import { AuthService, AuthStatus } from '../auth'; -import { ConfigService } from '../config'; +import { AuthService, AuthStatus } from '../auth' +import { ConfigService } from '../config' @Component({ selector: 'my-menu', @@ -10,7 +10,7 @@ import { ConfigService } from '../config'; styleUrls: [ './menu.component.scss' ] }) export class MenuComponent implements OnInit { - isLoggedIn: boolean; + isLoggedIn: boolean constructor ( private authService: AuthService, @@ -18,35 +18,35 @@ export class MenuComponent implements OnInit { private router: Router ) {} - ngOnInit() { - this.isLoggedIn = this.authService.isLoggedIn(); + ngOnInit () { + this.isLoggedIn = this.authService.isLoggedIn() this.authService.loginChangedSource.subscribe( status => { if (status === AuthStatus.LoggedIn) { - this.isLoggedIn = true; - console.log('Logged in.'); + this.isLoggedIn = true + console.log('Logged in.') } else if (status === AuthStatus.LoggedOut) { - this.isLoggedIn = false; - console.log('Logged out.'); + this.isLoggedIn = false + console.log('Logged out.') } else { - console.error('Unknown auth status: ' + status); + console.error('Unknown auth status: ' + status) } } - ); + ) } - isRegistrationEnabled() { - return this.configService.getConfig().signup.enabled; + isRegistrationEnabled () { + return this.configService.getConfig().signup.enabled } - isUserAdmin() { - return this.authService.isAdmin(); + isUserAdmin () { + return this.authService.isAdmin() } - logout() { - this.authService.logout(); + logout () { + this.authService.logout() // Redirect to home page - this.router.navigate(['/videos/list']); + this.router.navigate(['/videos/list']) } } diff --git a/client/src/app/core/module-import-guard.ts b/client/src/app/core/module-import-guard.ts index 445640c4f..32b1d8f19 100644 --- a/client/src/app/core/module-import-guard.ts +++ b/client/src/app/core/module-import-guard.ts @@ -1,5 +1,5 @@ -export function throwIfAlreadyLoaded(parentModule: any, moduleName: string) { +export function throwIfAlreadyLoaded (parentModule: any, moduleName: string) { if (parentModule) { - throw new Error(`${moduleName} has already been loaded. Import Core modules in the AppModule only.`); + throw new Error(`${moduleName} has already been loaded. Import Core modules in the AppModule only.`) } } -- cgit v1.2.3