From 1f256e7d3cf056c2d999260155cdba58ae1b878b Mon Sep 17 00:00:00 2001 From: Poslovitch Date: Sat, 24 Apr 2021 09:57:01 +0000 Subject: Implemented configurable minimum signup age Implements https://github.com/Chocobozzz/PeerTube/issues/3612 Fixed lint and removed debug Fixed another lint error Apply suggestions from code review Co-authored-by: Chocobozzz Add tests for min signup age config --- .../edit-basic-configuration.component.html | 16 +++++++++++++++- .../edit-basic-configuration.component.ts | 1 - .../edit-custom-config/edit-custom-config.component.ts | 4 +++- .../+signup/+register/register-step-terms.component.html | 4 ++-- .../+signup/+register/register-step-terms.component.ts | 1 + client/src/app/+signup/+register/register.component.html | 1 + client/src/app/+signup/+register/register.component.ts | 4 ++++ client/src/app/core/server/server.service.ts | 3 ++- .../shared/form-validators/custom-config-validators.ts | 9 +++++++++ 9 files changed, 37 insertions(+), 6 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 03997ea40..1f542e458 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 @@ -158,6 +158,20 @@ Signup won't be limited to a fixed number of users. + +
+ + +
+ + {form.value['signup']['minimumAge'], plural, =1 {year old} other {years old}} +
+ +
{{ formErrors.signup.minimumAge }}
+
@@ -469,7 +483,7 @@
- + - - I am at least 16 years old and agree + + I am at least {{ minimumAge }} years old and agree to the Terms and to the Code of Conduct of this instance diff --git a/client/src/app/+signup/+register/register-step-terms.component.ts b/client/src/app/+signup/+register/register-step-terms.component.ts index db834c68d..20c1ae1c4 100644 --- a/client/src/app/+signup/+register/register-step-terms.component.ts +++ b/client/src/app/+signup/+register/register-step-terms.component.ts @@ -12,6 +12,7 @@ import { FormReactive, FormValidatorService } from '@app/shared/shared-forms' }) export class RegisterStepTermsComponent extends FormReactive implements OnInit { @Input() hasCodeOfConduct = false + @Input() minimumAge = 16 @Output() formBuilt = new EventEmitter() @Output() termsClick = new EventEmitter() diff --git a/client/src/app/+signup/+register/register.component.html b/client/src/app/+signup/+register/register.component.html index dc1c7496f..de72065d3 100644 --- a/client/src/app/+signup/+register/register.component.html +++ b/client/src/app/+signup/+register/register.component.html @@ -17,6 +17,7 @@ diff --git a/client/src/app/+signup/+register/register.component.ts b/client/src/app/+signup/+register/register.component.ts index 8e89bb01a..241ca04c6 100644 --- a/client/src/app/+signup/+register/register.component.ts +++ b/client/src/app/+signup/+register/register.component.ts @@ -56,6 +56,10 @@ export class RegisterComponent implements OnInit { return this.serverConfig.signup.requiresEmailVerification } + get minimumAge () { + return this.serverConfig.signup.minimumAge + } + ngOnInit (): void { this.serverConfig = this.route.snapshot.data.serverConfig diff --git a/client/src/app/core/server/server.service.ts b/client/src/app/core/server/server.service.ts index 5b1b7603f..6918957f4 100644 --- a/client/src/app/core/server/server.service.ts +++ b/client/src/app/core/server/server.service.ts @@ -60,7 +60,8 @@ export class ServerService { signup: { allowed: false, allowedForCurrentIP: false, - requiresEmailVerification: false + requiresEmailVerification: false, + minimumAge: 16 }, transcoding: { profile: 'default', diff --git a/client/src/app/shared/form-validators/custom-config-validators.ts b/client/src/app/shared/form-validators/custom-config-validators.ts index ef6e9b456..1ed5700ff 100644 --- a/client/src/app/shared/form-validators/custom-config-validators.ts +++ b/client/src/app/shared/form-validators/custom-config-validators.ts @@ -49,6 +49,15 @@ export const SIGNUP_LIMIT_VALIDATOR: BuildFormValidator = { } } +export const SIGNUP_MINIMUM_AGE_VALIDATOR: BuildFormValidator = { + VALIDATORS: [Validators.required, Validators.min(1), Validators.pattern('[0-9]+')], + MESSAGES: { + 'required': $localize`Signup minimum age is required.`, + 'min': $localize`Signup minimum age must be greater than 1.`, + 'pattern': $localize`Signup minimum age must be a number.` + } +} + export const ADMIN_EMAIL_VALIDATOR: BuildFormValidator = { VALIDATORS: [Validators.required, Validators.email], MESSAGES: { -- cgit v1.2.3