@@ -569,12 +569,9 @@ def login(self, email, password):
569
569
# first check if we have a plugin that can check credentials
570
570
571
571
for plugin in self .plugins .values ():
572
- print (plugin )
573
572
if not hasattr (plugin , "get_login_url" ):
574
573
prevent_db_lookup = True
575
- print ("OK" )
576
574
if plugin .check_credentials (email , password ):
577
- print ("plugin accepted" )
578
575
# if the creadentials are independently validated
579
576
# get of create the user (if does not exist)
580
577
user_info = {}
@@ -586,25 +583,28 @@ def login(self, email, password):
586
583
else :
587
584
user_info ["email" ] = email + "@example.com"
588
585
user = self .get_or_register_user (user_info )
589
- print (user )
590
586
break
591
587
592
588
# else check against database
593
589
if not prevent_db_lookup :
594
590
value = email .lower ()
595
- field = db .auth_user .email if "@" in value else db .auth_user .username
591
+ field = (
592
+ db .auth_user .email
593
+ if "@" in value or not self .use_username
594
+ else db .auth_user .username
595
+ )
596
596
user = db (field == value ).select ().first ()
597
597
if user and not (CRYPT ()(password )[0 ] == user .password ):
598
598
user = None
599
599
600
600
# then check for possible login blockers
601
601
if not user :
602
602
error = "invalid_credentials"
603
- elif (user . get ( "action_token" ) or "" ).startswith ("pending-registration:" ):
603
+ elif (user [ "action_token" ] or "" ).startswith ("pending-registration:" ):
604
604
error = "registration_is_pending"
605
- elif user . get ( "action_token" ) == "account-blocked" :
605
+ elif user [ "action_token" ] == "account-blocked" :
606
606
error = "account_is_blocked"
607
- elif user . get ( "action_token" ) == "pending-approval" :
607
+ elif user [ "action_token" ] == "pending-approval" :
608
608
error = "account_needs_to_be_approved"
609
609
610
610
# return the error or the user
@@ -619,15 +619,12 @@ def request_reset_password(self, email, send=True, next="", route=None):
619
619
620
620
db = self .db
621
621
value = email .lower ()
622
- if self .use_username :
623
- query = (
624
- (db .auth_user .email == value )
625
- if "@" in value
626
- else (db .auth_user .username == value )
627
- )
628
- else :
629
- query = db .auth_user .email == value
630
- user = db (query ).select ().first ()
622
+ field = (
623
+ db .auth_user .email
624
+ if "@" in value or not self .use_username
625
+ else self .auth_user .username
626
+ )
627
+ user = db (field == value ).select ().first ()
631
628
if user and user .action_token != "account-blocked" :
632
629
token = str (uuid .uuid4 ())
633
630
if next :
0 commit comments