My web service provides me with permissions from my user. The permissions are stored as an array in JSON format. I need to find a way to access and display this data in another function.
{"StatusCode":0,"StatusMessage":"Authenticated Successfully",
"Token":"fgfhgjhgkfgddfgggffhhfazcfdddd",
"StatusDescription":{
"permissions":["usersgetall","usersdelete","usersupdate","clientgetall",
"clientupdate","clientdelete"....]}
"role":"root"
}
The login function that I have is structured like this: How can I create a new function that will list all the permissions for a specific user?
public loginByUsernameAndPassword(username: string, password: string): Observable<boolean> {
let urlSearchParams = new URLSearchParams();
urlSearchParams.append('username', username);
urlSearchParams.append('password', password);
urlSearchParams.append('user_uniqueIdid', '0');
urlSearchParams.append('session_id', '0');
let body = urlSearchParams.toString();
let headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
return this.http.post(Api.getUrl(Api.URLS.Login), body, {
headers: headers
})
.map((response: Response) => {
let res = response.json();
console.log(rs)// show Permissions[]
if (res.StatusCode === 0 && res.Token) {
this.currentUser = {
username: username,
token: res.Token
}
localStorage.setItem(AuthService.CURRENT_USER, JSON.stringify(this.currentUser));
return true;
} else {
return false;
}
});
}