File tree Expand file tree Collapse file tree 5 files changed +46
-3
lines changed
BotSharp.Abstraction/Repositories
Repository/FileRepository
BotSharp.OpenAPI/Controllers
Plugins/BotSharp.Plugin.MongoStorage/Repository Expand file tree Collapse file tree 5 files changed +46
-3
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ public interface IBotSharpRepository
1919
2020 #region User
2121 User ? GetUserByEmail ( string email ) => throw new NotImplementedException ( ) ;
22+ User ? GetUserByPhone ( string phone ) => throw new NotImplementedException ( ) ;
2223 User ? GetUserById ( string id ) => throw new NotImplementedException ( ) ;
2324 User ? GetUserByUserName ( string userName ) => throw new NotImplementedException ( ) ;
2425 void CreateUser ( User user ) => throw new NotImplementedException ( ) ;
Original file line number Diff line number Diff line change @@ -11,6 +11,11 @@ public partial class FileRepository
1111 return Users . FirstOrDefault ( x => x . Email == email . ToLower ( ) ) ;
1212 }
1313
14+ public User ? GetUserByPhone ( string phone )
15+ {
16+ return Users . FirstOrDefault ( x => x . Phone == phone ) ;
17+ }
18+
1419 public User ? GetUserById ( string id = null )
1520 {
1621 return Users . FirstOrDefault ( x => x . Id == id || ( x . ExternalId != null && x . ExternalId == id ) ) ;
Original file line number Diff line number Diff line change @@ -325,8 +325,24 @@ public async Task<bool> VerifyEmailExisting(string email)
325325
326326 public async Task < bool > SendVerificationCodeResetPassword ( User user )
327327 {
328+ if ( ! string . IsNullOrEmpty ( user . Email ) && ! string . IsNullOrEmpty ( user . Phone ) )
329+ {
330+ return false ;
331+ }
332+
328333 var db = _services . GetRequiredService < IBotSharpRepository > ( ) ;
329- var record = db . GetUserByEmail ( user . Email ) ;
334+
335+ User ? record = null ;
336+
337+ if ( ! string . IsNullOrEmpty ( user . Email ) )
338+ {
339+ record = db . GetUserByEmail ( user . Email ) ;
340+ }
341+
342+ if ( ! string . IsNullOrEmpty ( user . Phone ) )
343+ {
344+ record = db . GetUserByPhone ( user . Phone ) ;
345+ }
330346 if ( record == null )
331347 {
332348 return false ;
@@ -349,8 +365,23 @@ public async Task<bool> SendVerificationCodeResetPassword(User user)
349365
350366 public async Task < bool > ResetUserPassword ( User user )
351367 {
368+ if ( ! string . IsNullOrEmpty ( user . Email ) && ! string . IsNullOrEmpty ( user . Phone ) )
369+ {
370+ return false ;
371+ }
352372 var db = _services . GetRequiredService < IBotSharpRepository > ( ) ;
353- var record = db . GetUserByEmail ( user . Email ) ;
373+
374+ User ? record = null ;
375+
376+ if ( ! string . IsNullOrEmpty ( user . Email ) )
377+ {
378+ record = db . GetUserByEmail ( user . Email ) ;
379+ }
380+
381+ if ( ! string . IsNullOrEmpty ( user . Phone ) )
382+ {
383+ record = db . GetUserByPhone ( user . Phone ) ;
384+ }
354385
355386 if ( record == null )
356387 {
Original file line number Diff line number Diff line change @@ -110,7 +110,7 @@ public async Task<bool> VerifyEmailExisting([FromQuery] string email)
110110 }
111111 [ AllowAnonymous ]
112112 [ HttpPost ( "/user/verifycode" ) ]
113- public async Task < bool > SendVerificationCodeResetPassword ( [ FromQuery ] UserCreationModel user )
113+ public async Task < bool > SendVerificationCodeResetPassword ( [ FromBody ] UserCreationModel user )
114114 {
115115 return await _userService . SendVerificationCodeResetPassword ( user . ToUser ( ) ) ;
116116 }
Original file line number Diff line number Diff line change @@ -10,6 +10,12 @@ public partial class MongoRepository
1010 return user != null ? user . ToUser ( ) : null ;
1111 }
1212
13+ public User ? GetUserByPhone ( string phone )
14+ {
15+ var user = _dc . Users . AsQueryable ( ) . FirstOrDefault ( x => x . Phone == phone ) ;
16+ return user != null ? user . ToUser ( ) : null ;
17+ }
18+
1319 public User ? GetUserById ( string id )
1420 {
1521 var user = _dc . Users . AsQueryable ( )
You can’t perform that action at this time.
0 commit comments