aboutsummaryrefslogtreecommitdiff
path: root/ufund-ui/src/app/components/login/login.component.ts
blob: 7d906242237bf9e80c6ab2ddacce08ccde5de5e9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import {Component, OnInit} from '@angular/core'
import {UsersService} from '../../services/users.service';
import {ActivatedRoute, Router} from '@angular/router';

@Component({
  selector: 'app-login',
  standalone: false,
  templateUrl: './login.component.html',
  styleUrl: './login.component.css'
})
export class LoginComponent implements OnInit {

    protected next?: string | null;

    constructor(
        protected usersService: UsersService,
        private router: Router,
        private route: ActivatedRoute
    ) {}

    ngOnInit() {
        this.next = this.route.snapshot.queryParamMap.get('redir')
    }

    login(username: string | null, password: string | null) {
        let next = this.next || '/dashboard'
        console.log(`attempting to log in with ${username} ${password}`)
        if (!username || !password) {
            return;
        }

        this.usersService.login(username, password).then(() => {
            this.router.navigate([next]);
        })
    }
}