You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

41 lines
1.2 KiB

import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { User } from 'src/app/model/User';
@Injectable({
providedIn: 'root'
})
export class UserService {
path:string='http://localhost:8001/api1';
constructor(private httpClient:HttpClient){
}
postUser(user : User):Observable<User[]>{
let authCode = btoa(user.username+':'+user.password);
user.username = authCode;
user.password = '';
return this.httpClient.post<User[]>(this.path+'/signup/',user);
}
login(user : any):Observable<User[]>{
let httpOptions={
headers : new HttpHeaders({
'Content-Type':'application/json',
'Authorization':'Basic ' + btoa(user.username+':'+user.password)
})
}
window.sessionStorage.setItem("code",btoa(user.username+':'+user.password));
let login_api = this.path + '/login';
return this.httpClient.get<User[]>(login_api,httpOptions);
}
public getDetails(user:any):Observable<User>{
console.log("j",user)
let user_api=this.path+'/username/'+user;
return this.httpClient.get<any>(user_api);
}
}