Merge branch 'develop' of github.com:Frappet/hrms-api-org into develop
This commit is contained in:
commit
54554d140e
3 changed files with 52 additions and 4 deletions
|
|
@ -7050,7 +7050,7 @@ export class OrganizationController extends Controller {
|
||||||
orgRootId: orgRoot.id,
|
orgRootId: orgRoot.id,
|
||||||
orgRootDnaId: orgRoot.ancestorDNA,
|
orgRootDnaId: orgRoot.ancestorDNA,
|
||||||
orgLevel: 1,
|
orgLevel: 1,
|
||||||
orgName: `${orgChild1.orgChild1Name}/${orgRoot.orgRootName}`,
|
orgName: `${orgChild1.orgChild1Name} ${orgRoot.orgRootName}`,
|
||||||
orgTreeName: orgChild1.orgChild1Name,
|
orgTreeName: orgChild1.orgChild1Name,
|
||||||
orgTreeShortName: orgChild1.orgChild1ShortName,
|
orgTreeShortName: orgChild1.orgChild1ShortName,
|
||||||
orgTreeCode: orgChild1.orgChild1Code,
|
orgTreeCode: orgChild1.orgChild1Code,
|
||||||
|
|
@ -7178,7 +7178,7 @@ export class OrganizationController extends Controller {
|
||||||
orgRootId: orgChild1.id,
|
orgRootId: orgChild1.id,
|
||||||
orgRootDnaId: orgChild1.ancestorDNA,
|
orgRootDnaId: orgChild1.ancestorDNA,
|
||||||
orgLevel: 2,
|
orgLevel: 2,
|
||||||
orgName: `${orgChild2.orgChild2Name}/${orgChild1.orgChild1Name}/${orgRoot.orgRootName}`,
|
orgName: `${orgChild2.orgChild2Name} ${orgChild1.orgChild1Name} ${orgRoot.orgRootName}`,
|
||||||
orgTreeName: orgChild2.orgChild2Name,
|
orgTreeName: orgChild2.orgChild2Name,
|
||||||
orgTreeShortName: orgChild2.orgChild2ShortName,
|
orgTreeShortName: orgChild2.orgChild2ShortName,
|
||||||
orgTreeCode: orgChild2.orgChild2Code,
|
orgTreeCode: orgChild2.orgChild2Code,
|
||||||
|
|
@ -7316,7 +7316,7 @@ export class OrganizationController extends Controller {
|
||||||
orgRootId: orgChild2.id,
|
orgRootId: orgChild2.id,
|
||||||
orgRootDnaId: orgChild2.ancestorDNA,
|
orgRootDnaId: orgChild2.ancestorDNA,
|
||||||
orgLevel: 3,
|
orgLevel: 3,
|
||||||
orgName: `${orgChild3.orgChild3Name}/${orgChild2.orgChild2Name}/${orgChild1.orgChild1Name}/${orgRoot.orgRootName}`,
|
orgName: `${orgChild3.orgChild3Name} ${orgChild2.orgChild2Name} ${orgChild1.orgChild1Name} ${orgRoot.orgRootName}`,
|
||||||
orgTreeName: orgChild3.orgChild3Name,
|
orgTreeName: orgChild3.orgChild3Name,
|
||||||
orgTreeShortName: orgChild3.orgChild3ShortName,
|
orgTreeShortName: orgChild3.orgChild3ShortName,
|
||||||
orgTreeCode: orgChild3.orgChild3Code,
|
orgTreeCode: orgChild3.orgChild3Code,
|
||||||
|
|
@ -7461,7 +7461,7 @@ export class OrganizationController extends Controller {
|
||||||
orgRootId: orgChild3.id,
|
orgRootId: orgChild3.id,
|
||||||
orgRootDnaId: orgChild3.ancestorDNA,
|
orgRootDnaId: orgChild3.ancestorDNA,
|
||||||
orgLevel: 4,
|
orgLevel: 4,
|
||||||
orgName: `${orgChild4.orgChild4Name}/${orgChild3.orgChild3Name}/${orgChild2.orgChild2Name}/${orgChild1.orgChild1Name}/${orgRoot.orgRootName}`,
|
orgName: `${orgChild4.orgChild4Name} ${orgChild3.orgChild3Name} ${orgChild2.orgChild2Name} ${orgChild1.orgChild1Name} ${orgRoot.orgRootName}`,
|
||||||
orgTreeName: orgChild4.orgChild4Name,
|
orgTreeName: orgChild4.orgChild4Name,
|
||||||
orgTreeShortName: orgChild4.orgChild4ShortName,
|
orgTreeShortName: orgChild4.orgChild4ShortName,
|
||||||
orgTreeCode: orgChild4.orgChild4Code,
|
orgTreeCode: orgChild4.orgChild4Code,
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ import {
|
||||||
enableStatus,
|
enableStatus,
|
||||||
getUserByUsername,
|
getUserByUsername,
|
||||||
changeUserPassword,
|
changeUserPassword,
|
||||||
|
resetPassword
|
||||||
} 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";
|
||||||
|
|
@ -828,4 +829,19 @@ export class KeycloakController extends Controller {
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Post("user/reset-password")
|
||||||
|
async forgetPassword(
|
||||||
|
@Request() request: { user: { sub: string; preferred_username: string } },
|
||||||
|
@Body()
|
||||||
|
body: {
|
||||||
|
username: string;
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
const result = await resetPassword(body.username);
|
||||||
|
if (!result) {
|
||||||
|
throw new Error("Failed. Cannot change password.");
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -761,3 +761,35 @@ export async function changeUserPassword(userId: string, newPassword: string) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Function to reset password
|
||||||
|
export async function resetPassword(username: string) {
|
||||||
|
try {
|
||||||
|
const users = await fetch(`${KC_URL}/admin/realms/${KC_REALMS}/users?email=${encodeURIComponent(username)}`, {
|
||||||
|
headers: {
|
||||||
|
"authorization": `Bearer ${await getToken()}`,
|
||||||
|
"content-type": `application/json`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if(!users.ok) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const usersData = await users.json();
|
||||||
|
const userId = usersData[0].id;
|
||||||
|
const resetResponse = await fetch(`${KC_URL}/admin/realms/${KC_REALMS}/users/${userId}/execute-actions-email`, {
|
||||||
|
method: "PUT",
|
||||||
|
headers: {
|
||||||
|
"Authorization": `Bearer ${await getToken()}`,
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
},
|
||||||
|
body: JSON.stringify(["UPDATE_PASSWORD"])
|
||||||
|
});
|
||||||
|
if (!resetResponse.ok) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return { message: "Password reset email sent" };
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error triggering password reset:", error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue