<ng-container *ngIf="type !== 'video'" i18n>You might need to login to see the resource.</ng-container>
</div>
- <a class="peertube-button-big-link orange-button mt-5" i18n routerLink="/login">
- Login
- </a>
-
+ <my-login-link className="peertube-button-big-link orange-button mt-5"></my-login-link>
</div>
<div *ngIf="status === 403" class="box">
import { CommonModule } from '@angular/common'
import { NgModule } from '@angular/core'
+import { SharedMainModule } from '@app/shared/shared-main'
import { ErrorPageRoutingModule } from './error-page-routing.module'
import { ErrorPageComponent } from './error-page.component'
@NgModule({
imports: [
CommonModule,
+ SharedMainModule,
ErrorPageRoutingModule
],
.subscribe({
next: () => {
this.notifier.success($localize`Your password has been successfully reset!`)
+
this.router.navigate([ '/login' ])
},
getRatePopoverText () {
if (this.isUserLoggedIn) return undefined
- return $localize`You need to be <a href="/login">logged in</a> to rate this video.`
+ return $localize`You need to be logged in to rate this video.`
}
private checkUserRating () {
(click)="hideModals()" (key.enter)="hideModals()"
>
- <input
- type="submit" i18n-value value="Login to comment" class="peertube-button orange-button"
- (click)="gotoLogin()"
- >
+ <my-login-link i18n-label label="Login to comment" className="peertube-button-link orange-button"></my-login-link>
</div>
</ng-template>
SimpleChanges,
ViewChild
} from '@angular/core'
-import { Router } from '@angular/router'
import { Notifier, User } from '@app/core'
import { VIDEO_COMMENT_TEXT_VALIDATOR } from '@app/shared/form-validators/video-comment-validators'
import { FormReactive, FormReactiveService } from '@app/shared/shared-forms'
private notifier: Notifier,
private videoCommentService: VideoCommentService,
private modalService: NgbModal,
- private router: Router,
@Inject(LOCALE_ID) private localeId: string
) {
super()
return window.location.href
}
- gotoLogin () {
- this.hideModals()
- this.router.navigate([ '/login' ])
- }
-
cancelCommentReply () {
this.cancel.emit(null)
this.form.value['text'] = this.textareaElement.nativeElement.value = ''
import { Injectable } from '@angular/core'
import { Router } from '@angular/router'
import { Notifier } from '@app/core/notification/notifier.service'
-import { logger, OAuthUserTokens, objectToUrlEncoded, peertubeLocalStorage, PluginsManager } from '@root-helpers/index'
+import { logger, OAuthUserTokens, objectToUrlEncoded, peertubeLocalStorage } from '@root-helpers/index'
import { HttpStatusCode, MyUser as UserServerModel, OAuthClientLocal, User, UserLogin, UserRefreshToken } from '@shared/models'
import { environment } from '../../../environments/environment'
import { RestExtractor } from '../rest/rest-extractor.service'
-import { ServerService } from '../server'
+import { RedirectService } from '../routing'
import { AuthStatus } from './auth-status.model'
import { AuthUser } from './auth-user.model'
private refreshingTokenObservable: Observable<any>
constructor (
- private serverService: ServerService,
+ private redirectService: RedirectService,
private http: HttpClient,
private notifier: Notifier,
private hotkeysService: HotkeysService,
logger.info('Cannot refresh token -> logout...')
this.logout()
- const externalLoginUrl = PluginsManager.getDefaultLoginHref(environment.apiUrl, this.serverService.getHTMLConfig())
- if (externalLoginUrl) window.location.href = externalLoginUrl
- else this.router.navigate([ '/login' ])
+ this.redirectService.redirectToLogin()
return observableThrowError(() => ({
error: $localize`You need to reconnect.`
import { Injectable } from '@angular/core'
-import { ActivatedRouteSnapshot, CanActivate, CanActivateChild, Router, RouterStateSnapshot } from '@angular/router'
+import { ActivatedRouteSnapshot, CanActivate, CanActivateChild, RouterStateSnapshot } from '@angular/router'
import { AuthService } from '../auth/auth.service'
+import { RedirectService } from './redirect.service'
@Injectable()
export class LoginGuard implements CanActivate, CanActivateChild {
constructor (
- private router: Router,
- private auth: AuthService
+ private auth: AuthService,
+ private redirectService: RedirectService
) {}
canActivate (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
if (this.auth.isLoggedIn() === true) return true
- this.router.navigate([ '/login' ])
+ this.redirectService.redirectToLogin()
return false
}
import { logger } from '@root-helpers/logger'
import { ServerService } from '../server'
import { SessionStorageService } from '../wrappers/storage.service'
+import { PluginsManager } from '@root-helpers/plugins-manager'
+import { environment } from 'src/environments/environment'
const debugLogger = debug('peertube:router:RedirectService')
}
+ redirectToLogin () {
+ const externalLoginUrl = PluginsManager.getDefaultLoginHref(environment.apiUrl, this.serverService.getHTMLConfig())
+
+ if (externalLoginUrl) window.location.href = externalLoginUrl
+ else this.router.navigate([ '/login' ])
+ }
+
private doRedirect (redirectUrl: string, fallbackRoute?: string) {
debugLogger('Redirecting on %s', redirectUrl)
import { Injectable } from '@angular/core'
-import { ActivatedRouteSnapshot, CanActivate, CanActivateChild, Router, RouterStateSnapshot } from '@angular/router'
+import { ActivatedRouteSnapshot, CanActivate, CanActivateChild, RouterStateSnapshot } from '@angular/router'
import { AuthService } from '../auth/auth.service'
+import { RedirectService } from './redirect.service'
@Injectable()
export class UserRightGuard implements CanActivate, CanActivateChild {
constructor (
- private router: Router,
+ private redirectService: RedirectService,
private auth: AuthService
) {}
if (user.hasRight(neededUserRight)) return true
}
- this.router.navigate([ '/login' ])
+ this.redirectService.redirectToLogin()
return false
}
</div>
<div *ngIf="!isLoggedIn" class="login-buttons-block">
- <a i18n *ngIf="!getExternalLoginHref()" routerLink="/login" class="peertube-button-link orange-button">Login</a>
- <a i18n *ngIf="getExternalLoginHref()" [href]="getExternalLoginHref()" class="peertube-button-link orange-button">Login</a>
+ <my-login-link className="peertube-button-link orange-button w-100"></my-login-link>
<a *ngIf="isRegistrationAllowed()" routerLink="/signup" class="peertube-button-link create-account-button">
<my-signup-label [requiresApproval]="requiresApproval"></my-signup-label>
.login-buttons-block {
margin: 30px 25px 35px;
- > a {
+ > a,
+ > my-login-link {
display: block;
width: 100%;
import { HotkeysService } from 'angular2-hotkeys'
import * as debug from 'debug'
import { switchMap } from 'rxjs/operators'
-import { environment } from 'src/environments/environment'
import { ViewportScroller } from '@angular/common'
import { Component, OnInit, ViewChild } from '@angular/core'
import { Router } from '@angular/router'
import { QuickSettingsModalComponent } from '@app/modal/quick-settings-modal.component'
import { PeertubeModalService } from '@app/shared/shared-main/peertube-modal/peertube-modal.service'
import { NgbDropdown } from '@ng-bootstrap/ng-bootstrap'
-import { PluginsManager } from '@root-helpers/plugins-manager'
import { HTMLServerConfig, ServerConfig, UserRight, VideoConstant } from '@shared/models'
const debugLogger = debug('peertube:menu:MenuComponent')
.subscribe(() => this.openQuickSettings())
}
- getExternalLoginHref () {
- return PluginsManager.getDefaultLoginHref(environment.apiUrl, this.serverConfig)
- }
-
isRegistrationAllowed () {
if (!this.serverConfig) return false
export * from './from-now.pipe'
export * from './infinite-scroller.directive'
export * from './link.component'
+export * from './login-link.component'
export * from './number-formatter.pipe'
export * from './peertube-template.directive'
<ng-content></ng-content>
</ng-template>
-<a *ngIf="!href" [routerLink]="internalLink" [attr.title]="title" [tabindex]="tabindex">
+<a *ngIf="!href" [routerLink]="internalLink" [attr.title]="title" [tabindex]="tabindex" [ngClass]="builtClasses">
<ng-template *ngTemplateOutlet="content"></ng-template>
</a>
-<a *ngIf="href" [href]="href" [target]="target" [attr.title]="title" [tabindex]="tabindex">
+<a *ngIf="href" [href]="href" [target]="target" [attr.title]="title" [tabindex]="tabindex" [ngClass]="builtClasses">
<ng-template *ngTemplateOutlet="content"></ng-template>
</a>
-a {
+.no-class {
color: inherit;
text-decoration: inherit;
position: inherit;
-import { Component, Input } from '@angular/core'
+import { Component, Input, OnInit } from '@angular/core'
@Component({
selector: 'my-link',
styleUrls: [ './link.component.scss' ],
templateUrl: './link.component.html'
})
-export class LinkComponent {
+export class LinkComponent implements OnInit {
@Input() internalLink?: string | any[]
@Input() href?: string
- @Input() target?: string
+ @Input() target = '_self'
@Input() title?: string
+ @Input() className?: string
+
@Input() tabindex: string | number
+
+ builtClasses: string
+
+ ngOnInit () {
+ this.builtClasses = this.className
+ ? this.className
+ : 'no-class'
+ }
}
--- /dev/null
+<my-link i18n internalLink="/login" [href]="getExternalLoginHref()" [className]="className">{{ label }}</my-link>
--- /dev/null
+import { environment } from 'src/environments/environment'
+import { Component, Input } from '@angular/core'
+import { ServerService } from '@app/core'
+import { PluginsManager } from '@root-helpers/plugins-manager'
+
+@Component({
+ selector: 'my-login-link',
+ templateUrl: './login-link.component.html'
+})
+export class LoginLinkComponent {
+ @Input() label = $localize`Login`
+
+ @Input() className?: string
+
+ constructor (private server: ServerService) {
+
+ }
+
+ getExternalLoginHref () {
+ return PluginsManager.getDefaultLoginHref(environment.apiUrl, this.server.getHTMLConfig())
+ }
+}
FromNowPipe,
InfiniteScrollerDirective,
LinkComponent,
+ LoginLinkComponent,
NumberFormatterPipe,
PeerTubeTemplateDirective
} from './angular'
InfiniteScrollerDirective,
PeerTubeTemplateDirective,
LinkComponent,
+ LoginLinkComponent,
ActionDropdownComponent,
ButtonComponent,
InfiniteScrollerDirective,
PeerTubeTemplateDirective,
LinkComponent,
+ LoginLinkComponent,
ActionDropdownComponent,
ButtonComponent,
import { concat, forkJoin, merge } from 'rxjs'
import { Component, Input, OnChanges, OnInit } from '@angular/core'
-import { Router } from '@angular/router'
-import { AuthService, Notifier } from '@app/core'
+import { AuthService, Notifier, RedirectService } from '@app/core'
import { Account, VideoChannel, VideoService } from '@app/shared/shared-main'
import { FeedFormat } from '@shared/models'
import { UserSubscriptionService } from './user-subscription.service'
constructor (
private authService: AuthService,
- private router: Router,
+ private redirectService: RedirectService,
private notifier: Notifier,
private userSubscriptionService: UserSubscriptionService,
private videoService: VideoService
}
gotoLogin () {
- this.router.navigate([ '/login' ])
+ this.redirectService.redirectToLogin()
}
subscribeStatus (subscribed: boolean) {