diff --git a/dashboard/src/states/Dashboard/pages/Licenses/components/LicenseDialog/pages/LicenseKey/LicenseKey.jsx b/dashboard/src/states/Dashboard/pages/Licenses/components/LicenseDialog/pages/LicenseKey/LicenseKey.jsx new file mode 100644 index 0000000..4243bfb --- /dev/null +++ b/dashboard/src/states/Dashboard/pages/Licenses/components/LicenseDialog/pages/LicenseKey/LicenseKey.jsx @@ -0,0 +1,27 @@ +import {Button, TextField, Typography} from "@mui/material"; +import {Key} from "@mui/icons-material"; +import {useContext} from "react"; +import {ProjectContext} from "@/states/Dashboard/contexts/Project"; +import {replaceLicenseDefaults} from "./util.js"; + +export const LicenseKey = ({licenseKey, setLicenseKey, goBack}) => { + + const {currentProject} = useContext(ProjectContext); + + const generateKey = () => { + const key = replaceLicenseDefaults(currentProject.defaults.licenseKey); + setLicenseKey(key); + goBack(); + } + + return ( + <> + New key + setLicenseKey(event.target.value)} + InputProps={{startAdornment: }}/> + + + ); +} \ No newline at end of file diff --git a/dashboard/src/states/Dashboard/pages/Licenses/components/LicenseDialog/pages/LicenseKey/index.js b/dashboard/src/states/Dashboard/pages/Licenses/components/LicenseDialog/pages/LicenseKey/index.js new file mode 100644 index 0000000..4bda861 --- /dev/null +++ b/dashboard/src/states/Dashboard/pages/Licenses/components/LicenseDialog/pages/LicenseKey/index.js @@ -0,0 +1 @@ +export {LicenseKey as default} from "./LicenseKey.jsx"; \ No newline at end of file diff --git a/dashboard/src/states/Dashboard/pages/Licenses/components/LicenseDialog/pages/LicenseKey/util.js b/dashboard/src/states/Dashboard/pages/Licenses/components/LicenseDialog/pages/LicenseKey/util.js new file mode 100644 index 0000000..77a4733 --- /dev/null +++ b/dashboard/src/states/Dashboard/pages/Licenses/components/LicenseDialog/pages/LicenseKey/util.js @@ -0,0 +1,41 @@ +export const generateCharacter = () => { + return String.fromCharCode(Math.random() < 0.5 ? Math.floor(Math.random() * 26) + 65 : Math.floor(Math.random() * 26) + 97); +} + +export const generateSpecialCharacter = () => { + const specialChars = "!@#$%^&*()_+-=[]{};':\",./<>?"; + return specialChars[Math.floor(Math.random() * specialChars.length)]; +} + +export const generateAlphaNumeric = () => { + const alphanumericChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + return alphanumericChars[Math.floor(Math.random() * alphanumericChars.length)]; +} + +export const generateRandom = () => { + const allChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+-=[]{};':\",./<>?"; + return allChars[Math.floor(Math.random() * allChars.length)]; +} + +export const replaceLicenseDefaults = (defaultKey) => { + return defaultKey.split('').map(char => { + switch (char) { + case 'N': + return String(Math.floor(Math.random() * 10)); + case 'C': + return generateCharacter(); + case 'L': + return String.fromCharCode(Math.floor(Math.random() * 26) + 97); + case 'U': + return String.fromCharCode(Math.floor(Math.random() * 26) + 65); + case 'S': + return generateSpecialCharacter(); + case 'A': + return generateAlphaNumeric(); + case 'R': + return generateRandom(); + default: + return char; + } + }).join(''); +} \ No newline at end of file