casdoor/web/src/backend/UserBackend.js

190 lines
6.1 KiB
JavaScript
Raw Normal View History

2022-02-13 23:39:27 +08:00
// Copyright 2021 The Casdoor Authors. All Rights Reserved.
2021-02-13 13:30:51 +08:00
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
2021-02-13 12:15:19 +08:00
import * as Setting from "../Setting";
import i18next from "i18next";
2021-02-13 12:15:19 +08:00
export function getGlobalUsers(page, pageSize, field = "", value = "", sortField = "", sortOrder = "") {
return fetch(`${Setting.ServerUrl}/api/get-global-users?p=${page}&pageSize=${pageSize}&field=${field}&value=${value}&sortField=${sortField}&sortOrder=${sortOrder}`, {
2021-02-13 12:15:19 +08:00
method: "GET",
2022-08-06 23:54:56 +08:00
credentials: "include",
headers: {
"Accept-Language": Setting.getAcceptLanguage(),
},
2021-02-13 12:15:19 +08:00
}).then(res => res.json());
}
export function getUsers(owner, page = "", pageSize = "", field = "", value = "", sortField = "", sortOrder = "") {
return fetch(`${Setting.ServerUrl}/api/get-users?owner=${owner}&p=${page}&pageSize=${pageSize}&field=${field}&value=${value}&sortField=${sortField}&sortOrder=${sortOrder}`, {
2021-02-13 12:15:19 +08:00
method: "GET",
2022-08-06 23:54:56 +08:00
credentials: "include",
headers: {
"Accept-Language": Setting.getAcceptLanguage(),
},
2021-02-13 12:15:19 +08:00
}).then(res => res.json());
}
export function getUser(owner, name) {
return fetch(`${Setting.ServerUrl}/api/get-user?id=${owner}/${encodeURIComponent(name)}`, {
method: "GET",
2022-08-06 23:54:56 +08:00
credentials: "include",
headers: {
"Accept-Language": Setting.getAcceptLanguage(),
},
2021-02-13 12:15:19 +08:00
}).then(res => res.json());
}
export function updateUser(owner, name, user) {
const newUser = Setting.deepCopy(user);
2021-02-13 12:15:19 +08:00
return fetch(`${Setting.ServerUrl}/api/update-user?id=${owner}/${encodeURIComponent(name)}`, {
method: "POST",
credentials: "include",
2021-02-13 12:15:19 +08:00
body: JSON.stringify(newUser),
headers: {
"Accept-Language": Setting.getAcceptLanguage(),
},
2021-02-13 12:15:19 +08:00
}).then(res => res.json());
}
export function addUser(user) {
const newUser = Setting.deepCopy(user);
2021-02-13 12:15:19 +08:00
return fetch(`${Setting.ServerUrl}/api/add-user`, {
method: "POST",
credentials: "include",
2021-02-13 12:15:19 +08:00
body: JSON.stringify(newUser),
headers: {
"Accept-Language": Setting.getAcceptLanguage(),
},
2021-02-13 12:15:19 +08:00
}).then(res => res.json());
}
export function deleteUser(user) {
const newUser = Setting.deepCopy(user);
2021-02-13 12:15:19 +08:00
return fetch(`${Setting.ServerUrl}/api/delete-user`, {
method: "POST",
credentials: "include",
2021-02-13 12:15:19 +08:00
body: JSON.stringify(newUser),
headers: {
"Accept-Language": Setting.getAcceptLanguage(),
},
2021-02-13 12:15:19 +08:00
}).then(res => res.json());
}
feat: added avatar tailoring and uploading Signed-off-by: Kininaru <shiftregister233@outlook.com> fixed type errors Signed-off-by: Kininaru <shiftregister233@outlook.com> fixed the wrong folder Signed-off-by: Kininaru <shiftregister233@outlook.com> rewrite login check logic, added unix time to avatar url Signed-off-by: Kininaru <shiftregister233@outlook.com> fixed a bug about strconv Signed-off-by: Kininaru <shiftregister233@outlook.com> supported oss Signed-off-by: Kininaru <shiftregister233@outlook.com> disabled oss provide qiniu Signed-off-by: Kininaru <shiftregister233@outlook.com> Fixed avatar url error Signed-off-by: Kininaru <shiftregister233@outlook.com> Fixed avatar length bug Signed-off-by: Kininaru <shiftregister233@outlook.com> Fixed avatar length bug Signed-off-by: Kininaru <shiftregister233@outlook.com> fixed oss.conf Signed-off-by: Kininaru <shiftregister233@outlook.com> Put uploading avatar into UserEditPage Signed-off-by: Kininaru <shiftregister233@outlook.com> removed avatar dir Signed-off-by: Kininaru <shiftregister233@outlook.com> removed avatar in main.go Signed-off-by: Kininaru <shiftregister233@outlook.com> Made CropperDiv a reusable component, and updated README for OSS config Signed-off-by: Kininaru <shiftregister233@outlook.com> Convert ts to js Signed-off-by: Kininaru <shiftregister233@outlook.com> removed ts Signed-off-by: Kininaru <shiftregister233@outlook.com> fix: set avatar link to string 255 Signed-off-by: Kininaru <shiftregister233@outlook.com> fix: updated yarn lock Signed-off-by: Kininaru <shiftregister233@outlook.com> add: Casbin license Signed-off-by: Kininaru <shiftregister233@outlook.com>
2021-03-14 15:50:36 +08:00
2021-06-04 20:47:27 +08:00
export function getAddressOptions(url) {
return fetch(url, {
method: "GET",
}).then(res => res.json());
}
export function getAffiliationOptions(url, code) {
return fetch(`${url}/${code}`, {
method: "GET",
}).then(res => res.json());
}
export function setPassword(userOwner, userName, oldPassword, newPassword) {
const formData = new FormData();
formData.append("userOwner", userOwner);
formData.append("userName", userName);
formData.append("oldPassword", oldPassword);
formData.append("newPassword", newPassword);
return fetch(`${Setting.ServerUrl}/api/set-password`, {
method: "POST",
credentials: "include",
2022-08-06 23:54:56 +08:00
body: formData,
headers: {
"Accept-Language": Setting.getAcceptLanguage(),
},
}).then(res => res.json());
}
export function sendCode(checkType, checkId, checkKey, method, dest, type, applicationId, checkUser) {
const formData = new FormData();
formData.append("checkType", checkType);
formData.append("checkId", checkId);
formData.append("checkKey", checkKey);
formData.append("method", method);
formData.append("dest", dest);
formData.append("type", type);
formData.append("applicationId", applicationId);
formData.append("checkUser", checkUser);
return fetch(`${Setting.ServerUrl}/api/send-verification-code`, {
method: "POST",
credentials: "include",
2022-08-06 23:54:56 +08:00
body: formData,
headers: {
"Accept-Language": Setting.getAcceptLanguage(),
},
}).then(res => res.json()).then(res => {
if (res.status === "ok") {
Setting.showMessage("success", i18next.t("user:Code Sent"));
return true;
} else {
Setting.showMessage("error", i18next.t("user:" + res.msg));
return false;
}
});
}
export function verifyCaptcha(captchaType, captchaToken, clientSecret) {
const formData = new FormData();
formData.append("captchaType", captchaType);
formData.append("captchaToken", captchaToken);
formData.append("clientSecret", clientSecret);
return fetch(`${Setting.ServerUrl}/api/verify-captcha`, {
method: "POST",
credentials: "include",
2022-08-06 23:54:56 +08:00
body: formData,
headers: {
"Accept-Language": Setting.getAcceptLanguage(),
},
}).then(res => res.json()).then(res => {
if (res.status === "ok") {
if (res.data) {
Setting.showMessage("success", i18next.t("user:Captcha Verify Success"));
} else {
Setting.showMessage("error", i18next.t("user:Captcha Verify Failed"));
}
return true;
} else {
Setting.showMessage("error", i18next.t("user:" + res.msg));
return false;
}
});
}
export function resetEmailOrPhone(dest, type, code) {
const formData = new FormData();
formData.append("dest", dest);
formData.append("type", type);
formData.append("code", code);
return fetch(`${Setting.ServerUrl}/api/reset-email-or-phone`, {
method: "POST",
credentials: "include",
2022-08-06 23:54:56 +08:00
body: formData,
headers: {
"Accept-Language": Setting.getAcceptLanguage(),
},
}).then(res => res.json());
}
export function getCaptcha(owner, name, isCurrentProvider) {
return fetch(`${Setting.ServerUrl}/api/get-captcha?applicationId=${owner}/${encodeURIComponent(name)}&isCurrentProvider=${isCurrentProvider}`, {
2022-08-06 23:54:56 +08:00
method: "GET",
headers: {
"Accept-Language": Setting.getAcceptLanguage(),
},
}).then(res => res.json()).then(res => res.data);
}