no message
This commit is contained in:
parent
0b8f9b6c23
commit
a48656bdc9
2 changed files with 22 additions and 26 deletions
|
|
@ -30,7 +30,7 @@ import {
|
||||||
getRoleMappings,
|
getRoleMappings,
|
||||||
getUserCount,
|
getUserCount,
|
||||||
enableStatus,
|
enableStatus,
|
||||||
getUserByUsername
|
getUserByUsername,
|
||||||
} from "../keycloak";
|
} from "../keycloak";
|
||||||
import { AppDataSource } from "../database/data-source";
|
import { AppDataSource } from "../database/data-source";
|
||||||
import { Profile } from "../entities/Profile";
|
import { Profile } from "../entities/Profile";
|
||||||
|
|
@ -97,15 +97,21 @@ export class KeycloakController extends Controller {
|
||||||
profileId?: string;
|
profileId?: string;
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
const userId = await createUser(body.username, body.password, {
|
const checkUser = await getUserByUsername(body.username);
|
||||||
firstName: body.firstName,
|
let userId: any = "";
|
||||||
lastName: body.lastName,
|
if (checkUser.length == 0) {
|
||||||
// email: body.email,
|
userId = await createUser(body.username, body.password, {
|
||||||
});
|
firstName: body.firstName,
|
||||||
|
lastName: body.lastName,
|
||||||
if (typeof userId !== "string") {
|
// email: body.email,
|
||||||
throw new Error(userId.errorMessage);
|
});
|
||||||
|
if (typeof userId !== "string") {
|
||||||
|
throw new Error(userId.errorMessage);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
userId = checkUser[0].id;
|
||||||
}
|
}
|
||||||
|
|
||||||
const list = await getRoles();
|
const list = await getRoles();
|
||||||
if (!Array.isArray(list)) throw new Error("Failed. Cannot get role(s) data from the server.");
|
if (!Array.isArray(list)) throw new Error("Failed. Cannot get role(s) data from the server.");
|
||||||
const result = await addUserRoles(
|
const result = await addUserRoles(
|
||||||
|
|
@ -709,7 +715,7 @@ export class KeycloakController extends Controller {
|
||||||
roles: rolesData,
|
roles: rolesData,
|
||||||
};
|
};
|
||||||
|
|
||||||
return userDataWithRoles
|
return userDataWithRoles;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put("user/{userId}/enableStatus/{status}") //#log?
|
@Put("user/{userId}/enableStatus/{status}") //#log?
|
||||||
|
|
|
||||||
|
|
@ -227,14 +227,7 @@ export async function getUserListOrg(first = "", max = "", search = "", userIds:
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getUserCountOrg(first = "", max = "", search = "", userIds: string[] = []) {
|
export async function getUserCountOrg(first = "", max = "", search = "", userIds: string[] = []) {
|
||||||
console.log(userIds);
|
|
||||||
const userIdsParam = userIds.join(",");
|
const userIdsParam = userIds.join(",");
|
||||||
console.log(userIdsParam);
|
|
||||||
console.log("xxxxxxxxxxxxxxxxx");
|
|
||||||
console.log(
|
|
||||||
`${KC_URL}/admin/realms/${KC_REALMS}/users/count?first=${first || "0"}&max=${max || "-1"}${search ? `&search=${search}` : ""}${userIdsParam && userIdsParam != "" ? `&id=${userIdsParam}` : ""}`,
|
|
||||||
);
|
|
||||||
console.log("aaaaaaaaaaaaaaaaaa");
|
|
||||||
const res = await fetch(
|
const res = await fetch(
|
||||||
`${KC_URL}/admin/realms/${KC_REALMS}/users/count?first=${first || "0"}&max=${max || "-1"}${search ? `&search=${search}` : ""}${userIdsParam && userIdsParam != "" ? `&id=${userIdsParam}` : ""}`,
|
`${KC_URL}/admin/realms/${KC_REALMS}/users/count?first=${first || "0"}&max=${max || "-1"}${search ? `&search=${search}` : ""}${userIdsParam && userIdsParam != "" ? `&id=${userIdsParam}` : ""}`,
|
||||||
{
|
{
|
||||||
|
|
@ -497,18 +490,15 @@ export async function getUserRoles(userId: string) {
|
||||||
* @returns true if success, false otherwise.
|
* @returns true if success, false otherwise.
|
||||||
*/
|
*/
|
||||||
export async function addUserRoles(userId: string, roles: { id: string; name: string }[]) {
|
export async function addUserRoles(userId: string, roles: { id: string; name: string }[]) {
|
||||||
const res = await fetch(
|
const res = await fetch(`${KC_URL}/admin/realms/${KC_REALMS}/users/${userId}`, {
|
||||||
`${KC_URL}/admin/realms/${KC_REALMS}/users/${userId}`,
|
// prettier-ignore
|
||||||
{
|
headers: {
|
||||||
// prettier-ignore
|
|
||||||
headers: {
|
|
||||||
"authorization": `Bearer ${await getToken()}`,
|
"authorization": `Bearer ${await getToken()}`,
|
||||||
"content-type": `application/json`,
|
"content-type": `application/json`,
|
||||||
},
|
},
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify(roles),
|
body: JSON.stringify(roles),
|
||||||
},
|
}).catch((e) => console.log(e));
|
||||||
).catch((e) => console.log(e));
|
|
||||||
|
|
||||||
if (!res) return false;
|
if (!res) return false;
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue