2626from typing import Optional
2727
2828import Geohash
29+ from PyMatcha .models .like import Like
30+ from PyMatcha .models .match import Match
2931from PyMatcha .models .report import Report
3032from PyMatcha .models .tag import Tag
3133from PyMatcha .models .view import View
@@ -60,12 +62,6 @@ class User(Model):
6062 confirmed_on = Field (datetime .datetime , fmt = "%Y-%m-%d %H:%M:%S" )
6163 previous_reset_token = Field (str )
6264
63- def before_init (self , data ):
64- pass
65- # Not used, use User.create and password will be hashed.
66- # if "password" in data:
67- # self.password.value = hash_password(data["password"])
68-
6965 def check_password (self , password : str ) -> bool :
7066 logging .debug ("Checking password again {} hashed password" .format (self .id ))
7167 _hash , salt = self .password .split (":" )
@@ -166,7 +162,7 @@ def register(email: str, username: str, password: str, first_name: str, last_nam
166162 except ValueError :
167163 pass
168164 else :
169- logging .warning ("Email {} taken" .format (email ))
165+ logging .debug ("Email {} taken" .format (email ))
170166 raise ConflictError ("Email {} taken" .format (email ), "Use another email" )
171167
172168 # Check username availability
@@ -330,7 +326,7 @@ def get_likes_received(self):
330326 likes = c .fetchall ()
331327 like_list = []
332328 for like in likes :
333- like_list .append (Report (like ))
329+ like_list .append (Like (like ))
334330 return like_list
335331
336332 def get_likes_sent (self ):
@@ -351,7 +347,7 @@ def get_likes_sent(self):
351347 likes = c .fetchall ()
352348 like_list = []
353349 for like in likes :
354- like_list .append (Report (like ))
350+ like_list .append (Like (like ))
355351 return like_list
356352
357353 def already_likes (self , liked_id : int ) -> bool :
@@ -371,6 +367,26 @@ def already_likes(self, liked_id: int) -> bool:
371367 value = next (iter (result .values ()))
372368 return bool (value )
373369
370+ def get_matches (self ):
371+ logging .debug ("Getting all matches for user {}" .format (self .id ))
372+ with self .db .cursor () as c :
373+ c .execute (
374+ """
375+ SELECT matches.id as id, matches.user_1 as user_1,
376+ matches.user_2 as user_2, matches.dt_matched as dt_matched
377+ FROM users
378+ INNER JOIN matches on users.id = matches.user_1 or users.id = matches.user_2
379+ WHERE users.id = CAST({} AS UNSIGNED)
380+ """ .format (
381+ self .id
382+ )
383+ )
384+ matches = c .fetchall ()
385+ match_list = []
386+ for match in matches :
387+ match_list .append (Match (match ))
388+ return match_list
389+
374390
375391def get_user (uid : Any [int , str ]) -> Optional [User ]:
376392 not_found = 0
@@ -400,7 +416,7 @@ def get_user(uid: Any[int, str]) -> Optional[User]:
400416 f_user = user
401417 # If none of those worked, throw an error
402418 if not_found == 3 :
403- logging .warning ("User {} not found." .format (uid ))
419+ logging .debug ("User {} not found." .format (uid ))
404420 raise NotFoundError ("User {} not found." .format (uid ), "Try again with another uid" )
405421 logging .debug ("Found user {} from {}" .format (f_user .id , uid ))
406422 return f_user
0 commit comments