Skip to content

Commit

Permalink
[Updates📢] get user by email & improve create user service
Browse files Browse the repository at this point in the history
  • Loading branch information
[esekyi] committed Aug 25, 2024
1 parent fca4583 commit 6a1042e
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions app/services/user_services.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from app.models.user import User
from app import db
from werkzeug.security import generate_password_hash

def get_all_users():
return User.query.all()
Expand All @@ -9,16 +10,34 @@ def get_user_by_id(user_id):
return User.query.get(user_id)


def create_user(username, email, password_hash):
new_user = User(username=username, email=email, password_hash=password_hash)
return new_user
def get_user_by_email(email):
return User.query.filter_by(email=email).first()


def update_user(user, email=None, password_hash=None):
def create_user(first_name, last_name, username, email, password):
password_hash = generate_password_hash(password)
new_user = User(
first_name=first_name,
last_name=last_name,
username=username,
email=email,
password_hash=password_hash
)
db.session.add(new_user)
db.session.commit()
return new_user


def update_user(user, email=None, password=None, first_name=None, last_name=None):
if email:
user.email = email
if password_hash:
if password:
password_hash = generate_password_hash(password)
user.password_hash = password_hash
if first_name:
user.first_name = first_name
if last_name:
user.last_name = last_name
db.session.commit()


Expand Down

0 comments on commit 6a1042e

Please sign in to comment.