Commit de3ea93c authored by Ahmad Anvari's avatar Ahmad Anvari

Add balance to user model

parent 124c18d3
...@@ -12,7 +12,8 @@ class User(Model): ...@@ -12,7 +12,8 @@ class User(Model):
first_name=dictionary["first_name"], first_name=dictionary["first_name"],
last_name=dictionary["last_name"], last_name=dictionary["last_name"],
email=dictionary["email"], email=dictionary["email"],
hashed_password=dictionary["hashed_password"] hashed_password=dictionary["hashed_password"],
balance=dictionary["balance"],
) )
u.__id = str(dictionary["_id"]) u.__id = str(dictionary["_id"])
return u return u
...@@ -29,15 +30,18 @@ class User(Model): ...@@ -29,15 +30,18 @@ class User(Model):
res["email"] = self.__email res["email"] = self.__email
if self.__hashed_password is not None: if self.__hashed_password is not None:
res["hashed_password"] = self.__hashed_password res["hashed_password"] = self.__hashed_password
if self.__balance is not None:
res["balance"] = self.__balance
return res return res
def __init__(self, first_name, last_name, email, hashed_password): def __init__(self, first_name, last_name, email, hashed_password, balance):
self.__id = None self.__id = None
self.__first_name = first_name self.__first_name = first_name
self.__last_name = last_name self.__last_name = last_name
self.__email = email self.__email = email
self.__hashed_password = hashed_password self.__hashed_password = hashed_password
self.__balance = balance
@staticmethod @staticmethod
def get_collection(): def get_collection():
...@@ -70,3 +74,6 @@ class User(Model): ...@@ -70,3 +74,6 @@ class User(Model):
def compare_password(self, new_password): def compare_password(self, new_password):
new_hashed_password = hashlib.md5(new_password.encode()).hexdigest() new_hashed_password = hashlib.md5(new_password.encode()).hexdigest()
return self.__hashed_password == new_hashed_password return self.__hashed_password == new_hashed_password
def __repr__(self):
return self.__email
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment