import { TokenService } from '@delon/auth'; import { User, Auth } from '@domain'; import { Injectable, Inject } from '@angular/core'; import { _HttpClient } from '@delon/theme'; // import { HttpParams, HttpClient } from '@angular/common/http'; import { map, switchMap , catchError } from 'rxjs/operators'; // import 'rxjs/add/operator/shareReplay'; import { throwError as _throw , Observable, of } from 'rxjs'; @Injectable({providedIn: 'root'}) export class AuthService { // uri = ''; constructor(private http: _HttpClient) { } // register(user: User): Observable { // const uri = this.urisConfig.userUri; // z // // const params = new HttpParams() // // .set('phone', user.phone); // const param = {phone : user.phone}; // const ans = this.http.get(uri, param); // console.log(ans); // return this.http.get(uri, param) // .pipe( // switchMap(res => { // if (( res).length > 0 ) { // return _throw('E0001'); // mobile phone existed // } // return this.http.post(uri, JSON.stringify(user)); // }) // ); // } // setLoginParams(user: User): HttpParams { // if (user.phone === '') { // return new HttpParams() // .set('phone', user.phone) // .set('password', user.password); // } else { // return new HttpParams() // .set('name', user.name) // .set('password', user.password); // } // } // setLoginParams(user: User): any { // if (user.mobile === '') { // return { // phone : user.mobile, // password : user.password // }; // } else { // return { // name : user.userName, // password : user.password // }; // } // } Login(param: User): Observable { const uri = '/passport/UMA'; // const param = this.setLoginParams(user); const ans = this.http.get(uri, param); // 校验是否有对应的用户 return this.http.get(uri, param) .pipe( catchError(err => { console.log('authSrv err', err); return of({}); }), map( res => { // backend use queryhash: 5c6a1d0f089bb7559034392f // auth = {token,user}; const auth = res; if (!auth.user) { console.log('auth.service-Login,no get user'); throw new Error('Username or password incorrect'); } return auth; } ) ); } }