Skip to content

Commit

Permalink
Merge branch 'DHBW-FN-TIT20:main' into Implementation-Recipe-Frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
screetox authored Feb 11, 2022
2 parents 8dd142b + 2afb377 commit 7865664
Show file tree
Hide file tree
Showing 17 changed files with 138 additions and 48 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ If you **dont** have a PostgreSQL Database start the container:
docker run -p 8080:80 \
-v /essensfindung/app/data \
-e GOOGLE_API_KEY=KEY \
-e SECRET_KEY=KEY \
--name essensfindung \
essensfindung
```
Expand All @@ -53,6 +54,7 @@ If you have a PostgreSQL Database:
```console
docker run -p 8080:80 \
-e GOOGLE_API_KEY=KEY \
-e SECRET_KEY=KEY \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=PASSWORD \
-e POSTGRES_SERVER=localhost \
Expand Down Expand Up @@ -114,4 +116,4 @@ To install the requierd dependencies via pip:
```console
pip install -r requirements_dev.txt
```
Here you have to manuel manage the requirements.txt files. Use a fixed versions only.
Here you have to manuel manage the requirements.txt files. Use a fixed versions only.
2 changes: 1 addition & 1 deletion app/db/crud/restaurant.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def create_restaurant(db: Session, rest: scheme_rest.RestaurantBase) -> Restaura
Restaurant: Return if success
"""
try:
db_rest = Restaurant(**rest.dict())
db_rest = Restaurant(place_id=rest.place_id)
db.add(db_rest)
db.commit()
db.refresh(db_rest)
Expand Down
2 changes: 2 additions & 0 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Main entry Point for the Application"""
import logging
import traceback
from logging.handlers import RotatingFileHandler
from pathlib import Path

Expand Down Expand Up @@ -166,6 +167,7 @@ async def general_exception_handler(request: fastapi.Request, exc: Exception):
"""
# TODO: Logging the Errors
print(str(exc))
traceback.print_exc()
print(f"Request-URL: {request.url} ")
return fastapi.responses.RedirectResponse(url=f"/error?err_msg={str(exc)}", status_code=status.HTTP_302_FOUND)

Expand Down
2 changes: 1 addition & 1 deletion app/schemes/scheme_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Restaurant(RestaurantBase):
class RestBewertungBase(BaseModel):
"""BaseClass for the Bewertung"""

comment: str
comment: Optional[str] = ""
rating: Optional[float] = 0


Expand Down
3 changes: 2 additions & 1 deletion app/services/service_res.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,9 @@ def search_for_restaurant(db_session: Session, user: UserBase, user_f: FilterRes
except httpx.HTTPError as error:
raise GoogleApiException("Can't communicate with the Google API") from error

if crud_restaurant.get_restaurant_by_id(db_session, restaurant.place_id):
if not crud_restaurant.get_restaurant_by_id(db_session, restaurant.place_id):
crud_restaurant.create_restaurant(db_session, restaurant)
if not crud_bewertung.get_bewertung_from_user_to_rest(db_session, user, restaurant):
add_assessment(db_session, RestBewertungCreate(person=user, restaurant=restaurant))
return restaurant

Expand Down
Binary file added app/static/img/icons8-checkmark-yes-large.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/static/img/icons8-macos-close-large.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 28 additions & 25 deletions app/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,30 +55,38 @@
max-width: 480px;
}
.img-display {
height: calc(1.625rem + 4.5vw);
height: calc(5.665vw + 2.5rem);
max-height: calc(5.665vw + 2.5rem);
width: auto;
}
.img-display svg {
height: calc(1.625rem + 4.5vw);
height: calc(5.665vw + 2.5rem);
max-height: calc(5.665vw + 2.5rem);
width: auto;
}
@media screen and (min-width: 1200px) {
.img-display {
height: 5rem;
width: auto;
}
.img-display svg {
height: 5rem;
width: auto;
}
}

.trans-03 {
transition: color 0.3s;
}
.transparent {
color: #fff0 !important;
}

.display-sub {
font-size: calc(1.6vw + 0.8rem) !important;
}

@media screen and (min-width: 1200px) {
.display-sub {
font-size: 2rem !important;
}
.img-display {
height: 6.675rem;
}
.img-display svg {
height: 6.675rem;
}
}
</style>
</head>

Expand All @@ -90,9 +98,9 @@

<div class="container-sm align-items-center justify-content-center">
<div class="row justify-content-center">
<div class="col d-flex justify-content-center limit-width">
<div class="text-center d-flex">
<div alt="" class="img-display me-3 mt-2">
<div class="col d-flex justify-content-center">
<div class="text-center d-flex align-items-end">
<div alt="" class="img-display">
<svg version="1.1" viewBox="0 0 67.733 67.733" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<g display="none">
<path d="m4.1698 101.14c-32.485-3.947-60.224-24.884-72.829-54.969-9.2376-22.049-9.2376-47.582 0-69.631 9.1707-21.889 26.707-39.426 48.596-48.596 10.67-4.4702 22.579-6.8991 33.828-6.8991h4.8378l-1.1949 2.0285c-3.5024 5.9456-3.3121 13.545 0.48533 19.382 3.233 4.9692 9.4217 8.5759 14.716 8.5759h1.4804l-1.1798 2.3948c-1.7934 3.6403-2.664 7.1365-2.8737 11.54-0.25556 5.3667 0.62568 9.562 3.0277 14.414 3.1474 6.3577 7.3067 10.517 13.663 13.664 8.6632 4.2888 18.396 4.1803 27.038-0.3013 1.3151-0.68197 2.4264-1.1782 2.4694-1.1028 0.04306 0.075403 0.43804 0.8544 0.87773 1.7311 1.3203 2.6326 3.7578 5.4425 6.0475 6.9715 3.3664 2.248 5.6518 2.9894 9.7761 3.1715 4.0099 0.17706 6.4052-0.32949 9.5502-2.0196 1.6056-0.86283 1.8597-0.91367 2.0594-0.41196 0.47994 1.2058 0.61537 14.713 0.18966 18.917-2.1495 21.224-11.148 40.246-26.12 55.219-14.616 14.616-33.025 23.524-53.588 25.929-5.3434 0.62504-15.687 0.62195-20.857-6e-3zm18.168-15.001c17.422-1.9329 33.397-9.5357 45.53-21.669 11.664-11.664 19.332-27.296 21.492-43.813l0.23675-1.8106-2.7614-0.61198c-5.1613-1.1438-9.6675-3.2847-14.008-6.6552l-1.9857-1.5419-2.0269 0.50637c-3.4097 0.85181-11.742 1.0047-16.005 0.29359-9.6845-1.6156-17.965-5.8571-24.823-12.716-8.8502-8.8502-13.421-20.188-13.2-32.742l0.08111-4.6129-1.5566-1.186c-6.6658-5.079-11.348-12.536-13.179-20.99-0.1835-0.84719-0.33719-0.94748-1.1734-0.76573-26.056 5.6633-47.459 25.022-55.636 50.321-2.8285 8.7508-3.9358 16.681-3.6079 25.839 0.4026 11.247 2.8616 20.892 7.9189 31.061 10.541 21.196 31.202 36.514 54.42 40.348 2.4253 0.40048 5.0447 0.78584 5.8208 0.85636 3.1272 0.28415 11.479 0.21993 14.464-0.11122zm16.525-22.224c-3.4678-0.71014-6.615-3.2692-8.1536-6.6299-2.5163-5.4964 0.17521-12.393 5.8537-14.999 2.3566-1.0816 6.6097-1.0561 9.0902 0.05455 2.2463 1.0057 4.8014 3.5721 5.8549 5.8806 1.1104 2.4332 1.1329 6.6938 0.04788 9.0578-2.1695 4.7271-7.7553 7.6475-12.693 6.6364zm-54.556-8.078c-2.6858-1.0828-4.6476-2.9225-5.9606-5.5895-1.005-2.0415-1.1641-2.7282-1.1641-5.0253 0-2.3026 0.15828-2.9822 1.1761-5.0497 2.1095-4.2851 5.9451-6.4782 10.776-6.1614 9.3724 0.61475 13.967 11.69 7.7287 18.628-2.3138 2.5735-4.5294 3.6098-8.0388 3.76-2.1824 0.09337-3.2065-0.03418-4.517-0.56255zm-9.7705-37.111c-4.4314-0.73434-9.2475-4.4223-11.108-8.5064-3.4338-7.5358-0.32756-16.242 7.1057-19.916 2.2423-1.1082 3.0747-1.3254 5.5843-1.4571 6.7582-0.35471 12.61 3.3148 15.079 9.4558 0.62835 1.563 0.78222 2.6606 0.79124 5.6444 0.010372 3.4324-0.070026 3.8756-1.0959 6.0407-3.0329 6.4011-9.5258 9.8702-16.355 8.7384zm38.629 0.06797c-3.6567-0.91644-5.9358-3.7736-5.9337-7.4388 0.00247-4.3056 3.2186-7.5223 7.5212-7.5223 7.9657 0 10.483 10.756 3.3514 14.318-1.3753 0.68708-3.6043 0.97711-4.9389 0.64264zm-15.967-37.877c-6.4678-2.4525-6.6983-11.522-0.36019-14.17 5.2278-2.1838 11.16 2.3295 10.41 7.9201-0.61797 4.6073-5.8311 7.8492-10.05 6.2495zm96.887-0.53383c-3.2248-1.6847-4.8076-5.2528-3.849-8.6767 1.8817-6.7208 11.22-7.4445 14.159-1.0973 1.8615 4.0206-0.39115 9.0974-4.5954 10.357-2.1258 0.63691-3.6832 0.478-5.7143-0.58307zm-35.764-6.7449c-3.6567-0.91644-5.9358-3.7736-5.9337-7.4388 0.0025-4.3056 3.2186-7.5223 7.5212-7.5223 7.9657 0 10.483 10.756 3.3514 14.318-1.3753 0.68708-3.6043 0.97711-4.9389 0.64264zm8.6552-30.794c-2.6383-1.0128-5.3075-3.7172-6.3079-6.391-2.8056-7.4987 2.5998-15.41 10.529-15.41 6.2252 0 11.289 5.0637 11.289 11.289 0 7.9484-8.0231 13.386-15.51 10.512z"/>
Expand All @@ -108,19 +116,14 @@
</g>
</svg>
</div>
<h1 class="display-1">Essensfinder</h1>
</div>
</div>
</div>
<div class="row justify-content-center">
<div class="col d-flex justify-content-center limit-width" style="max-width: 480px;">
<div class="text-end d-flex">
<div class="img-display me-3 mt-2"></div>
<h1 class="display-1 fs-2">Jetzt Finden. Jetzt Essen.</h1>
<div class="d-flex flex-column ms-3 text-start">
<h1 class="display-1 m-0 lh-1">Essensfinder</h1>
<h1 class="display-1 display-sub m-0 ms-1">Jetzt Finden. Jetzt Essen.</h1>
</div>
</div>
</div>
</div>
<div class="d-flex justify-content-center">
<div class="d-flex justify-content-center my-3">
<a href="/register" class="btn btn-outline-dark m-2">Registrieren</a>
<a href="/signin" class="btn btn-outline-dark m-2">Anmelden</a>
<a href="/main" class="btn btn-outline-dark m-2">Main</a>
Expand Down
37 changes: 37 additions & 0 deletions app/templates/signin/accresponse.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{% extends "shared/layout_singleform.html" %}

{% block content %}


<div class="row justify-content-center">
<div class="text-center mb-3">
{% if success == "True" %}
<h2>Konto Erfolgreich Erstellt</h2>
{% elif success == "False" %}
<h2>Konto Erstellen Fehlgeschlagen</h2>
{% endif %}
</div>
<div class="col-10 limit-width">
{% if success == "True" %}
<img src="/static/img/icons8-checkmark-yes-large.png" alt="" class="mx-auto d-block w-25">
<div class="text-center">
<p class="mt-4">
Melden Sie sich and und finden Sie Essen!
</p>
<a href="/signin" class="btn btn-dark">Anmelden</a>
</div>
{% elif success == "False" %}
<img src="/static/img/icons8-macos-close-large.png" alt="" class="mx-auto d-block w-25">
<div class="text-center">
{% if msg is defined and msg|length > 0 %}
<p class="mt-4">
Fehler: {{ msg }}
</p>
{% endif %}
<a href="/register" class="btn btn-dark mt-3">Erneut Registrieren</a>
</div>
{% endif %}
</div>
</div>

{% endblock %}
2 changes: 1 addition & 1 deletion app/templates/signin/pwchange.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ <h2>Passwort &auml;ndern</h2>
</div>
</div>
<div class="form-actions text-center">
<button type="submit" class="btn btn-dark">Passwort &auml;ndern</button>
<button type="submit" class="btn btn-dark mt-3">Passwort &auml;ndern</button>
</div>
</form>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/templates/signin/pwreset.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ <h2>Passwort zur&uuml;cksetzen</h2>
</div>
</div>
<div class="form-actions text-center">
<button type="submit" class="btn btn-dark">Passwort &auml;ndern</button>
<button type="submit" class="btn btn-dark mt-3">Passwort &auml;ndern</button>
</div>
</form>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/templates/signin/recover.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ <h2>Email Eingeben</h2>
<input type="email" name="emailInput" id="emailInput" class="form-control" required>
</div>
<div class="form-actions text-center">
<button type="submit" class="btn btn-dark">Passwort Zur&uuml;cksetzen</button>
<button type="submit" class="btn btn-dark mt-3">Passwort Zur&uuml;cksetzen</button>
</div>
</form>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/templates/signin/register.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<h2>Registrieren</h2>
</div>
<div class="col-10 limit-width">
<form action="" id="registrationForm" class="needs-validation">
<form action="" method="post" id="registrationForm" class="needs-validation">
<div class="mb-4">
<label for="emailInput" class="form-label mb-1 ms-1">Email:</label>
<input type="email" name="emailInput" id="emailInput" class="form-control" required>
Expand All @@ -32,7 +32,7 @@ <h2>Registrieren</h2>
</label>
</div>
<div class="form-actions text-center">
<button type="submit" class="btn btn-dark">Konto Erstellen</button>
<button type="submit" class="btn btn-dark mt-3">Konto Erstellen</button>
</div>
</form>
</div>
Expand Down
32 changes: 22 additions & 10 deletions app/templates/signin/signin.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,32 @@ <h2>Anmelden</h2>
<div class="col-10 limit-width">
<form method="post">
<div class="mb-3">
<label for="emailInput" class="form-label mb-1 ms-1">Email: ([email protected])</label>
<input type="email" name="emailInput" id="emailInput" class="form-control" required>
<label for="emailInput" class="form-label mb-1 ms-1">Email:</label>
{% if error is defined and error|length > 0 %}
<input type="email" name="emailInput" id="emailInput" placeholder="[email protected]" class="form-control is-invalid" required>
<div class="invalid-feedback">
{{ error }}
</div>
{% else %}
<input type="email" name="emailInput" id="emailInput" placeholder="[email protected]" class="form-control" required>
{% endif %}
</div>
<div class="mb-3">
<label for="passwordInput" class="form-label mb-1 ms-1">Passwort: (password)</label>
<input type="password" name="passwordInput" id="passwordInput" class="form-control" required>
<a href="/recover" class="ms-1 mt-2">Passwort Vergessen?</a>
<label for="passwordInput" class="form-label mb-1 ms-1">Passwort:</label>

{% if error is defined and error|length > 0 %}
<input type="password" name="passwordInput" id="passwordInput" placeholder="password" class="form-control is-invalid" required>
<div class="invalid-feedback">
{{ error }}
</div>
{% else %}
<input type="password" name="passwordInput" id="passwordInput" placeholder="password" class="form-control" required>
{% endif %}

<a href="/recover" class="ms-1 pt-3">Passwort Vergessen?</a>
</div>
<div class="form-actions text-center">
<button type="submit" class="btn btn-dark">Anmelden</button>
<button type="submit" class="btn btn-dark mt-3">Anmelden</button>
</div>
</form>
</div>
Expand All @@ -28,8 +44,4 @@ <h2>Anmelden</h2>
<p>Noch kein Konto? <a href="/register">Hier Registrieren!</a></p>
</div>

{% if error is defined and error|length > 0 %}
<script> alert("{{ error }}"); </script>
{% endif %}

{% endblock %}
3 changes: 2 additions & 1 deletion app/tests/test_restaurant_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ def test_search_for_restaurant(
location=LocationBase(lat="1111", lng="345"),
)

user = create_user(db_session, UserCreate(email="[email protected]", password="geheim"))
user = UserCreate(email="[email protected]", password="geheim")
create_user(db_session, user)

return_res = service_res.search_for_restaurant(db_session, user, filter)
assert return_res == random_res
Expand Down
35 changes: 33 additions & 2 deletions app/views/signin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
from starlette.requests import Request
from starlette.templating import Jinja2Templates

from db.crud.user import create_user
from db.database import get_db
from schemes import exceptions
from schemes.scheme_user import UserCreate
from tools import security
from tools.config import settings

Expand Down Expand Up @@ -45,7 +47,7 @@ def signin(request: Request, error: Optional[str] = ""):
return templates.TemplateResponse("signin/signin.html", {"request": request, "error": error})


@router.post("/signin/", response_class=HTMLResponse)
@router.post("/signin/", response_class=RedirectResponse)
async def login(request: Request, url: Optional[str] = None, db_session: Session = Depends(get_db)):
if not url:
url = "/main"
Expand Down Expand Up @@ -91,7 +93,36 @@ def register(request: Request):

legal = {"tos": tosstring, "privacy": privstring}

return templates.TemplateResponse("signin/register.html", {"request": request, "legal": legal})
data = {"request": request, "legal": legal}
return templates.TemplateResponse("signin/register.html", data)


@router.post("/register/", response_class=RedirectResponse)
async def register_post(request: Request, db_session: Session = Depends(get_db)):
form = await request.form()
email = form.get("emailInput")
password = form.get("passwordInput")

try:
user = UserCreate(email=email, password=password)
create_user(db=db_session, person=user)
return RedirectResponse("/accresp/?success=True", status_code=status.HTTP_302_FOUND)
except exceptions.DuplicateEntry:
return RedirectResponse(
"/accresp/?success=False&msg=User mit der email gibt es bereits", status_code=status.HTTP_302_FOUND
)
except exceptions.DatabaseException:
return RedirectResponse(
"/accresp/?success=False&msg=Probleme mit der Datenbank", status_code=status.HTTP_302_FOUND
)


@router.get("/accresp/", response_class=HTMLResponse)
def account_response(request: Request, msg: Optional[str] = "", success: Optional[str] = ""):
"""Return a response page for account creation, either positive or negative"""
data = {"request": request, "msg": msg, "success": success}
return templates.TemplateResponse("signin/accresponse.html", data)



@router.get("/recover/", response_class=HTMLResponse)
Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ services:
environment:
- TZ=Europe/Berlin
- GOOGLE_API_KEY=CHANGE_TO_KEY
- SECRET_KEY=REALY_REALY_SECRET
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=SAVE_PASSWORD
- POSTGRES_SERVER=db
Expand All @@ -29,4 +30,4 @@ services:
- PUID=1000
- PGID=1000
- POSTGRES_PASSWORD=SAVE_PASSWORD
- POSTGRES_DB=essensfindung
- POSTGRES_DB=essensfindung

0 comments on commit 7865664

Please sign in to comment.