blob: bcf46ea64229265f53ba5c31cd02d77ff88ea040 [file] [log] [blame]
brunomilitzer87111ee2021-05-18 12:50:32 +01001/*-
2 * ============LICENSE_START=======================================================
3 * ONAP CLAMP
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights
6 * reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END============================================
20 * ===================================================================
21 *
22 */
23
24export default class UserService {
25 static notLoggedUserName = 'Anonymous';
26
27 static login() {
28 return fetch(window.location.pathname + 'restservices/clds/v1/user/getUser', {
29 method: 'GET',
30 credentials: 'same-origin'
31 })
32 .then(function (response) {
33 console.debug("getUser response received, status code:", response.status);
34 if (response.ok) {
35 return response.text();
36 } else {
37 console.error("getUser response is nok");
38 return UserService.notLoggedUserName;
39 }
40 })
41 .then(function (data) {
42 console.info("User connected:", data)
43 return data;
44 })
45 .catch(function (error) {
46 console.warn("getUser error received, user set to: ", UserService.notLoggedUserName);
47 console.error("getUser error:", error);
48 return UserService.notLoggedUserName;
49 });
50 }
51
52 static getUserInfo() {
53 return fetch(window.location.pathname + 'restservices/clds/v2/clampInformation', {
54 method: 'GET',
55 credentials: 'same-origin'
56 })
57 .then(function (response) {
58 console.debug("getUserInfo response received, status code:", response.status);
59 if (response.ok) {
60 return response.json();
61 } else {
62 return {}
63 }
64 })
65 .then(function (data) {
66 console.info("User info received:", data)
67 return data;
68 })
69 .catch(function (error) {
70 console.warn("getUserInfo error received, user set to: ", UserService.notLoggedUserName);
71 console.error("getUserInfo error:", error);
72 return {};
73 });
74 }
75}