Skip to content

Commit

Permalink
Quick UI changes (#449)
Browse files Browse the repository at this point in the history
* Implement register admin user

* Fix frontend errors

* Fix frontend issues

* center button

* Add generate recoverycode

* Updates to register modal

* Updates to register modal

* Remove models

* Remove models

* Clean up

* Cleanup

* RESET password implementation

* Update ConfirmationModal code

* Update ConfirmationModal code

* Add code to reset password in backend

* Cleanup

* Fix confirmation modal
  • Loading branch information
lickem22 authored Oct 16, 2024
1 parent d551c52 commit 15a80b2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
39 changes: 31 additions & 8 deletions admin_app/src/app/login/components/RegisterModal.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import CheckIcon from "@mui/icons-material/Check";
import ContentCopyIcon from "@mui/icons-material/ContentCopy";
import LockOutlinedIcon from "@mui/icons-material/LockOutlined";
import {
Alert,
Expand Down Expand Up @@ -190,14 +192,18 @@ const ConfirmationModal = ({
onClose: () => void;
recoveryCodes: string[];
}) => {
const [copySuccess, setCopySuccess] = useState("");
const [isClicked, setIsClicked] = useState(false);

const handleClose = () => {
setIsClicked(false);
onClose();
};

const handleCopyToClipboard = async () => {
try {
await navigator.clipboard.writeText(recoveryCodes.join("\n"));
setCopySuccess("Copied!");
} catch (err) {
setCopySuccess("Failed to copy!");
console.error("Failed to copy recovery codes: ", err);
}
};

Expand All @@ -216,15 +222,32 @@ const ConfirmationModal = ({
value={recoveryCodes ? recoveryCodes.join("\n") : ""}
InputProps={{
readOnly: true,
sx: {
textAlign: "center",
},
}}
inputProps={{
style: { textAlign: "center" },
}}
/>
<Button onClick={handleCopyToClipboard} color="primary">
Copy Recovery Codes
</Button>
{copySuccess && <p>{copySuccess}</p>}

<Box display="flex" justifyContent="center" mt={2}>
<Button
variant="contained"
onClick={() => {
handleCopyToClipboard();
setIsClicked(true);
}}
startIcon={isClicked ? <CheckIcon /> : <ContentCopyIcon />}
style={{ paddingLeft: "20px", paddingRight: "20px" }}
>
{isClicked ? "Copied" : "Copy"}
</Button>
</Box>
</DialogContent>

<DialogActions sx={{ marginBottom: 1, marginRight: 1 }}>
<Button onClick={onClose} color="primary">
<Button onClick={handleClose} color="primary" variant="contained" autoFocus>
Back to Login
</Button>
</DialogActions>
Expand Down
6 changes: 3 additions & 3 deletions core_backend/add_new_data_to_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import pandas as pd
import urllib3
from add_users_to_db import ADMIN_API_KEY
from app.config import (
LITELLM_API_KEY,
LITELLM_ENDPOINT,
Expand Down Expand Up @@ -73,7 +72,7 @@
"--csv", help="Path to the CSV containing example questions ", required=True
)
parser.add_argument("--host", help="Your hosted AAQ url", required=True)
parser.add_argument("--api-key", help="Your AAQ API key", required=False)
parser.add_argument("--api-key", help="Your AAQ API key", required=True)
parser.add_argument(
"--nb-workers",
help="Number of workers to use for parallel processing",
Expand All @@ -94,6 +93,7 @@
help="Subset of the data to use for testing",
required=False,
)

args = parser.parse_args()


Expand Down Expand Up @@ -392,7 +392,7 @@ def update_date_of_contents(date: datetime) -> None:
if __name__ == "__main__":
HOST = args.host
NB_WORKERS = int(args.nb_workers) if args.nb_workers else 8
API_KEY = args.api_key if args.api_key else ADMIN_API_KEY
API_KEY = args.api_key

start_date_string = args.start_date if args.start_date else "01-08-23"
end_date_string = args.end_date if args.end_date else None
Expand Down
9 changes: 1 addition & 8 deletions core_backend/app/user_tools/routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,7 @@ async def reset_password(
username=user.username, asession=asession
)

is_recovery_code_correct = user.recovery_code in user_to_update.recovery_codes

if not is_recovery_code_correct:
if user.recovery_code not in user_to_update.recovery_codes:
raise HTTPException(status_code=400, detail="Recovery code is incorrect.")
updated_recovery_codes = [
val for val in user_to_update.recovery_codes if val != user.recovery_code
Expand All @@ -173,11 +171,6 @@ async def reset_password(
created_datetime_utc=updated_user.created_datetime_utc,
updated_datetime_utc=updated_user.updated_datetime_utc,
)
except UserAlreadyExistsError as e:
logger.error(f"Error resetting password: {e}")
raise HTTPException(
status_code=400, detail="User with that username already exists."
) from e

except UserNotFoundError as v:
logger.error(f"Error resetting password: {v}")
Expand Down

0 comments on commit 15a80b2

Please sign in to comment.