Update + Signup works!
This commit is contained in:
parent
e944df3d7d
commit
ddb984d0cd
app
50
app/main.py
50
app/main.py
@ -49,56 +49,6 @@ async def signup(request: Request):
|
||||
return templates.TemplateResponse("signup.html", {"request": request})
|
||||
|
||||
|
||||
# TODO: Create users routes
|
||||
# User - register/create
|
||||
# User - delete
|
||||
# User - update
|
||||
|
||||
# @app.route("/signup", methods=["GET", "POST"])
|
||||
# def signup():
|
||||
# if request.method == "POST":
|
||||
# username = request.form["username"]
|
||||
# password = request.form["password"]
|
||||
|
||||
# # Verify the password meets requirements
|
||||
# if len(password) < 8:
|
||||
# return {"status": "Password must be at least 8 characters"}
|
||||
# if not any(char.isdigit() for char in password):
|
||||
# return {"status": "Password must contain at least one digit"}
|
||||
# if not any(char.isupper() for char in password):
|
||||
# return {
|
||||
# "status": "Password must contain at least one uppercase letter"
|
||||
# }
|
||||
|
||||
# # Get database session
|
||||
# db = SessionLocal()
|
||||
|
||||
# user = db.query(User).filter(User.username == username).first()
|
||||
# if user:
|
||||
# db.close()
|
||||
# return {"status": "Username not available"}
|
||||
# # Add information to the database
|
||||
# hashed_password = bcrypt.hashpw(
|
||||
# password.encode("utf-8"), bcrypt.gensalt()
|
||||
# ).decode("utf-8")
|
||||
# api_key = "".join(
|
||||
# random.choices(string.ascii_letters + string.digits, k=20)
|
||||
# )
|
||||
# new_user = User(
|
||||
# username=username, password=hashed_password, api_key=api_key
|
||||
# )
|
||||
# db.add(new_user)
|
||||
# db.commit()
|
||||
# db.close()
|
||||
# # Log in the newly created user
|
||||
# flask_user = FlaskUser()
|
||||
# flask_user.id = username
|
||||
# login_user(flask_user)
|
||||
|
||||
# return {"status": "success"}
|
||||
# return render_template("signup.html")
|
||||
|
||||
|
||||
@app.get("/dashboard")
|
||||
async def dashboard(
|
||||
response: Annotated[
|
||||
|
@ -1,5 +1,6 @@
|
||||
from fastapi import APIRouter, status, Path, Depends
|
||||
from fastapi.exception_handlers import HTTPException
|
||||
from fastapi.security import OAuth2PasswordRequestForm
|
||||
from typing import Annotated
|
||||
import string
|
||||
import bcrypt
|
||||
@ -92,15 +93,15 @@ async def update_pass(
|
||||
|
||||
@router.post("/register", summary="Register a new user")
|
||||
async def get_links(
|
||||
login_data: LoginDataSchema,
|
||||
form_data: Annotated[OAuth2PasswordRequestForm, Depends()],
|
||||
db=Depends(get_db),
|
||||
):
|
||||
"""
|
||||
Given the login data (username, password) process the registration of a new
|
||||
user account and return either the user or an error message
|
||||
"""
|
||||
username = login_data.username
|
||||
password = login_data.password
|
||||
username = form_data.username
|
||||
password = form_data.password
|
||||
|
||||
# Make sure the password meets all of the requirements
|
||||
check_password_reqs(password)
|
||||
|
@ -96,8 +96,6 @@
|
||||
body: formData
|
||||
});
|
||||
|
||||
console.log(await response.json());
|
||||
|
||||
if (response.status != 200) {
|
||||
document.getElementById('error').style.display = 'block';
|
||||
} else {
|
||||
|
@ -91,24 +91,21 @@
|
||||
// Prevent default form submission
|
||||
event.preventDefault();
|
||||
|
||||
// Get form data
|
||||
const formData = new FormData(this);
|
||||
|
||||
console.log(formData)
|
||||
|
||||
// Send POST request to /signup containing form data
|
||||
const response = await fetch('/signup', {
|
||||
const response = await fetch('/api/users/register', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
});
|
||||
|
||||
data = await response.json()
|
||||
if (response.status != 200) {
|
||||
const data = await response.json();
|
||||
|
||||
if (data.status != "success") {
|
||||
document.getElementById('error').style.display = 'block';
|
||||
document.getElementById('error').innerText = data.status;
|
||||
} else {
|
||||
window.location.href = '/dashboard';
|
||||
document.getElementById('error').innerText = data.detail;
|
||||
}
|
||||
else {
|
||||
window.location.href = '/login';
|
||||
}
|
||||
});
|
||||
</script>
|
@ -86,7 +86,7 @@ async def get_current_user_from_token(
|
||||
return await get_current_user(token, db=db)
|
||||
|
||||
|
||||
# Backwards kinda of way to get refresh token support
|
||||
# Backwards kind of way to get refresh token support
|
||||
# `refresh_get_current_user` is only called from /refresh
|
||||
# and alerts `get_current_user` that it should expect a refresh token
|
||||
async def refresh_get_current_user(
|
||||
|
Loading…
x
Reference in New Issue
Block a user