Advertisement
talofer99

login

May 29th, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. import { Component, OnInit } from '@angular/core';
  2. import { Router } from '@angular/router';
  3. import {UserService} from '../user.service'
  4. import { HttpClient } from '@angular/common/http';
  5. import { map } from 'rxjs/operators';
  6.  
  7. import { HttpHeaders } from '@angular/common/http';
  8.  
  9. const httpOptions = {
  10. headers: new HttpHeaders({
  11. 'Content-Type': 'application/json'
  12. })
  13. };
  14.  
  15.  
  16. @Component({
  17. selector: 'app-login-form',
  18. templateUrl: './login-form.component.html',
  19. styleUrls: ['./login-form.component.css']
  20. })
  21. export class LoginFormComponent implements OnInit {
  22. loginResult: any;
  23. loginUrl = 'http://67604f41b6e04406b30c11909d8f1060.cloudapp.net/api/ACAccount/ValidateUser2Json';
  24. loginParam = '';
  25. constructor(private router:Router, private user:UserService,private http: HttpClient) { }
  26.  
  27. ngOnInit() {
  28. }
  29.  
  30. loginUser(e) {
  31. e.preventDefault();
  32. console.log(e);
  33. var username = e.target.elements[0].value;
  34. var password = e.target.elements[1].value;
  35. console.log(username, password);
  36. this.loginParam = '"' + this.user.getUserClientNumber() + '^' + username + '^' + password + '"';
  37. console.log(this.loginParam);
  38. this.getLoginResult();
  39.  
  40.  
  41. if(username == 'admin' && password == 'admin') {
  42. this.user.setUserLoggedIn();
  43. this.router.navigate(['dashboard']);
  44. }
  45. return false;
  46. }
  47.  
  48. // Read all REST Items
  49. getLoginResult(): void {
  50. this.restLogIn()
  51. .subscribe(
  52. loginResult => {
  53. this.loginResult = loginResult;
  54. console.log(this.loginResult);
  55. }
  56. )
  57. }
  58.  
  59. // Rest Items Service: Read all REST Items
  60. restLogIn() {
  61. return this.http
  62. .post<any[]>(this.loginUrl, this.loginParam,httpOptions)
  63. .pipe(map(data => data));
  64. }
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement