From 0bc53e20296de68288481e2375b297626087174b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 3 Dec 2021 17:04:47 +0100 Subject: Add ability to redirect users on external auth --- .../edit-basic-configuration.component.html | 32 +++++++++++++++++++++- .../edit-basic-configuration.component.ts | 4 +++ .../edit-custom-config.component.ts | 12 ++++++++ client/src/app/+login/login.component.ts | 5 ++-- client/src/app/menu/menu.component.html | 4 ++- client/src/app/menu/menu.component.ts | 10 +++++++ client/src/root-helpers/plugins-manager.ts | 6 ++++ 7 files changed, 69 insertions(+), 4 deletions(-) (limited to 'client') diff --git a/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.html b/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.html index 318c8e2c2..c9533208a 100644 --- a/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.html +++ b/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.html @@ -56,6 +56,36 @@ + + + + +
+ +
+
+
+ + + +
+ + + ⚠️ You don't have any external auth plugin enabled. + ⚠️ You have multiple external auth plugins enabled. + + +
+
+
+
+ @@ -276,7 +306,7 @@
VIDEO CHANNELS
- +
diff --git a/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.ts b/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.ts index 7a8258820..81457bd36 100644 --- a/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.ts +++ b/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.ts @@ -36,6 +36,10 @@ export class EditBasicConfigurationComponent implements OnInit, OnChanges { } } + countExternalAuth () { + return this.serverConfig.plugin.registeredExternalAuths.length + } + getVideoQuotaOptions () { return this.configService.videoQuotaOptions } diff --git a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts index fdb0a7532..f2eaa3033 100644 --- a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts +++ b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts @@ -106,6 +106,18 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit { whitelisted: null } }, + client: { + videos: { + miniature: { + preferAuthorDisplayName: null + } + }, + menu: { + login: { + redirectOnSingleExternalAuth: null + } + } + }, cache: { previews: { size: CACHE_PREVIEWS_SIZE_VALIDATOR diff --git a/client/src/app/+login/login.component.ts b/client/src/app/+login/login.component.ts index 1fa4bd3b5..648b8db36 100644 --- a/client/src/app/+login/login.component.ts +++ b/client/src/app/+login/login.component.ts @@ -1,4 +1,4 @@ -import { environment } from 'src/environments/environment' + import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core' import { ActivatedRoute } from '@angular/router' import { AuthService, Notifier, RedirectService, UserService } from '@app/core' @@ -7,6 +7,7 @@ import { LOGIN_PASSWORD_VALIDATOR, LOGIN_USERNAME_VALIDATOR } from '@app/shared/ import { FormReactive, FormValidatorService } from '@app/shared/shared-forms' import { InstanceAboutAccordionComponent } from '@app/shared/shared-instance' import { NgbAccordion, NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap' +import { PluginsManager } from '@root-helpers/plugins-manager' import { RegisteredExternalAuthConfig, ServerConfig } from '@shared/models' @Component({ @@ -98,7 +99,7 @@ export class LoginComponent extends FormReactive implements OnInit, AfterViewIni } getAuthHref (auth: RegisteredExternalAuthConfig) { - return environment.apiUrl + `/plugins/${auth.name}/${auth.version}/auth/${auth.authName}` + return PluginsManager.getExternalAuthHref(auth) } login () { diff --git a/client/src/app/menu/menu.component.html b/client/src/app/menu/menu.component.html index 55fc27b5f..9ea991042 100644 --- a/client/src/app/menu/menu.component.html +++ b/client/src/app/menu/menu.component.html @@ -99,7 +99,9 @@
diff --git a/client/src/app/menu/menu.component.ts b/client/src/app/menu/menu.component.ts index 97f07c956..bcc884878 100644 --- a/client/src/app/menu/menu.component.ts +++ b/client/src/app/menu/menu.component.ts @@ -21,6 +21,7 @@ import { LanguageChooserComponent } from '@app/menu/language-chooser.component' 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 logger = debug('peertube:menu:MenuComponent') @@ -129,6 +130,15 @@ export class MenuComponent implements OnInit { .subscribe(() => this.openQuickSettings()) } + getExternalLoginHref () { + if (this.serverConfig.client.menu.login.redirectOnSingleExternalAuth !== true) return undefined + + const externalAuths = this.serverConfig.plugin.registeredExternalAuths + if (externalAuths.length !== 1) return undefined + + return PluginsManager.getExternalAuthHref(externalAuths[0]) + } + isRegistrationAllowed () { if (!this.serverConfig) return false diff --git a/client/src/root-helpers/plugins-manager.ts b/client/src/root-helpers/plugins-manager.ts index a1b763ff2..9cba63373 100644 --- a/client/src/root-helpers/plugins-manager.ts +++ b/client/src/root-helpers/plugins-manager.ts @@ -15,6 +15,7 @@ import { RegisterClientHookOptions, RegisterClientSettingsScript, RegisterClientVideoFieldOptions, + RegisteredExternalAuthConfig, ServerConfigPlugin } from '../../../shared/models' import { environment } from '../environments/environment' @@ -78,6 +79,11 @@ class PluginsManager { return isTheme ? '/themes' : '/plugins' } + static getExternalAuthHref (auth: RegisteredExternalAuthConfig) { + return environment.apiUrl + `/plugins/${auth.name}/${auth.version}/auth/${auth.authName}` + + } + loadPluginsList (config: HTMLServerConfig) { for (const plugin of config.plugin.registered) { this.addPlugin(plugin) -- cgit v1.2.3