Advertisement
Guest User

Untitled

a guest
Dec 30th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. <ul id="links">
  2. <li>
  3. <a href="/">Home</a>
  4. </li>
  5. <li>
  6. <a href="/census">Census</a>
  7. </li>
  8. <li>
  9. <button (click)="login()">Login</button>
  10. </li>
  11. </ul>
  12.  
  13. import { Component, OnInit } from '@angular/core';
  14. import { Router } from '@angular/router';
  15.  
  16. import { AuthenticationService } from '../_services/Authentication.Service';
  17.  
  18. @Component({
  19. selector: 'app-header',
  20. templateUrl: './header.component.html',
  21. styleUrls: ['./header.component.css']
  22. })
  23. export class HeaderComponent implements OnInit {
  24.  
  25. constructor(private _auth: AuthenticationService, private router: Router) { }
  26.  
  27. ngOnInit() {
  28. }
  29.  
  30. login() {
  31.         this.loading = true;
  32.         this._auth.login(this.model.username, this.model.password)
  33.             .subscribe(result => {
  34.  
  35.             });
  36.     }
  37.  
  38. }
  39.  
  40. import { Injectable } from '@angular/core';
  41. import { Http, Headers, Response, RequestOptions } from '@angular/http';
  42. import { Observable } from 'rxjs';
  43. import 'rxjs/add/operator/map'
  44.  
  45. @Injectable()
  46. export class AuthenticationService {
  47.     public token: string;
  48.  
  49.     constructor(private http: Http) {
  50.         // set token if saved in local storage
  51.         var currentUser = JSON.parse(localStorage.getItem('currentUser'));
  52.         this.token = currentUser && currentUser.token;
  53.     }
  54.  
  55.     login(usn: string, psw: string): Observable<boolean> {
  56. let headers = new Headers({ 'Content-Type': 'application/json' });
  57. let options = new RequestOptions({ headers: headers });
  58. return this.http.post('http://localhost:5000/auth', JSON.stringify({ username: "email-removed", password: "password-removed" }), options)
  59. .map((response: Response) => { return true; });
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement