fengxiang
2018-03-08 efe936a73370a55d4c3336fb9973a92fcf87efff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { Authorization } from '@business/entity/token';
import { HttpClient } from '@angular/common/http';
import { environment } from 'environments/environment';
import { Observable } from 'rxjs/Observable';
import { Injectable } from '@angular/core';
import { UserContext } from '@business/entity/data';
import { error } from 'selenium-webdriver';
 
@Injectable()
export class LoginService {
  public authorization: Authorization;
  public userContext: UserContext;
  private urls = {
    login: environment.SERVER_BASH_URL + 'auth/login',
    userContext: environment.SERVER_BASH_URL + 'user-context',
  };
  constructor(private http: HttpClient) { }
  public validate(username: string, password: string): Observable<Authorization> {
      return this.http.post(this.urls.login, {username: username, password: password, mode: 'Web'}).map(
           (res: any) => {
               this.authorization = res;
               return res;
           }
      );
  }
  public loadUserContext(): void {
      this.http.get(this.urls.userContext).subscribe(
        (res: UserContext) => {
           this.userContext = res;
           return res;
        }
      );
  }
}