talofer99 icon

login

talofer99 | PRO | 05/29/18 01:14:59 PM UTC | 0 ⭐ | 397 👁️ | Never ⏰ | []
text |

1.75 KB

|

None

|

0 👍

/

0 👎

import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import {UserService} from '../user.service'
import { HttpClient } from '@angular/common/http';
import { map } from 'rxjs/operators';
 import { HttpHeaders } from '@angular/common/http';
 const httpOptions = {
  headers: new HttpHeaders({
    'Content-Type':  'application/json'
  })
};
  @Component({
  selector: 'app-login-form',
  templateUrl: './login-form.component.html',
  styleUrls: ['./login-form.component.css']
})
export class LoginFormComponent implements OnInit {
  loginResult: any;
  loginUrl = 'http://67604f41b6e04406b30c11909d8f1060.cloudapp.net/api/ACAccount/ValidateUser2Json';
  loginParam = '';
  constructor(private router:Router, private user:UserService,private http: HttpClient) { }
   ngOnInit() {
  }
   loginUser(e) {
  	e.preventDefault();
  	console.log(e);
  	var username = e.target.elements[0].value;
  	var password = e.target.elements[1].value;
  	console.log(username, password);
	this.loginParam = '"' + this.user.getUserClientNumber() + '^' + username + '^' + password + '"';
	console.log(this.loginParam);
	this.getLoginResult();
    	if(username == 'admin' && password == 'admin') {
      this.user.setUserLoggedIn();
  	  this.router.navigate(['dashboard']);
  	}
	return false;
  }
   // Read all REST Items
  getLoginResult(): void {
    this.restLogIn()
      .subscribe(
        loginResult => {
          this.loginResult = loginResult;
		  console.log(this.loginResult);
        }
      )
  }
   // Rest Items Service: Read all REST Items
  restLogIn() {
    return this.http
      .post<any[]>(this.loginUrl, this.loginParam,httpOptions)
      .pipe(map(data => data));
  }
 }

Comments