diff options
author | Chocobozzz <me@florianbigard.com> | 2023-02-14 11:47:01 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-02-14 11:51:44 +0100 |
commit | 98bd5e2256bfdeba6d5ab07f0421acfde1a0de26 (patch) | |
tree | a1193f1af10f0da7a532d4aa6d5045e51c3d16a9 /client/src/app/shared | |
parent | 4ea827076df39935375d66fffb5e1e27e667111e (diff) | |
download | PeerTube-98bd5e2256bfdeba6d5ab07f0421acfde1a0de26.tar.gz PeerTube-98bd5e2256bfdeba6d5ab07f0421acfde1a0de26.tar.zst PeerTube-98bd5e2256bfdeba6d5ab07f0421acfde1a0de26.zip |
Refactor login redirection/button links
Correctly handle external auth redirection in all cases
Diffstat (limited to 'client/src/app/shared')
8 files changed, 46 insertions, 10 deletions
diff --git a/client/src/app/shared/shared-main/angular/index.ts b/client/src/app/shared/shared-main/angular/index.ts index 4b87c2952..f72d60313 100644 --- a/client/src/app/shared/shared-main/angular/index.ts +++ b/client/src/app/shared/shared-main/angular/index.ts | |||
@@ -5,5 +5,6 @@ export * from './duration-formatter.pipe' | |||
5 | export * from './from-now.pipe' | 5 | export * from './from-now.pipe' |
6 | export * from './infinite-scroller.directive' | 6 | export * from './infinite-scroller.directive' |
7 | export * from './link.component' | 7 | export * from './link.component' |
8 | export * from './login-link.component' | ||
8 | export * from './number-formatter.pipe' | 9 | export * from './number-formatter.pipe' |
9 | export * from './peertube-template.directive' | 10 | export * from './peertube-template.directive' |
diff --git a/client/src/app/shared/shared-main/angular/link.component.html b/client/src/app/shared/shared-main/angular/link.component.html index e61a1e085..2ea2df2b5 100644 --- a/client/src/app/shared/shared-main/angular/link.component.html +++ b/client/src/app/shared/shared-main/angular/link.component.html | |||
@@ -2,10 +2,10 @@ | |||
2 | <ng-content></ng-content> | 2 | <ng-content></ng-content> |
3 | </ng-template> | 3 | </ng-template> |
4 | 4 | ||
5 | <a *ngIf="!href" [routerLink]="internalLink" [attr.title]="title" [tabindex]="tabindex"> | 5 | <a *ngIf="!href" [routerLink]="internalLink" [attr.title]="title" [tabindex]="tabindex" [ngClass]="builtClasses"> |
6 | <ng-template *ngTemplateOutlet="content"></ng-template> | 6 | <ng-template *ngTemplateOutlet="content"></ng-template> |
7 | </a> | 7 | </a> |
8 | 8 | ||
9 | <a *ngIf="href" [href]="href" [target]="target" [attr.title]="title" [tabindex]="tabindex"> | 9 | <a *ngIf="href" [href]="href" [target]="target" [attr.title]="title" [tabindex]="tabindex" [ngClass]="builtClasses"> |
10 | <ng-template *ngTemplateOutlet="content"></ng-template> | 10 | <ng-template *ngTemplateOutlet="content"></ng-template> |
11 | </a> | 11 | </a> |
diff --git a/client/src/app/shared/shared-main/angular/link.component.scss b/client/src/app/shared/shared-main/angular/link.component.scss index bb86d5488..f54240d31 100644 --- a/client/src/app/shared/shared-main/angular/link.component.scss +++ b/client/src/app/shared/shared-main/angular/link.component.scss | |||
@@ -1,4 +1,4 @@ | |||
1 | a { | 1 | .no-class { |
2 | color: inherit; | 2 | color: inherit; |
3 | text-decoration: inherit; | 3 | text-decoration: inherit; |
4 | position: inherit; | 4 | position: inherit; |
diff --git a/client/src/app/shared/shared-main/angular/link.component.ts b/client/src/app/shared/shared-main/angular/link.component.ts index ecbd9151c..1f5975589 100644 --- a/client/src/app/shared/shared-main/angular/link.component.ts +++ b/client/src/app/shared/shared-main/angular/link.component.ts | |||
@@ -1,17 +1,27 @@ | |||
1 | import { Component, Input } from '@angular/core' | 1 | import { Component, Input, OnInit } from '@angular/core' |
2 | 2 | ||
3 | @Component({ | 3 | @Component({ |
4 | selector: 'my-link', | 4 | selector: 'my-link', |
5 | styleUrls: [ './link.component.scss' ], | 5 | styleUrls: [ './link.component.scss' ], |
6 | templateUrl: './link.component.html' | 6 | templateUrl: './link.component.html' |
7 | }) | 7 | }) |
8 | export class LinkComponent { | 8 | export class LinkComponent implements OnInit { |
9 | @Input() internalLink?: string | any[] | 9 | @Input() internalLink?: string | any[] |
10 | 10 | ||
11 | @Input() href?: string | 11 | @Input() href?: string |
12 | @Input() target?: string | 12 | @Input() target = '_self' |
13 | 13 | ||
14 | @Input() title?: string | 14 | @Input() title?: string |
15 | 15 | ||
16 | @Input() className?: string | ||
17 | |||
16 | @Input() tabindex: string | number | 18 | @Input() tabindex: string | number |
19 | |||
20 | builtClasses: string | ||
21 | |||
22 | ngOnInit () { | ||
23 | this.builtClasses = this.className | ||
24 | ? this.className | ||
25 | : 'no-class' | ||
26 | } | ||
17 | } | 27 | } |
diff --git a/client/src/app/shared/shared-main/angular/login-link.component.html b/client/src/app/shared/shared-main/angular/login-link.component.html new file mode 100644 index 000000000..f90ffba68 --- /dev/null +++ b/client/src/app/shared/shared-main/angular/login-link.component.html | |||
@@ -0,0 +1 @@ | |||
<my-link i18n internalLink="/login" [href]="getExternalLoginHref()" [className]="className">{{ label }}</my-link> | |||
diff --git a/client/src/app/shared/shared-main/angular/login-link.component.ts b/client/src/app/shared/shared-main/angular/login-link.component.ts new file mode 100644 index 000000000..7e3a773c2 --- /dev/null +++ b/client/src/app/shared/shared-main/angular/login-link.component.ts | |||
@@ -0,0 +1,22 @@ | |||
1 | import { environment } from 'src/environments/environment' | ||
2 | import { Component, Input } from '@angular/core' | ||
3 | import { ServerService } from '@app/core' | ||
4 | import { PluginsManager } from '@root-helpers/plugins-manager' | ||
5 | |||
6 | @Component({ | ||
7 | selector: 'my-login-link', | ||
8 | templateUrl: './login-link.component.html' | ||
9 | }) | ||
10 | export class LoginLinkComponent { | ||
11 | @Input() label = $localize`Login` | ||
12 | |||
13 | @Input() className?: string | ||
14 | |||
15 | constructor (private server: ServerService) { | ||
16 | |||
17 | } | ||
18 | |||
19 | getExternalLoginHref () { | ||
20 | return PluginsManager.getDefaultLoginHref(environment.apiUrl, this.server.getHTMLConfig()) | ||
21 | } | ||
22 | } | ||
diff --git a/client/src/app/shared/shared-main/shared-main.module.ts b/client/src/app/shared/shared-main/shared-main.module.ts index eb1642d97..0bdf27263 100644 --- a/client/src/app/shared/shared-main/shared-main.module.ts +++ b/client/src/app/shared/shared-main/shared-main.module.ts | |||
@@ -25,6 +25,7 @@ import { | |||
25 | FromNowPipe, | 25 | FromNowPipe, |
26 | InfiniteScrollerDirective, | 26 | InfiniteScrollerDirective, |
27 | LinkComponent, | 27 | LinkComponent, |
28 | LoginLinkComponent, | ||
28 | NumberFormatterPipe, | 29 | NumberFormatterPipe, |
29 | PeerTubeTemplateDirective | 30 | PeerTubeTemplateDirective |
30 | } from './angular' | 31 | } from './angular' |
@@ -92,6 +93,7 @@ import { VideoChannelService } from './video-channel' | |||
92 | InfiniteScrollerDirective, | 93 | InfiniteScrollerDirective, |
93 | PeerTubeTemplateDirective, | 94 | PeerTubeTemplateDirective, |
94 | LinkComponent, | 95 | LinkComponent, |
96 | LoginLinkComponent, | ||
95 | 97 | ||
96 | ActionDropdownComponent, | 98 | ActionDropdownComponent, |
97 | ButtonComponent, | 99 | ButtonComponent, |
@@ -152,6 +154,7 @@ import { VideoChannelService } from './video-channel' | |||
152 | InfiniteScrollerDirective, | 154 | InfiniteScrollerDirective, |
153 | PeerTubeTemplateDirective, | 155 | PeerTubeTemplateDirective, |
154 | LinkComponent, | 156 | LinkComponent, |
157 | LoginLinkComponent, | ||
155 | 158 | ||
156 | ActionDropdownComponent, | 159 | ActionDropdownComponent, |
157 | ButtonComponent, | 160 | ButtonComponent, |
diff --git a/client/src/app/shared/shared-user-subscription/subscribe-button.component.ts b/client/src/app/shared/shared-user-subscription/subscribe-button.component.ts index 7a55a6ffb..a002bf4e7 100644 --- a/client/src/app/shared/shared-user-subscription/subscribe-button.component.ts +++ b/client/src/app/shared/shared-user-subscription/subscribe-button.component.ts | |||
@@ -1,7 +1,6 @@ | |||
1 | import { concat, forkJoin, merge } from 'rxjs' | 1 | import { concat, forkJoin, merge } from 'rxjs' |
2 | import { Component, Input, OnChanges, OnInit } from '@angular/core' | 2 | import { Component, Input, OnChanges, OnInit } from '@angular/core' |
3 | import { Router } from '@angular/router' | 3 | import { AuthService, Notifier, RedirectService } from '@app/core' |
4 | import { AuthService, Notifier } from '@app/core' | ||
5 | import { Account, VideoChannel, VideoService } from '@app/shared/shared-main' | 4 | import { Account, VideoChannel, VideoService } from '@app/shared/shared-main' |
6 | import { FeedFormat } from '@shared/models' | 5 | import { FeedFormat } from '@shared/models' |
7 | import { UserSubscriptionService } from './user-subscription.service' | 6 | import { UserSubscriptionService } from './user-subscription.service' |
@@ -27,7 +26,7 @@ export class SubscribeButtonComponent implements OnInit, OnChanges { | |||
27 | 26 | ||
28 | constructor ( | 27 | constructor ( |
29 | private authService: AuthService, | 28 | private authService: AuthService, |
30 | private router: Router, | 29 | private redirectService: RedirectService, |
31 | private notifier: Notifier, | 30 | private notifier: Notifier, |
32 | private userSubscriptionService: UserSubscriptionService, | 31 | private userSubscriptionService: UserSubscriptionService, |
33 | private videoService: VideoService | 32 | private videoService: VideoService |
@@ -152,7 +151,7 @@ export class SubscribeButtonComponent implements OnInit, OnChanges { | |||
152 | } | 151 | } |
153 | 152 | ||
154 | gotoLogin () { | 153 | gotoLogin () { |
155 | this.router.navigate([ '/login' ]) | 154 | this.redirectService.redirectToLogin() |
156 | } | 155 | } |
157 | 156 | ||
158 | subscribeStatus (subscribed: boolean) { | 157 | subscribeStatus (subscribed: boolean) { |