feature/mobile-layout (#431)

* lazy load cards

* shopping list recipe search bug

* admin layout fluid

* site loader

* username support

* mobile tabs

* set username at signup

* update user tests

* patch bug on shopping list

* public mealplan links

* support link (I'm a monster)

* icon only on mobile

* padding

Co-authored-by: hay-kot <hay-kot@pm.me>
This commit is contained in:
Hayden
2021-05-25 21:01:22 -07:00
committed by GitHub
parent 8f8127a5fc
commit 822663905d
33 changed files with 273 additions and 119 deletions

View File

@@ -28,8 +28,13 @@ def create_file_token(file_path: Path) -> bool:
def authenticate_user(session, email: str, password: str) -> UserInDB:
user: UserInDB = db.users.get(session, email, "email", any_case=True)
if not user:
user = db.users.get(session, email, "username", any_case=True)
if not user:
return False
print(user)
if not verify_password(password, user.password):
return False
return user

View File

@@ -22,6 +22,11 @@ class User(SqlAlchemyBase, BaseMixins):
__tablename__ = "users"
id = Column(Integer, primary_key=True)
full_name = Column(String, index=True)
username = Column(
String,
index=True,
unique=True,
)
email = Column(String, unique=True, index=True)
password = Column(String)
group_id = Column(Integer, ForeignKey("groups.id"))
@@ -32,16 +37,7 @@ class User(SqlAlchemyBase, BaseMixins):
)
def __init__(
self,
session,
full_name,
email,
password,
group: str = settings.DEFAULT_GROUP,
admin=False,
id=None,
*args,
**kwargs
self, session, full_name, email, password, group: str = settings.DEFAULT_GROUP, admin=False, **_
) -> None:
group = group or settings.DEFAULT_GROUP
@@ -51,12 +47,19 @@ class User(SqlAlchemyBase, BaseMixins):
self.admin = admin
self.password = password
def update(self, full_name, email, group, admin, session=None, id=None, password=None, *args, **kwargs):
if self.username is None:
self.username = full_name
def update(self, full_name, email, group, admin, username, session=None, id=None, password=None, *args, **kwargs):
self.username = username
self.full_name = full_name
self.email = email
self.group = Group.get_ref(session, group)
self.admin = admin
if self.username is None:
self.username = full_name
if password:
self.password = password

View File

@@ -23,6 +23,16 @@ def get_all_meals(
return db.groups.get_meals(session, current_user.group)
@router.get("/{id}", response_model=MealPlanOut)
def get_meal_plan(
id,
session: Session = Depends(generate_session),
):
""" Returns a single Meal Plan from the Database """
return db.meals.get(session, id, "uid")
@router.post("/create", status_code=status.HTTP_201_CREATED)
def create_meal_plan(
background_tasks: BackgroundTasks,

View File

@@ -23,7 +23,7 @@ def get_token(
email = data.username
password = data.password
user = authenticate_user(session, email, password)
user: UserInDB = authenticate_user(session, email, password)
if not user:
background_tasks.add_task(
@@ -34,7 +34,7 @@ def get_token(
headers={"WWW-Authenticate": "Bearer"},
)
access_token = security.create_access_token(dict(sub=email))
access_token = security.create_access_token(dict(sub=user.email))
return {"access_token": access_token, "token_type": "bearer"}

View File

@@ -43,6 +43,7 @@ class GroupBase(CamelModel):
class UserBase(CamelModel):
username: Optional[str]
full_name: Optional[str] = None
email: constr(to_lower=True, strip_whitespace=True)
admin: bool
@@ -59,6 +60,7 @@ class UserBase(CamelModel):
}
schema_extra = {
"username": "ChangeMe",
"fullName": "Change Me",
"email": "changeme@email.com",
"group": settings.DEFAULT_GROUP,