Home page carousel
[eliot.git] / blueprints / common / eliot-ui / frontend-src / src / app / login / login.component.ts
1 import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
2 // import { ToolbarService } from './../toolbar/toolbar.service';
3
4 import { Router, ActivatedRoute } from '@angular/router';
5 import { FormBuilder, FormGroup, Validators } from '@angular/forms';
6
7 import { AuthenticationService } from '../_services/authentication.service';
8 import { EliotserviceService } from '../eliotservice.service';
9 declare var particlesJS: any;
10
11 @Component({
12   selector: 'app-login',
13   templateUrl: './login.component.html',
14   styleUrls: ['./login.component.scss']
15 })
16 export class LoginComponent implements OnInit {
17   
18
19   loginForm: FormGroup;
20   loading = false;
21   submitted = false;
22   returnUrl: string;
23   hide = true;
24
25   roles = {
26     role:'ADMIN'
27   }
28
29   constructor(
30     private formBuilder: FormBuilder,
31     private route: ActivatedRoute,
32     private router: Router,
33     private authenticationService: AuthenticationService,
34     private eliotService: EliotserviceService
35
36   ) { }
37
38   ngOnInit() {
39     debugger;
40     
41     this.loginForm = this.formBuilder.group({
42       email: ['', Validators.required],
43       password: ['', Validators.required]
44     });
45
46     particlesJS.load('particles-js', './../../assets/particlesjs-config.json', function() {
47       console.log('callback - particles.js config loaded');
48     });
49   }
50
51   get fval() { return this.loginForm.controls; }
52
53   onFormSubmit() {
54     console.log("Inside onFormSubmit() ....")
55     this.submitted = true;
56     if (this.loginForm.invalid) {
57       console.log("Login Form invalid...")
58       return;
59     }
60     this.loading = true;
61
62     // mock role 
63     this.eliotService.getRoleName()
64       .subscribe(
65         data => {
66           console.log(data);
67           sessionStorage.setItem('roleName',data.roleName);
68         }
69       );
70     this.router.navigate(['/']);
71
72     this.authenticationService.login(this.fval.email.value, this.fval.password.value)
73       .subscribe(
74         data => {
75           sessionStorage.setItem('roleName',this.roles.role);
76           this.router.navigate(['/']);
77         },
78         error => {
79           this.loading = false;
80         });
81   }
82
83 }