Last active
December 27, 2017 13:39
-
-
Save zac260103/a5aeb8a3d63e88d3440b77ed51a2fe83 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Subject } from 'rxjs/Subject'; | |
import { TokenInfo } from './tokeninfo'; | |
//import { Token } from './checktoken'; | |
//import { Applist } from './applist'; | |
//import { ApplistWithVersion } from './applistwithversion'; | |
import { Injectable, Input } from '@angular/core'; | |
import { Http } from '@angular/http'; | |
import { ActivatedRoute } from '@angular/router'; | |
import {Observable} from 'rxjs/Observable'; | |
import { Router } from '@angular/router'; | |
import { Headers, RequestOptions } from '@angular/http'; | |
import 'rxjs/add/operator/toPromise'; | |
import 'rxjs/add/operator/catch'; | |
@Injectable() | |
export class LoginService { | |
public tokeninfo: TokenInfo; | |
public tokeninfo3: TokenInfo; | |
private tokeninfo2 = new Subject(); | |
tokenObservable =this.tokeninfo2.asObservable(); | |
//router: Router; | |
constructor(private http: Http, | |
private route: ActivatedRoute, | |
private router: Router, | |
) {} | |
/****** for docker with certificate (現場) ******/ | |
apiurl : string = 'http://localhost:8080/myapii/catalogg?token=xxx&os=ggg' | |
tokenurl: string = 'http://localhost:8080/myapii/login' | |
getimageurl : string = 'https://emss.b2e.cht.com.tw:7702/myapii/image?imageUrl=' | |
applisturlForOne : string = 'http://localhost:8080/myapii/getappinfo?token=xxx' | |
getToken(name:string, password:string) : Promise<TokenInfo>{ | |
let headers = new Headers({ 'username': name }); | |
headers.append('password', password); | |
let options = new RequestOptions({ headers: headers, method: "get" }); | |
console.log("getToken") | |
return this.http | |
.get(this.tokenurl, options) | |
.toPromise() | |
.then(value => { | |
this.tokeninfo = value.json(); | |
console.log("tokeninfo="+this.tokeninfo); | |
//console.log(this.tokeninfo.access_token); | |
//console.log(this.apiurl + 'token=' + token +'&'+ 'os=' + platform); | |
//console.log("c"); | |
return this.tokeninfo; | |
}) | |
.catch(error => { | |
if (error.status === 401) { | |
console.log("ssdssss") | |
this.router.navigate(['error']); | |
console.log("sds") | |
return Observable.throw(error); | |
} | |
// do any other checking for statuses here | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment