Guest User

Untitled

a guest
Aug 11th, 2016
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. import {Injectable} from "@angular/core";
  2. import {Http, Headers} from "@angular/http";
  3. import { Observable } from 'rxjs/Observable';
  4.  
  5. @Injectable()
  6. export class LoginService {
  7.  
  8. private loggedIn = false;
  9. private loginUrl = 'http://localhost:8080/j_spring_security_check';
  10. private logoutUrl = 'http://localhost:8080/j_spring_security_logout';
  11.  
  12. constructor(private http: Http) { }
  13.  
  14. login(username, password) {
  15. let headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded' });
  16. let body = 'j_username=' +username +'&j_password=' +password;
  17. return this.http.post(this.loginUrl, body, { headers: headers }).map(
  18. result => this.loggedIn = true
  19. );
  20. }
  21.  
  22. logout() {
  23. let headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded' });
  24. let body = '';
  25. return this.http.post(this.logoutUrl, body, { headers: headers }).map(
  26. result => this.loggedIn = false
  27. );
  28. }
  29.  
  30. isLoggedIn(): boolean {
  31. return this.loggedIn
  32. }
  33. }
Add Comment
Please, Sign In to add comment