🩹 Add password verification

This commit is contained in:
Brian Wiborg 2025-09-27 16:50:15 +02:00
parent 20a826e8c0
commit 3071d76ae1
No known key found for this signature in database

View file

@ -16,13 +16,13 @@ Find your loaded project singleton via identifier: `p`
@app.command()
def startproject(name: str):
"""Create a new OhMyAPI project in the given directory"""
"""Create a new OhMyAPI project in the given directory."""
scaffolding.startproject(name)
@app.command()
def startapp(app_name: str, root: str = "."):
"""Create a new app with the given name in your OhMyAPI project"""
"""Create a new app with the given name in your OhMyAPI project."""
scaffolding.startapp(app_name, root)
@ -93,6 +93,10 @@ def migrate(app: str = "*", root: str = "."):
@app.command()
def createsuperuser(root: str = "."):
"""Create a superuser in the DB.
This requires the presence of `ohmyapi_auth` in your INSTALLED_APPS to work.
"""
project_path = Path(root).resolve()
project = runtime.Project(project_path)
if not project.is_app_installed("ohmyapi_auth"):
@ -103,9 +107,14 @@ def createsuperuser(root: str = "."):
import ohmyapi_auth
email = input("E-Mail: ")
username = input("Username: ")
password = getpass("Password: ")
password1, password2 = "foo", "bar"
while password1 != password2:
password1 = getpass("Password: ")
password2 = getpass("Repeat Password: ")
if password1 != password2:
print("Passwords didn't match!")
user = ohmyapi_auth.models.User(email=email, username=username, is_staff=True, is_admin=True)
user.set_password(password)
user.set_password(password1)
asyncio.run(project.init_orm())
asyncio.run(user.save())
asyncio.run(project.close_orm())