register
This commit is contained in:
parent
66fc33d44b
commit
9729d8a253
@ -31,8 +31,8 @@ export class LoginComponent implements OnInit {
|
|||||||
if (this.loginForm.valid) {
|
if (this.loginForm.valid) {
|
||||||
this.authService.Login(
|
this.authService.Login(
|
||||||
this.loginForm.get('username')!.value,
|
this.loginForm.get('username')!.value,
|
||||||
this.loginForm.get('password')!.value)
|
this.loginForm.get('password')!.value
|
||||||
.subscribe({
|
).subscribe({
|
||||||
next: result => {
|
next: result => {
|
||||||
if (result.error) {
|
if (result.error) {
|
||||||
this.toastrService.error(result.error, "Error", {
|
this.toastrService.error(result.error, "Error", {
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
<mat-card class="card">
|
<mat-card class="card">
|
||||||
|
|
||||||
<form>
|
<form [formGroup]="registerForm" (ngSubmit)="register()">
|
||||||
|
|
||||||
<mat-form-field>
|
<mat-form-field>
|
||||||
<mat-label>Username</mat-label>
|
<mat-label>Username</mat-label>
|
||||||
<input matInput required>
|
<input required matInput formControlName="username">
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
|
|
||||||
<mat-form-field>
|
<mat-form-field>
|
||||||
<mat-label>Password</mat-label>
|
<mat-label>Password</mat-label>
|
||||||
<input matInput required type="password">
|
<input required type="password" matInput formControlName="password">
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
|
|
||||||
<mat-form-field>
|
<mat-form-field>
|
||||||
<mat-label>Repeat Password</mat-label>
|
<mat-label>Repeat Password</mat-label>
|
||||||
<input matInput required type="password">
|
<input required type="password" matInput formControlName="repeatPassword">
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
|
|
||||||
<button mat-button>Register</button>
|
<button mat-button>Register</button>
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
import { AuthService } from '../../services/auth.service';
|
||||||
|
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
|
||||||
|
import { ToastrService } from 'ngx-toastr';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-register',
|
selector: 'app-register',
|
||||||
@ -7,5 +11,63 @@ import { Component } from '@angular/core';
|
|||||||
styleUrls: ['../auth.module.scss', './register.component.scss']
|
styleUrls: ['../auth.module.scss', './register.component.scss']
|
||||||
})
|
})
|
||||||
export class RegisterComponent {
|
export class RegisterComponent {
|
||||||
|
registerForm!: FormGroup;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private authService: AuthService,
|
||||||
|
private formBuilder: FormBuilder,
|
||||||
|
private toastrService: ToastrService,
|
||||||
|
private router: Router
|
||||||
|
) { }
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
this.registerForm = this.formBuilder.group({
|
||||||
|
username: new FormControl('', [
|
||||||
|
Validators.required,
|
||||||
|
Validators.minLength(3),
|
||||||
|
Validators.maxLength(32)
|
||||||
|
]),
|
||||||
|
password: new FormControl('', [
|
||||||
|
Validators.required,
|
||||||
|
Validators.minLength(6),
|
||||||
|
Validators.maxLength(32)
|
||||||
|
]),
|
||||||
|
repeatPassword: new FormControl('', [
|
||||||
|
Validators.required,
|
||||||
|
Validators.minLength(6),
|
||||||
|
Validators.maxLength(32),
|
||||||
|
])
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
register(): void {
|
||||||
|
if (this.registerForm.valid) {
|
||||||
|
this.authService.Register(
|
||||||
|
this.registerForm.get('username')!.value,
|
||||||
|
this.registerForm.get('password')!.value,
|
||||||
|
this.registerForm.get('repeatPassword')!.value
|
||||||
|
).subscribe({
|
||||||
|
next: result => {
|
||||||
|
if (result.error) {
|
||||||
|
this.toastrService.error(result.error, "Error", {
|
||||||
|
timeOut: 3000,
|
||||||
|
closeButton: true
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.toastrService.info(result.message, "Success", {
|
||||||
|
timeOut: 3000,
|
||||||
|
closeButton: true
|
||||||
|
});
|
||||||
|
this.router.navigateByUrl('/auth/login');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: _ => {
|
||||||
|
this.toastrService.error("API error", "Error", {
|
||||||
|
timeOut: 3000,
|
||||||
|
closeButton: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user