github.com/in4it/ecs-deploy@v0.0.42-0.20240508120354-ed77ff16df25/webapp/src/app/login/login.component.ts (about) 1 import { Component, OnInit } from '@angular/core'; 2 3 import { Router, ActivatedRoute } from '@angular/router'; 4 5 import { AlertService, AuthService } from '../services/index'; 6 7 @Component({ 8 selector: 'app-login', 9 templateUrl: './login.component.html', 10 styleUrls: ['./login.component.css'] 11 }) 12 export class LoginComponent implements OnInit { 13 14 model: any = {}; 15 loading = false; 16 returnUrl: string; 17 18 constructor( 19 private route: ActivatedRoute, 20 private router: Router, 21 private authenticationService: AuthService, 22 private alertService: AlertService) { } 23 24 ngOnInit() { 25 // reset login status 26 this.authenticationService.logout(); 27 28 // get return url from route parameters or default to '/' 29 this.returnUrl = this.route.snapshot.queryParams['returnUrl'] || '/'; 30 } 31 32 login() { 33 this.loading = true; 34 this.authenticationService.login(this.model.username, this.model.password) 35 .subscribe( 36 data => { 37 this.router.navigate([this.returnUrl]); 38 }, 39 error => { 40 console.log(error) 41 this.alertService.error(error.error.message); 42 this.loading = false; 43 }); 44 } 45 }