40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
import { Component, OnInit } from '@angular/core';
|
|
import { Router } from '@angular/router';
|
|
import { FormGroup, FormControl, Validators } from '@angular/forms';
|
|
import { MatSnackBar } from '@angular/material/snack-bar';
|
|
import { Rayconnect } from '../../../services/rayconnect/rayconnect.service';
|
|
|
|
@Component({
|
|
selector: 'app-app',
|
|
templateUrl: './app.component.html',
|
|
styleUrls: ['./app.component.scss']
|
|
})
|
|
export class AppComponent implements OnInit {
|
|
|
|
public form: FormGroup = new FormGroup({
|
|
username: new FormControl('', [Validators.required]),
|
|
password: new FormControl('', [Validators.required])
|
|
})
|
|
constructor(private rayconnect: Rayconnect, private snackbar: MatSnackBar, private router: Router) { }
|
|
|
|
ngOnInit(): void {
|
|
}
|
|
|
|
async submit() {
|
|
if (this.form.valid) {
|
|
this.form.disable();
|
|
try {
|
|
let res = await this.rayconnect.LoginWithPassword({ username: this.form.get('username').value, password: this.form.get('password').value });
|
|
this.snackbar.open(res['message'], 'باشه', { duration: 3000, direction: 'rtl' });
|
|
if (res['status'] == true) {
|
|
await this.rayconnect.setToken(res['data']['token']);
|
|
this.router.navigate(['/panel']);
|
|
} else
|
|
this.form.enable();
|
|
} catch (error) {
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|