Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Injectable } from '@angular/core';
- import { HttpClient } from '@angular/common/http';
- import { map } from 'rxjs/operators';
- @Injectable()
- export class UserService {
- constructor(
- private _httpClient: HttpClient
- ) { }
- public auth(user) {
- return this._httpClient.post('users/login', user).pipe(map((resp: any) => resp.json()));
- }
- }
- import { Component, OnInit } from '@angular/core';
- import { Router } from '@angular/router';
- import { UserService } from '../../services/user.service';
- @Component({
- selector: 'app-side-menu',
- templateUrl: './side-menu.component.html',
- styleUrls: ['./side-menu.component.scss']
- })
- export class SideMenuComponent implements OnInit {
- public positionsList: Array<any> = [];
- public selectedOption: string;
- public feedbackMessage: string;
- public email: string;
- public password: string;
- public formNotValid: boolean;
- constructor(
- private _userService: UserService,
- private _router: Router
- ) {
- }
- ngOnInit() {
- }
- public sendLoginForm() {
- if(!this.email || !this.password){
- this.formNotValid = true;
- this.feedbackMessage = "Both fields are required to login!";
- return false;
- }
- const user = {
- email: this.email,
- password: this.password
- }
- this._userService.auth(user).subscribe(resp => {
- if(!resp.success){
- this.feedbackMessage = resp.message;
- return false;
- }
- });
- }
- public getSelectedOption(option) {
- this.selectedOption = "as " + option;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement