File tree Expand file tree Collapse file tree 3 files changed +43
-33
lines changed
Expand file tree Collapse file tree 3 files changed +43
-33
lines changed Original file line number Diff line number Diff line change 114114logging .debug ("Configuring JWT" )
115115
116116ACCESS_TOKEN_EXPIRES = datetime .timedelta (minutes = 15 )
117+
117118REFRESH_TOKEN_EXPIRES = datetime .timedelta (days = 30 )
118119application .config ["JWT_ACCESS_TOKEN_EXPIRES" ] = ACCESS_TOKEN_EXPIRES
119120application .config ["JWT_REFRESH_TOKEN_EXPIRES" ] = REFRESH_TOKEN_EXPIRES
Original file line number Diff line number Diff line change @@ -486,34 +486,37 @@ def get_messages_with_user(self, with_user_id) -> List[Message]:
486486
487487
488488def get_user (uid : Any [int , str ]) -> Optional [User ]:
489- not_found = 0
490489 # These initializations are to make PEP happy and silence warnings
491- f_user = None
490+ f_user = None # noqa
492491
493492 if isinstance (uid , str ):
494493 uid = uid .lower ()
495494
496495 try :
497- user = User . get ( id = uid )
496+ uid = int ( uid )
498497 except ValueError :
499- not_found += 1
500- else :
501- f_user = user
502- try :
503- user = User .get (username = uid )
504- except ValueError :
505- not_found += 1
506- else :
507- f_user = user
508- try :
509- user = User .get (email = uid )
510- except ValueError :
511- not_found += 1
498+ try :
499+ user = User .get (username = uid )
500+ except ValueError :
501+ pass
502+ else :
503+ logging .debug ("Found user {} from {}" .format (user .id , uid ))
504+ return user
505+ try :
506+ user = User .get (email = uid )
507+ except ValueError :
508+ pass
509+ else :
510+ logging .debug ("Found user {} from {}" .format (user .id , uid ))
511+ return user
512512 else :
513- f_user = user
513+ try :
514+ user = User .get (id = uid )
515+ except ValueError :
516+ pass
517+ else :
518+ logging .debug ("Found user {} from {}" .format (user .id , uid ))
519+ return user
514520 # If none of those worked, throw an error
515- if not_found == 3 :
516- logging .debug ("User {} not found." .format (uid ))
517- raise NotFoundError ("User {} not found." .format (uid ))
518- logging .debug ("Found user {} from {}" .format (f_user .id , uid ))
519- return f_user
521+ logging .debug ("User {} not found." .format (uid ))
522+ raise NotFoundError ("User {} not found." .format (uid ))
Original file line number Diff line number Diff line change @@ -233,20 +233,26 @@ def get(cls, **kwargs):
233233 return False
234234 key = next (iter (kwargs ))
235235 val = kwargs [key ]
236-
236+ if isinstance (val , str ):
237+ typ = "CHAR"
238+ else :
239+ typ = None
237240 temp = cls ()
241+ fields = ", " .join (temp .fields .keys ())
238242 with temp .db .cursor () as c :
239- c .execute (
243+ if typ :
244+ query = f"""
245+ SELECT { fields }
246+ FROM { cls .table_name }
247+ WHERE { key } =CAST('{ val } ' AS { typ } CHARACTER SET utf8mb4);
240248 """
241- SELECT
242- {fields}
243- FROM
244- {table}
245- WHERE {cond}=%s""" .format (
246- fields = ", " .join (temp .fields .keys ()), table = cls .table_name , cond = key
247- ),
248- (val ,),
249- )
249+ else :
250+ query = f"""
251+ SELECT { fields }
252+ FROM { cls .table_name }
253+ WHERE { key } ={ val } ;
254+ """
255+ c .execute (query )
250256
251257 data = c .fetchone ()
252258 c .close ()
You can’t perform that action at this time.
0 commit comments