if (this.authService.isLoggedIn()) {
// The service will automatically redirect to the login page if the token is not valid anymore
- this.userService.checkTokenValidity()
+ this.authService.refreshUserInformation()
}
// Load custom data from server
// Do not use the barrel (dependency loop)
import { UserRole } from '../../../../../shared/models/users/user-role.type'
-import { User } from '../../shared/users/user.model'
+import { User, UserConstructorHash } from '../../shared/users/user.model'
export type TokenOptions = {
accessToken: string
Tokens.flush()
}
- constructor (userHash: {
- id: number,
- username: string,
- role: UserRole,
- email: string,
- displayNSFW: boolean
- }, hashTokens: TokenOptions) {
+ constructor (userHash: UserConstructorHash, hashTokens: TokenOptions) {
super(userHash)
this.tokens = new Tokens(hashTokens)
}
import { AuthStatus } from './auth-status.model'
import { AuthUser } from './auth-user.model'
-import { OAuthClientLocal, UserRole, UserRefreshToken } from '../../../../../shared'
+import {
+ OAuthClientLocal,
+ UserRole,
+ UserRefreshToken,
+ VideoChannel,
+ User as UserServerModel
+} from '../../../../../shared'
// Do not use the barrel (dependency loop)
import { RestExtractor } from '../../shared/rest'
import { UserLogin } from '../../../../../shared/models/users/user-login.model'
-import { User } from '../../shared/users/user.model'
+import { User, UserConstructorHash } from '../../shared/users/user.model'
interface UserLoginWithUsername extends UserLogin {
access_token: string
role: UserRole
displayNSFW: boolean
email: string
+ videoQuota: number
+ author: {
+ id: number
+ uuid: string
+ }
+ videoChannels: VideoChannel[]
}
@Injectable()
res => {
this.user.displayNSFW = res.displayNSFW
this.user.role = res.role
+ this.user.videoChannels = res.videoChannels
+ this.user.author = res.author
this.user.save()
}
// User is not loaded yet, set manually auth header
const headers = new HttpHeaders().set('Authorization', `${obj.token_type} ${obj.access_token}`)
- return this.http.get<User>(AuthService.BASE_USER_INFORMATION_URL, { headers })
+ return this.http.get<UserServerModel>(AuthService.BASE_USER_INFORMATION_URL, { headers })
.map(res => {
const newProperties = {
- id: res.id as number,
- role: res.role as UserRole,
- displayNSFW: res.displayNSFW as boolean,
- email: res.email as string
+ id: res.id,
+ role: res.role,
+ displayNSFW: res.displayNSFW,
+ email: res.email,
+ videoQuota: res.videoQuota,
+ author: res.author,
+ videoChannels: res.videoChannels
}
return Object.assign(obj, newProperties)
}
private handleLogin (obj: UserLoginWithUserInformation) {
- const id = obj.id
- const username = obj.username
- const role = obj.role
- const email = obj.email
- const displayNSFW = obj.displayNSFW
+ const hashUser: UserConstructorHash = {
+ id: obj.id,
+ username: obj.username,
+ role: obj.role,
+ email: obj.email,
+ displayNSFW: obj.displayNSFW,
+ videoQuota: obj.videoQuota,
+ videoChannels: obj.videoChannels,
+ author: obj.author
+ }
const hashTokens = {
accessToken: obj.access_token,
tokenType: obj.token_type,
refreshToken: obj.refresh_token
}
- this.user = new AuthUser({ id, username, role, displayNSFW, email }, hashTokens)
+ this.user = new AuthUser(hashUser, hashTokens)
this.user.save()
this.setStatus(AuthStatus.LoggedIn)
MESSAGES: {}
}
+export const VIDEO_CHANNEL = {
+ VALIDATORS: [ Validators.required ],
+ MESSAGES: {
+ 'required': 'Video channel is required.'
+ }
+}
+
export const VIDEO_DESCRIPTION = {
VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(250) ],
MESSAGES: {
private restExtractor: RestExtractor
) {}
- checkTokenValidity () {
- const url = UserService.BASE_USERS_URL + 'me'
-
- // AuthHttp will redirect us to the login page if the token is not valid anymore
- this.authHttp.get(url).subscribe()
- }
-
changePassword (newPassword: string) {
const url = UserService.BASE_USERS_URL + 'me'
const body: UserUpdateMe = {
>
</div>
+ <div class="form-group">
+ <label for="category">Channel</label>
+ <select class="form-control" id="channelId" formControlName="channelId">
+ <option></option>
+ <option *ngFor="let channel of userVideoChannels" [value]="channel.id">{{ channel.label }}</option>
+ </select>
+
+ <div *ngIf="formErrors.channelId" class="alert alert-danger">
+ {{ formErrors.channelId }}
+ </div>
+ </div>
+
<div class="form-group">
<label for="category">Category</label>
<select class="form-control" id="category" formControlName="category">
VIDEO_LANGUAGE,
VIDEO_DESCRIPTION,
VIDEO_TAGS,
+ VIDEO_CHANNEL,
VIDEO_FILE
} from '../../shared'
-import { ServerService } from '../../core'
+import { AuthService, ServerService } from '../../core'
import { VideoService } from '../shared'
import { VideoCreate } from '../../../../../shared'
import { HttpEventType, HttpResponse } from '@angular/common/http'
videoCategories = []
videoLicences = []
videoLanguages = []
+ userVideoChannels = []
tagValidators = VIDEO_TAGS.VALIDATORS
tagValidatorsMessages = VIDEO_TAGS.MESSAGES
category: '',
licence: '',
language: '',
+ channelId: '',
description: '',
videofile: ''
}
category: VIDEO_CATEGORY.MESSAGES,
licence: VIDEO_LICENCE.MESSAGES,
language: VIDEO_LANGUAGE.MESSAGES,
+ channelId: VIDEO_CHANNEL.MESSAGES,
description: VIDEO_DESCRIPTION.MESSAGES,
videofile: VIDEO_FILE.MESSAGES
}
private formBuilder: FormBuilder,
private router: Router,
private notificationsService: NotificationsService,
+ private authService: AuthService,
private serverService: ServerService,
private videoService: VideoService
) {
category: [ '', VIDEO_CATEGORY.VALIDATORS ],
licence: [ '', VIDEO_LICENCE.VALIDATORS ],
language: [ '', VIDEO_LANGUAGE.VALIDATORS ],
+ channelId: [ this.userVideoChannels[0].id, VIDEO_CHANNEL.VALIDATORS ],
description: [ '', VIDEO_DESCRIPTION.VALIDATORS ],
videofile: [ '', VIDEO_FILE.VALIDATORS ],
tags: [ '' ]
this.videoLicences = this.serverService.getVideoLicences()
this.videoLanguages = this.serverService.getVideoLanguages()
+ const user = this.authService.getUser()
+ this.userVideoChannels = user.videoChannels.map(v => ({ id: v.id, label: v.name }))
+
this.buildForm()
}
const category = formValue.category
const licence = formValue.licence
const language = formValue.language
+ const channelId = formValue.channelId
const description = formValue.description
const tags = formValue.tags
const videofile = this.videofileInput.nativeElement.files[0]
formData.append('category', '' + category)
formData.append('nsfw', '' + nsfw)
formData.append('licence', '' + licence)
+ formData.append('channelId', '' + channelId)
formData.append('videofile', videofile)
// Language is optional
-import { ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core'
+import { Component, OnDestroy, OnInit } from '@angular/core'
import { ActivatedRoute, Router } from '@angular/router'
import { Subscription } from 'rxjs/Subscription'
import { BehaviorSubject } from 'rxjs/BehaviorSubject'
VideoService,
VideoPagination
} from '../shared'
-import { AuthService, AuthUser } from '../../core'
import { Search, SearchField, SearchService } from '../../shared'
@Component({
totalItems: null
}
sort: SortField
- user: AuthUser = null
videos: Video[] = []
private search: Search
constructor (
private notificationsService: NotificationsService,
- private authService: AuthService,
- private changeDetector: ChangeDetectorRef,
private router: Router,
private route: ActivatedRoute,
private videoService: VideoService,
) {}
ngOnInit () {
- if (this.authService.isLoggedIn()) {
- this.user = AuthUser.load()
- }
-
// Subscribe to route changes
this.subActivatedRoute = this.route.params.subscribe(routeParams => {
this.loadRouteParams(routeParams)
// Pod 4 is friend with : 2 3
// Pod 6 is friend with : 2 3
it('Should make friends between pod 1, 2, 3 and 6 and exchange their videos', async function () {
- this.timeout(20000)
+ this.timeout(30000)
await makeFriendsWrapper(1)
- await wait(11000)
+ await wait(22000)
const res = await getVideosWrapper(1)
const videos = res.body.data