Add "agree to the terms" checkbox in registration form

pull/850/head
Chocobozzz 2018-07-25 11:01:53 +02:00
parent b2c60abe6e
commit b4a929accf
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
9 changed files with 31 additions and 6 deletions

View File

@ -12,7 +12,7 @@
<div [innerHTML]="descriptionHTML"></div>
</div>
<div class="terms">
<div class="terms" id="terms-section">
<div i18n class="section-title">Terms</div>
<div [innerHTML]="termsHTML"></div>

View File

@ -23,7 +23,7 @@ export abstract class FormReactive {
this.formErrors = formErrors
this.validationMessages = validationMessages
this.form.valueChanges.subscribe(data => this.onValueChanged(false))
this.form.valueChanges.subscribe(() => this.onValueChanged(false))
}
protected onValueChanged (forceCheck = false) {

View File

@ -1,7 +1,6 @@
import { FormBuilder, FormControl, FormGroup, ValidatorFn } from '@angular/forms'
import { Injectable } from '@angular/core'
import { FormReactiveErrors, FormReactiveValidationMessages } from '@app/shared/forms/form-reactive'
import { I18n } from '@ngx-translate/i18n-polyfill'
export type BuildFormValidator = {
VALIDATORS: ValidatorFn[],
@ -18,8 +17,7 @@ export type BuildFormDefaultValues = {
export class FormValidatorService {
constructor (
private formBuilder: FormBuilder,
private i18n: I18n
private formBuilder: FormBuilder
) {}
buildForm (obj: BuildFormArgument, defaultValues: BuildFormDefaultValues = {}) {

View File

@ -12,6 +12,7 @@ export class UserValidatorsService {
readonly USER_ROLE: BuildFormValidator
readonly USER_DISPLAY_NAME: BuildFormValidator
readonly USER_DESCRIPTION: BuildFormValidator
readonly USER_TERMS: BuildFormValidator
constructor (private i18n: I18n) {
@ -89,5 +90,14 @@ export class UserValidatorsService {
'maxlength': this.i18n('Description cannot be more than 250 characters long.')
}
}
this.USER_TERMS = {
VALIDATORS: [
Validators.requiredTrue
],
MESSAGES: {
'required': this.i18n('You must to agree with the instance terms in order to registering on it.')
}
}
}
}

View File

@ -3,6 +3,7 @@
<input type="checkbox" [(ngModel)]="checked" (ngModelChange)="onModelChange()" [id]="inputName" [disabled]="isDisabled" />
<span role="checkbox" [attr.aria-checked]="checked"></span>
<span *ngIf="labelText">{{ labelText }}</span>
<span *ngIf="labelHtml" [innerHTML]="labelHtml"></span>
</label>
<my-help *ngIf="helpHtml" tooltipPlacement="top" helpType="custom" i18n-customHtml [customHtml]="helpHtml"></my-help>

View File

@ -17,6 +17,7 @@ export class PeertubeCheckboxComponent implements ControlValueAccessor {
@Input() checked = false
@Input() inputName: string
@Input() labelText: string
@Input() labelHtml: string
@Input() helpHtml: string
isDisabled = false

View File

@ -54,6 +54,17 @@
</div>
</div>
<div class="form-group form-group-terms">
<my-peertube-checkbox
inputName="terms" formControlName="terms"
i18n-labelHtml labelHtml="I have read and agree to the <a href='/about/instance#terms-section' target='_blank'rel='noopener noreferrer'>Terms</a> of this instance"
></my-peertube-checkbox>
<div *ngIf="formErrors.terms" class="form-error">
{{ formErrors.terms }}
</div>
</div>
<input type="submit" i18n-value value="Signup" [disabled]="!form.valid">
</form>

View File

@ -10,6 +10,9 @@
}
}
.form-group-terms {
margin: 30px 0;
}
input:not([type=submit]) {
@include peertube-input-text(340px);

View File

@ -38,7 +38,8 @@ export class SignupComponent extends FormReactive implements OnInit {
this.buildForm({
username: this.userValidatorsService.USER_USERNAME,
password: this.userValidatorsService.USER_PASSWORD,
email: this.userValidatorsService.USER_EMAIL
email: this.userValidatorsService.USER_EMAIL,
terms: this.userValidatorsService.USER_TERMS
})
this.serverService.configLoaded