removed secrets from the code (reom from chatgpt)
This commit is contained in:
+21
-5
@@ -1,25 +1,41 @@
|
||||
from lapp import create_app
|
||||
import os
|
||||
import secrets
|
||||
import sqlalchemy as sa
|
||||
from models import db, User, ListOfItems, Shared, Item, Group
|
||||
|
||||
def initial_secret(env_name):
|
||||
return os.environ.get(env_name) or secrets.token_urlsafe(18)
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = create_app()
|
||||
app.app_context().push()
|
||||
query = sa.select(User)
|
||||
users = db.session.scalars(query).all()
|
||||
if len(users) == 0:
|
||||
g = Group(secret="This is the group just for the admin")
|
||||
admin_group_secret = initial_secret("LAPP_INITIAL_ADMIN_GROUP")
|
||||
user_group_secret = initial_secret("LAPP_INITIAL_USER_GROUP")
|
||||
admin_password = initial_secret("LAPP_INITIAL_ADMIN_PASSWORD")
|
||||
user_password = initial_secret("LAPP_INITIAL_USER_PASSWORD")
|
||||
|
||||
g = Group(secret=admin_group_secret)
|
||||
db.session.add(g)
|
||||
g = Group(secret="GroupForIgnaceAndLoversThatDoGroceries")
|
||||
g = Group(secret=user_group_secret)
|
||||
db.session.add(g)
|
||||
admin = User(name="admin", group_id=1, is_admin=True, is_approved=True, is_private=True)
|
||||
admin.set_password("suy2025")
|
||||
admin.set_password(admin_password)
|
||||
db.session.add(admin)
|
||||
user1 = User(name="ignace", group_id=2, is_admin=False, is_approved=True)
|
||||
user1.set_password("xanderj2")
|
||||
user1.set_password(user_password)
|
||||
db.session.add(user1)
|
||||
db.session.commit()
|
||||
|
||||
print("Created initial credentials:")
|
||||
print(f"admin password: {admin_password}")
|
||||
print(f"admin group secret: {admin_group_secret}")
|
||||
print(f"ignace password: {user_password}")
|
||||
print(f"ignace group secret: {user_group_secret}")
|
||||
|
||||
lol1 = ListOfItems(owner_user_id = user1.id, name="Supermarkt", is_active=True)
|
||||
db.session.add(lol1)
|
||||
lol2 = ListOfItems(owner_user_id = user1.id, name="Klusjes", is_active=True)
|
||||
@@ -35,4 +51,4 @@ if __name__ == "__main__":
|
||||
db.session.add(item3)
|
||||
db.session.add(item4)
|
||||
|
||||
db.session.commit()
|
||||
db.session.commit()
|
||||
|
||||
Reference in New Issue
Block a user