frontend-smartfarming/agrilink_vocpro/src/app/pages/register/register.component.ts

45 lines
1.3 KiB
TypeScript

import { Component } from '@angular/core';
import { Router, RouterModule } from '@angular/router';
import { AuthService } from '../../cores/services/auth.service';
import { FormsModule } from '@angular/forms';
import { RegistrationData } from '../../cores/interface/auth';
import { ToastrService } from 'ngx-toastr';
import { CommonModule } from '@angular/common';
@Component({
selector: 'app-register',
standalone: true,
imports: [FormsModule, RouterModule, CommonModule],
templateUrl: './register.component.html',
styleUrls: ['./register.component.scss']
})
export class RegisterComponent {
username: string = '';
password: string = '';
email: string = '';
fullname: string = '';
constructor(private authService: AuthService, private router: Router, private toast: ToastrService) {}
onSubmit() {
const registrationData: RegistrationData = {
username: this.username,
pwd: this.password,
email: this.email,
google_id: '1',
fullname: this.fullname,
avatar: ''
};
this.authService.register(registrationData).subscribe(
(response) => {
this.toast.success('Registration successful');
this.router.navigate(['/auth']);
},
(error) => {
this.toast.error(error.error.message);
}
);
}
}