Login:Src:Utils: remove some actions
This commit is contained in:
parent
8dac5fbb9f
commit
1505d9ae78
@ -284,31 +284,6 @@ export async function getPortalPasswordSettings(
|
||||
return passwordSettings.response as TPasswordSettings;
|
||||
}
|
||||
|
||||
export async function getUserByEmail(
|
||||
userEmail: string,
|
||||
confirmKey: string | null = null,
|
||||
) {
|
||||
const [getUserByEmail] = createRequest(
|
||||
[`/people/email?email=${userEmail}`],
|
||||
[confirmKey ? ["Confirm", confirmKey] : ["", ""]],
|
||||
"GET",
|
||||
);
|
||||
|
||||
const res = await fetch(getUserByEmail);
|
||||
|
||||
if (!res.ok) {
|
||||
return res.status;
|
||||
}
|
||||
|
||||
const user = await res.json();
|
||||
|
||||
if (user && user.displayName) {
|
||||
user.displayName = Encoder.htmlDecode(user.displayName);
|
||||
}
|
||||
|
||||
return user.response as TUser;
|
||||
}
|
||||
|
||||
export async function getUserFromConfirm(
|
||||
userId: string,
|
||||
confirmKey: string | null = null,
|
||||
@ -380,237 +355,6 @@ export async function getPortalTimeZones(confirmKey: string | null = null) {
|
||||
return portalTimeZones.response as TTimeZone[];
|
||||
}
|
||||
|
||||
/* export async function checkConfirmLink(data: any): Promise<any> {
|
||||
try {
|
||||
const [checkConfirmLink] = createRequest(
|
||||
[`/authentication/confirm`],
|
||||
[["Content-Type", "application/json;charset=utf-8"]],
|
||||
"POST",
|
||||
JSON.stringify(data),
|
||||
);
|
||||
|
||||
console.log("data", JSON.stringify(data));
|
||||
|
||||
const res = await (await fetch(checkConfirmLink)).json();
|
||||
|
||||
if (!res.ok) return;
|
||||
|
||||
const validationResult = await res.json();
|
||||
|
||||
return validationResult.response;
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
} */
|
||||
|
||||
export async function logout() {
|
||||
const [logout] = createRequest(
|
||||
[`/authentication/logout`],
|
||||
[["", ""]],
|
||||
"POST",
|
||||
);
|
||||
|
||||
const res = await fetch(logout);
|
||||
|
||||
if (!res.ok) return;
|
||||
}
|
||||
|
||||
export async function signupOAuth(signupAccount: { [key: string]: string }) {
|
||||
const [signupOAuth] = createRequest(
|
||||
[`/people/thirdparty/signup`],
|
||||
[["", ""]],
|
||||
"POST",
|
||||
JSON.stringify({
|
||||
signupAccount,
|
||||
}),
|
||||
);
|
||||
|
||||
const res = await (await fetch(signupOAuth)).json();
|
||||
|
||||
if (!res.ok) throw new Error(res.statusText);
|
||||
}
|
||||
|
||||
export async function createUser(
|
||||
data: TCreateUserData,
|
||||
confirmKey: string | null = null,
|
||||
) {
|
||||
const [createUser] = createRequest(
|
||||
[`/people`],
|
||||
[
|
||||
confirmKey ? ["Confirm", confirmKey] : ["", ""],
|
||||
["Content-Type", "application/json;charset=utf-8"],
|
||||
],
|
||||
"POST",
|
||||
JSON.stringify(data),
|
||||
);
|
||||
|
||||
const res = await fetch(createUser);
|
||||
|
||||
if (!res.ok) throw await res.json();
|
||||
|
||||
const user = await res.json();
|
||||
|
||||
if (user && user.displayName) {
|
||||
user.displayName = Encoder.htmlDecode(user.displayName);
|
||||
}
|
||||
|
||||
return user.response as TUser;
|
||||
}
|
||||
|
||||
export async function suspendPortal(confirmKey: string | null = null) {
|
||||
const [changeEmail] = createRequest(
|
||||
[`/portal/suspend`],
|
||||
[
|
||||
confirmKey ? ["confirm", confirmKey] : ["", ""],
|
||||
["Content-Type", "application/json;charset=utf-8"],
|
||||
],
|
||||
"PUT",
|
||||
);
|
||||
|
||||
const res = await fetch(changeEmail);
|
||||
|
||||
if (!res.ok) throw new Error(res.statusText);
|
||||
}
|
||||
|
||||
export async function continuePortal(confirmKey: string | null = null) {
|
||||
const [continuePortal] = createRequest(
|
||||
[`/portal/continue`],
|
||||
[
|
||||
confirmKey ? ["confirm", confirmKey] : ["", ""],
|
||||
["Content-Type", "application/json;charset=utf-8"],
|
||||
],
|
||||
"PUT",
|
||||
);
|
||||
|
||||
const res = await fetch(continuePortal);
|
||||
|
||||
if (!res.ok) throw new Error(res.statusText);
|
||||
}
|
||||
|
||||
export async function changePassword(
|
||||
passwordHash: string,
|
||||
userId?: string,
|
||||
confirmKey: string | null = null,
|
||||
) {
|
||||
const [changePassword] = createRequest(
|
||||
[`/people/${userId}/password`],
|
||||
[
|
||||
confirmKey ? ["confirm", confirmKey] : ["", ""],
|
||||
["Content-Type", "application/json;charset=utf-8"],
|
||||
],
|
||||
"PUT",
|
||||
JSON.stringify({ passwordHash }),
|
||||
);
|
||||
|
||||
const res = await fetch(changePassword);
|
||||
|
||||
if (!res.ok) {
|
||||
if (res.status === 500) {
|
||||
const errorRes = await res.json();
|
||||
throw new Error(errorRes.error.message);
|
||||
}
|
||||
throw new Error(res.statusText);
|
||||
}
|
||||
|
||||
const user = await res.json();
|
||||
|
||||
if (user && user.displayName) {
|
||||
user.displayName = Encoder.htmlDecode(user.displayName);
|
||||
}
|
||||
|
||||
return user.response as TUser;
|
||||
}
|
||||
|
||||
export async function changeEmail(
|
||||
email: string,
|
||||
userId?: string,
|
||||
key: string | null = null,
|
||||
) {
|
||||
const [changeEmail] = createRequest(
|
||||
[`/people/${userId}/password`],
|
||||
[
|
||||
key ? ["confirm", key] : ["", ""],
|
||||
["Content-Type", "application/json;charset=utf-8"],
|
||||
],
|
||||
"PUT",
|
||||
JSON.stringify({ email }),
|
||||
);
|
||||
|
||||
const res = await fetch(changeEmail);
|
||||
|
||||
if (!res.ok) throw new Error(res.statusText);
|
||||
}
|
||||
|
||||
export async function updateActivationStatus(
|
||||
activationStatus: EmployeeActivationStatus,
|
||||
userId: string,
|
||||
key: string,
|
||||
) {
|
||||
const [updateActivationStatus] = createRequest(
|
||||
[`/people/activationstatus/${activationStatus}`],
|
||||
[
|
||||
key ? ["confirm", key] : ["", ""],
|
||||
["Content-Type", "application/json;charset=utf-8"],
|
||||
],
|
||||
"PUT",
|
||||
JSON.stringify({ userIds: [userId] }),
|
||||
);
|
||||
|
||||
const res = await fetch(updateActivationStatus);
|
||||
|
||||
if (!res.ok) throw new Error(res.statusText);
|
||||
}
|
||||
|
||||
export async function updateUser(
|
||||
id: string,
|
||||
FirstName?: string,
|
||||
LastName?: string,
|
||||
) {
|
||||
const [updateUser] = createRequest(
|
||||
[`/people/${id}`],
|
||||
[["Content-Type", "application/json;charset=utf-8"]],
|
||||
"PUT",
|
||||
JSON.stringify({ id, FirstName, LastName }),
|
||||
);
|
||||
|
||||
const res = await fetch(updateUser);
|
||||
|
||||
if (!res.ok) {
|
||||
if (res.status === 500) {
|
||||
const errorRes = await res.json();
|
||||
throw new Error(errorRes.error.message);
|
||||
}
|
||||
throw new Error(res.statusText);
|
||||
}
|
||||
|
||||
const user = await res.json();
|
||||
|
||||
if (user && user.displayName) {
|
||||
user.displayName = Encoder.htmlDecode(user.displayName);
|
||||
}
|
||||
|
||||
return user.response as TUser;
|
||||
}
|
||||
|
||||
export async function ownerChange(
|
||||
ownerId?: string,
|
||||
confirmKey: string | null = null,
|
||||
) {
|
||||
const [changePassword] = createRequest(
|
||||
[`/settings/owner`],
|
||||
[
|
||||
confirmKey ? ["confirm", confirmKey] : ["", ""],
|
||||
["Content-Type", "application/json;charset=utf-8"],
|
||||
],
|
||||
"PUT",
|
||||
JSON.stringify({ ownerId }),
|
||||
);
|
||||
|
||||
const res = await fetch(changePassword);
|
||||
|
||||
if (!res.ok) throw new Error(res.statusText);
|
||||
}
|
||||
|
||||
export async function getTfaSecretKeyAndQR(confirmKey: string | null = null) {
|
||||
const [getTfaSecretKeyAndQR] = createRequest(
|
||||
[`/settings/tfaapp/setup`],
|
||||
@ -626,34 +370,3 @@ export async function getTfaSecretKeyAndQR(confirmKey: string | null = null) {
|
||||
|
||||
return tfaSecretKeyAndQR.response as TTfaSecretKeyAndQR;
|
||||
}
|
||||
|
||||
export async function deleteSelf(confirmKey: string | null = null) {
|
||||
const [deleteSelf] = createRequest(
|
||||
[`/people/@self`],
|
||||
[confirmKey ? ["Confirm", confirmKey] : ["", ""]],
|
||||
"DELETE",
|
||||
);
|
||||
|
||||
const res = await fetch(deleteSelf);
|
||||
|
||||
if (!res.ok) throw new Error(res.statusText);
|
||||
}
|
||||
|
||||
export async function deletePortal(confirmKey: string | null = null) {
|
||||
const [deletePortal] = createRequest(
|
||||
[`/portal/delete`],
|
||||
[
|
||||
confirmKey ? ["Confirm", confirmKey] : ["", ""],
|
||||
["Accept", "application/json;charset=utf-8"],
|
||||
],
|
||||
"DELETE",
|
||||
);
|
||||
|
||||
const res = await fetch(deletePortal);
|
||||
|
||||
if (!res.ok) throw new Error(res.statusText);
|
||||
|
||||
const feedbackUrl = await res.json();
|
||||
|
||||
return feedbackUrl.response as string;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user