@@ -55,6 +55,11 @@ record = db.GetUserByUserName(user.UserName);
5555
5656 if ( record == null && ! string . IsNullOrWhiteSpace ( user . Phone ) )
5757 {
58+ //if (user.Type != "internal")
59+ //{
60+ // record = db.GetUserByPhoneV2(user.Phone, regionCode: (string.IsNullOrWhiteSpace(user.RegionCode) ? "CN" : user.RegionCode));
61+ //}
62+
5863 record = db . GetUserByPhone ( user . Phone , regionCode : ( string . IsNullOrWhiteSpace ( user . RegionCode ) ? "CN" : user . RegionCode ) ) ;
5964 }
6065
@@ -477,11 +482,17 @@ public async Task<Token> ActiveUser(UserActivationModel model)
477482 var id = model . UserName ;
478483 var db = _services . GetRequiredService < IBotSharpRepository > ( ) ;
479484 var record = id . Contains ( "@" ) ? db . GetUserByEmail ( id ) : db . GetUserByUserName ( id ) ;
485+
480486 if ( record == null )
481487 {
482488 record = db . GetUserByPhone ( id , regionCode : ( string . IsNullOrWhiteSpace ( model . RegionCode ) ? "CN" : model . RegionCode ) ) ;
483489 }
484490
491+ //if (record == null)
492+ //{
493+ // record = db.GetUserByPhoneV2(id, regionCode: (string.IsNullOrWhiteSpace(model.RegionCode) ? "CN" : model.RegionCode));
494+ //}
495+
485496 if ( record == null )
486497 {
487498 return default ;
@@ -621,21 +632,12 @@ public async Task<bool> SendVerificationCodeNoLogin(User user)
621632 public async Task < User > ResetVerificationCode ( User user )
622633 {
623634 var db = _services . GetRequiredService < IBotSharpRepository > ( ) ;
624- User record = null ;
625- if ( ! string . IsNullOrEmpty ( user . Email ) && ! string . IsNullOrEmpty ( user . Phone ) )
635+ if ( ! string . IsNullOrWhiteSpace ( user . Email ) && ! string . IsNullOrWhiteSpace ( user . Phone ) )
626636 {
627637 return null ;
628638 }
629639
630- if ( ! string . IsNullOrEmpty ( user . Phone ) )
631- {
632- record = db . GetUserByPhone ( user . Phone , regionCode : user . RegionCode ) ;
633- }
634-
635- if ( ! string . IsNullOrEmpty ( user . Email ) )
636- {
637- record = db . GetUserByEmail ( user . Email ) ;
638- }
640+ User ? record = GetLoginUserByUniqueFilter ( user , db ) ;
639641
640642 if ( record == null )
641643 {
@@ -650,6 +652,36 @@ record = db.GetUserByEmail(user.Email);
650652 return record ;
651653 }
652654
655+ private static User ? GetLoginUserByUniqueFilter ( User user , IBotSharpRepository db )
656+ {
657+ User ? record = null ;
658+ if ( ! string . IsNullOrWhiteSpace ( user . Id ) )
659+ {
660+ record = db . GetUserById ( user . Id ) ;
661+ }
662+
663+ if ( record == null && ! string . IsNullOrWhiteSpace ( user . Phone ) )
664+ {
665+ record = db . GetUserByPhone ( user . Phone , regionCode : string . IsNullOrWhiteSpace ( user . RegionCode ) ? "CN" : user . RegionCode ) ;
666+ //if (record == null)
667+ //{
668+ // record = db.GetUserByPhoneV2(user.Phone, regionCode: string.IsNullOrWhiteSpace(user.RegionCode) ? "CN" : user.RegionCode);
669+ //}
670+ }
671+
672+ if ( record == null && ! string . IsNullOrWhiteSpace ( user . Email ) )
673+ {
674+ record = db . GetUserByEmail ( user . Email ) ;
675+ }
676+
677+ if ( record == null && ! string . IsNullOrWhiteSpace ( user . UserName ) )
678+ {
679+ record = db . GetUserByUserName ( user . UserName ) ;
680+ }
681+
682+ return record ;
683+ }
684+
653685 public async Task < bool > SendVerificationCodeLogin ( )
654686 {
655687 var db = _services . GetRequiredService < IBotSharpRepository > ( ) ;
@@ -689,17 +721,7 @@ public async Task<bool> ResetUserPassword(User user)
689721 }
690722 var db = _services . GetRequiredService < IBotSharpRepository > ( ) ;
691723
692- User ? record = null ;
693-
694- if ( ! string . IsNullOrEmpty ( user . Email ) )
695- {
696- record = db . GetUserByEmail ( user . Email ) ;
697- }
698-
699- if ( ! string . IsNullOrEmpty ( user . Phone ) )
700- {
701- record = db . GetUserByPhone ( user . Phone , regionCode : ( string . IsNullOrWhiteSpace ( user . RegionCode ) ? "CN" : user . RegionCode ) ) ;
702- }
724+ User ? record = GetLoginUserByUniqueFilter ( user , db ) ;
703725
704726 if ( record == null )
705727 {
@@ -724,20 +746,7 @@ public async Task<bool> SetUserPassword(User user)
724746 }
725747 var db = _services . GetRequiredService < IBotSharpRepository > ( ) ;
726748
727- User ? record = null ;
728-
729- if ( ! string . IsNullOrEmpty ( user . Id ) )
730- {
731- record = db . GetUserById ( user . Id ) ;
732- }
733- else if ( ! string . IsNullOrEmpty ( user . Phone ) )
734- {
735- record = db . GetUserByPhone ( user . Phone , regionCode : ( string . IsNullOrWhiteSpace ( user . RegionCode ) ? "CN" : user . RegionCode ) ) ;
736- }
737- else if ( ! string . IsNullOrEmpty ( user . Email ) )
738- {
739- record = db . GetUserByEmail ( user . Email ) ;
740- }
749+ User ? record = GetLoginUserByUniqueFilter ( user , db ) ;
741750
742751 if ( record == null )
743752 {
0 commit comments