Advertisement
Guest User

Untitled

a guest
Oct 26th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. import { Injectable } from '@angular/core';
  2. import { HttpClient } from '@angular/common/http';
  3. import { map } from 'rxjs/operators';
  4.  
  5. @Injectable()
  6. export class UserService {
  7.  
  8. constructor(
  9. private _httpClient: HttpClient
  10. ) { }
  11.  
  12.  
  13. public auth(user) {
  14. return this._httpClient.post('users/login', user).pipe(map((resp: any) => resp.json()));
  15. }
  16.  
  17. }
  18.  
  19. import { Component, OnInit } from '@angular/core';
  20. import { Router } from '@angular/router';
  21. import { UserService } from '../../services/user.service';
  22.  
  23.  
  24.  
  25. @Component({
  26. selector: 'app-side-menu',
  27. templateUrl: './side-menu.component.html',
  28. styleUrls: ['./side-menu.component.scss']
  29. })
  30. export class SideMenuComponent implements OnInit {
  31.  
  32. public positionsList: Array<any> = [];
  33. public selectedOption: string;
  34. public feedbackMessage: string;
  35.  
  36. public email: string;
  37. public password: string;
  38.  
  39. public formNotValid: boolean;
  40.  
  41. constructor(
  42. private _userService: UserService,
  43. private _router: Router
  44. ) {
  45.  
  46. }
  47.  
  48. ngOnInit() {
  49. }
  50.  
  51. public sendLoginForm() {
  52. if(!this.email || !this.password){
  53. this.formNotValid = true;
  54. this.feedbackMessage = "Both fields are required to login!";
  55. return false;
  56. }
  57.  
  58. const user = {
  59. email: this.email,
  60. password: this.password
  61. }
  62.  
  63. this._userService.auth(user).subscribe(resp => {
  64. if(!resp.success){
  65. this.feedbackMessage = resp.message;
  66. return false;
  67. }
  68. });
  69. }
  70.  
  71. public getSelectedOption(option) {
  72. this.selectedOption = "as " + option;
  73. }
  74.  
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement