Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <ul id="links">
- <li>
- <a href="/">Home</a>
- </li>
- <li>
- <a href="/census">Census</a>
- </li>
- <li>
- <button (click)="login()">Login</button>
- </li>
- </ul>
- import { Component, OnInit } from '@angular/core';
- import { Router } from '@angular/router';
- import { AuthenticationService } from '../_services/Authentication.Service';
- @Component({
- selector: 'app-header',
- templateUrl: './header.component.html',
- styleUrls: ['./header.component.css']
- })
- export class HeaderComponent implements OnInit {
- constructor(private _auth: AuthenticationService, private router: Router) { }
- ngOnInit() {
- }
- login() {
- this.loading = true;
- this._auth.login(this.model.username, this.model.password)
- .subscribe(result => {
- });
- }
- }
- import { Injectable } from '@angular/core';
- import { Http, Headers, Response, RequestOptions } from '@angular/http';
- import { Observable } from 'rxjs';
- import 'rxjs/add/operator/map'
- @Injectable()
- export class AuthenticationService {
- public token: string;
- constructor(private http: Http) {
- // set token if saved in local storage
- var currentUser = JSON.parse(localStorage.getItem('currentUser'));
- this.token = currentUser && currentUser.token;
- }
- login(usn: string, psw: string): Observable<boolean> {
- let headers = new Headers({ 'Content-Type': 'application/json' });
- let options = new RequestOptions({ headers: headers });
- return this.http.post('http://localhost:5000/auth', JSON.stringify({ username: "email-removed", password: "password-removed" }), options)
- .map((response: Response) => { return true; });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement