get user from .env config

This commit is contained in:
Cayo Puigdefabregas 2023-07-21 17:21:08 +02:00
parent 0b0d9edaad
commit 9ff20740dd
1 changed files with 9 additions and 8 deletions

View File

@ -1,6 +1,7 @@
from uuid import uuid4
from boltons.urlutils import URL
from decouple import config
from ereuse_devicehub.db import db
from ereuse_devicehub.resources.agent.models import Person
@ -13,6 +14,9 @@ class InitDatas:
super().__init__()
self.app = app
self.schema = app.config.get('DB_SCHEMA')
self.email = config('EMAIL_DEMO')
self.name = self.email.split('@')[0] if self.email else None
self.password = config('PASSWORD_DEMO')
self.app.cli.command(
'initdata', short_help='Save a minimum structure of datas.'
)(self.run)
@ -29,12 +33,9 @@ class InitDatas:
db.session.add(inv)
db.session.commit()
email = 'user@dhub.com'
password = '1234'
name = 'user'
user = User(email=email, password=password)
user.individuals.add(Person(name=name))
if self.email:
user = User(email=self.email, password=self.password)
user.individuals.add(Person(name=self.name))
db.session.add(user)
db.session.commit()