feat(auth): admin user updates added
if a password change happens then an email will be sent to the user.
This commit is contained in:
13
frontend/src/utils/formStuff/options/userformOptions.tsx
Normal file
13
frontend/src/utils/formStuff/options/userformOptions.tsx
Normal file
@@ -0,0 +1,13 @@
|
||||
import { formOptions } from "@tanstack/react-form";
|
||||
|
||||
export const userFormOptions = (user: any) => {
|
||||
return formOptions({
|
||||
defaultValues: {
|
||||
username: user.username,
|
||||
password: "",
|
||||
email: user.email,
|
||||
//hobbies: [],
|
||||
},
|
||||
// } as Person,
|
||||
});
|
||||
};
|
||||
27
frontend/src/utils/passwordGen.ts
Normal file
27
frontend/src/utils/passwordGen.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
export const generatePassword = (length: number) => {
|
||||
const uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
const lowercase = "abcdefghijklmnopqrstuvwxyz";
|
||||
const numbers = "0123456789";
|
||||
const symbols = "!@#$%&()_+-={}:,.<>?/"; // Safe symbol list
|
||||
|
||||
// Ensure the password contains at least one of each required type
|
||||
let password: any = [
|
||||
uppercase[Math.floor(Math.random() * uppercase.length)],
|
||||
lowercase[Math.floor(Math.random() * lowercase.length)],
|
||||
numbers[Math.floor(Math.random() * numbers.length)],
|
||||
symbols[Math.floor(Math.random() * symbols.length)],
|
||||
];
|
||||
|
||||
// Fill the rest of the password with random characters from all sets
|
||||
const allCharacters = uppercase + lowercase;
|
||||
for (let i = password.length; i < length; i++) {
|
||||
password.push(
|
||||
allCharacters[Math.floor(Math.random() * allCharacters.length)]
|
||||
);
|
||||
}
|
||||
|
||||
// Shuffle the password to avoid predictable patterns
|
||||
password = password.sort(() => Math.random() - 0.5).join("");
|
||||
|
||||
return password;
|
||||
};
|
||||
26
frontend/src/utils/querys/admin/users.tsx
Normal file
26
frontend/src/utils/querys/admin/users.tsx
Normal file
@@ -0,0 +1,26 @@
|
||||
import { queryOptions } from "@tanstack/react-query";
|
||||
import axios from "axios";
|
||||
|
||||
export function getUsers() {
|
||||
const token = localStorage.getItem("auth_token");
|
||||
return queryOptions({
|
||||
queryKey: ["getUsers"],
|
||||
queryFn: () => fetchUsers(token),
|
||||
enabled: !!token, // Prevents query if token is null
|
||||
staleTime: 1000,
|
||||
//refetchInterval: 2 * 2000,
|
||||
refetchOnWindowFocus: true,
|
||||
});
|
||||
}
|
||||
|
||||
const fetchUsers = async (token: string | null) => {
|
||||
const { data } = await axios.get(`/api/auth/allusers`, {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
// if we are not localhost ignore the devDir setting.
|
||||
//const url: string = window.location.host.split(":")[0];
|
||||
return data.data ?? [];
|
||||
};
|
||||
Reference in New Issue
Block a user