Skip to content

Commit 9fad17f

Browse files
authored
Merge pull request #9 from AnonymousDotNet/lida_dev
修改手机号和邮箱忘记密码接口和发送验证码接口逻辑
2 parents 0f91ae1 + ce6595b commit 9fad17f

File tree

5 files changed

+46
-3
lines changed

5 files changed

+46
-3
lines changed

src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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();

src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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));

src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff 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
{

src/Infrastructure/BotSharp.OpenAPI/Controllers/UserController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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
}

src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff 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()

0 commit comments

Comments
 (0)