Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {Injectable} from "@angular/core";
- import {Http, Headers} from "@angular/http";
- import { Observable } from 'rxjs/Observable';
- @Injectable()
- export class LoginService {
- private loggedIn = false;
- private loginUrl = 'http://localhost:8080/j_spring_security_check';
- private logoutUrl = 'http://localhost:8080/j_spring_security_logout';
- constructor(private http: Http) { }
- login(username, password) {
- let headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded' });
- let body = 'j_username=' +username +'&j_password=' +password;
- return this.http.post(this.loginUrl, body, { headers: headers }).map(
- result => this.loggedIn = true
- );
- }
- logout() {
- let headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded' });
- let body = '';
- return this.http.post(this.logoutUrl, body, { headers: headers }).map(
- result => this.loggedIn = false
- );
- }
- isLoggedIn(): boolean {
- return this.loggedIn
- }
- }
Add Comment
Please, Sign In to add comment