Merge pull request #9 from AnonymousDotNet/lida_dev

修改手机号和邮箱忘记密码接口和发送验证码接口逻辑
This commit is contained in:
Haiping 2024-09-06 23:04:20 -05:00 committed by GitHub
commit 9fad17fc26
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 46 additions and 3 deletions

View file

@ -19,6 +19,7 @@ public interface IBotSharpRepository
#region User
User? GetUserByEmail(string email) => throw new NotImplementedException();
User? GetUserByPhone(string phone) => throw new NotImplementedException();
User? GetUserById(string id) => throw new NotImplementedException();
User? GetUserByUserName(string userName) => throw new NotImplementedException();
void CreateUser(User user) => throw new NotImplementedException();

View file

@ -11,6 +11,11 @@ public partial class FileRepository
return Users.FirstOrDefault(x => x.Email == email.ToLower());
}
public User? GetUserByPhone(string phone)
{
return Users.FirstOrDefault(x => x.Phone == phone);
}
public User? GetUserById(string id = null)
{
return Users.FirstOrDefault(x => x.Id == id || (x.ExternalId != null && x.ExternalId == id));

View file

@ -325,8 +325,24 @@ public class UserService : IUserService
public async Task<bool> SendVerificationCodeResetPassword(User user)
{
if (!string.IsNullOrEmpty(user.Email) && !string.IsNullOrEmpty(user.Phone))
{
return false;
}
var db = _services.GetRequiredService<IBotSharpRepository>();
var record = db.GetUserByEmail(user.Email);
User? record = null;
if (!string.IsNullOrEmpty(user.Email))
{
record = db.GetUserByEmail(user.Email);
}
if (!string.IsNullOrEmpty(user.Phone))
{
record = db.GetUserByPhone(user.Phone);
}
if (record == null)
{
return false;
@ -349,8 +365,23 @@ public class UserService : IUserService
public async Task<bool> ResetUserPassword(User user)
{
if (!string.IsNullOrEmpty(user.Email) && !string.IsNullOrEmpty(user.Phone))
{
return false;
}
var db = _services.GetRequiredService<IBotSharpRepository>();
var record = db.GetUserByEmail(user.Email);
User? record = null;
if (!string.IsNullOrEmpty(user.Email))
{
record = db.GetUserByEmail(user.Email);
}
if (!string.IsNullOrEmpty(user.Phone))
{
record = db.GetUserByPhone(user.Phone);
}
if (record == null)
{

View file

@ -110,7 +110,7 @@ public class UserController : ControllerBase
}
[AllowAnonymous]
[HttpPost("/user/verifycode")]
public async Task<bool> SendVerificationCodeResetPassword([FromQuery] UserCreationModel user)
public async Task<bool> SendVerificationCodeResetPassword([FromBody] UserCreationModel user)
{
return await _userService.SendVerificationCodeResetPassword(user.ToUser());
}

View file

@ -10,6 +10,12 @@ public partial class MongoRepository
return user != null ? user.ToUser() : null;
}
public User? GetUserByPhone(string phone)
{
var user = _dc.Users.AsQueryable().FirstOrDefault(x => x.Phone == phone);
return user != null ? user.ToUser() : null;
}
public User? GetUserById(string id)
{
var user = _dc.Users.AsQueryable()