Skip to content

Commit

Permalink
Merge branch 'main' into feat-email-checkout
Browse files Browse the repository at this point in the history
  • Loading branch information
jschiel committed Feb 26, 2023
2 parents 452dbdc + 8743a47 commit 79e5e33
Show file tree
Hide file tree
Showing 39 changed files with 24,210 additions and 18,133 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/buildBackend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
uses: docker/build-push-action@v2
with:
push: false
tags: fius/drinklistv4-backend:dev
file: backend/Dockerfile
context: ./backend
platforms: linux/amd64,linux/arm/v7
platforms: linux/amd64,linux/arm/v7
1 change: 1 addition & 0 deletions .github/workflows/buildFrontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
uses: docker/build-push-action@v2
with:
push: false
tags: fius/drinklistv4-frontend:dev
file: frontend/Dockerfile
context: ./frontend
platforms: linux/amd64,linux/arm/v7
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ You need to mount the file [`env.js`](frontend/public/environment/env.js) in t
* Defaults to: `false`
* `DB_CONNECTION`
* Path to sqlite file or connection string for postress etc.
* Defaults to: `sqlite:///database.db`
* Defaults to: `sqlite:///db/database.db`
* Note the sqlite file is relative to the `instance` directory, meaning the actual path of the database file starts with `instance/.../*.db`
* The default path is therefore `instance/db/database.db` (inside docker container `/usr/src/app/instance/db/database.db`)
* `ADMIN_USERNAME`
* Username of admin user
* Defaults to: `admin`
Expand Down
4 changes: 2 additions & 2 deletions backend/database/Queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ def change_user_visibility(self, member_id):
user.hidden = not user.hidden
self.session.commit()

def add_user(self, name, money, password, hidden=False):
def add_user(self, name, money, password, alias="", hidden=False):
pw_hash, salt = TokenManager.hashPassword(password)
self.session.add(
Member(name=name, balance=money, password=pw_hash, salt=salt, hidden=hidden))
Member(name=name, balance=money, password=pw_hash, salt=salt, alias=alias, hidden=hidden))
self.session.commit()

def get_drinks(self):
Expand Down
12 changes: 9 additions & 3 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@

token_manager = authenticator.TokenManager()

db = Queries.Queries(sql_database)
with app.app_context():
db = Queries.Queries(sql_database)

taskScheduler = TaskScheduler.TaskScheduler()
taskScheduler.start()
Expand Down Expand Up @@ -262,6 +263,7 @@ def delete(self, member_id):

model = api.model('Add User', {
'name': fields.String(description='Name of the new user', required=True),
'alias': fields.String(description='Alias of the user', required=False),
'money': fields.Float(description='Initial balance of the user', required=True),
'password': fields.String(description='Initial password of user', required=True),
})
Expand All @@ -275,8 +277,12 @@ def post(self):
"""
Add a user
"""
db.add_user(request.json["name"],
request.json["money"], request.json["password"])
if 'alias' in request.json:
db.add_user(request.json["name"],
request.json["money"], request.json["password"], alias=request.json["alias"])
else:
db.add_user(request.json["name"],
request.json["money"], request.json["password"])
return util.build_response("User added")


Expand Down
2 changes: 1 addition & 1 deletion backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ psycopg2
waitress
requests
flask-restx
werkzeug==2.1.2
werkzeug
3 changes: 2 additions & 1 deletion backend/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
app = Flask(__name__)
CORS(app, supports_credentials=True)
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
os.makedirs("instance/db", exist_ok=True)
if os.environ.get("DB_CONNECTION"):
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get("DB_CONNECTION")
else:
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.db'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///db/database.db'

sql_database = SQLAlchemy(app)
Loading

0 comments on commit 79e5e33

Please sign in to comment.