修改手机号和邮箱忘记密码接口和发送验证码接口逻辑
This commit is contained in:
parent
f62cd8eafb
commit
de3cba3e59
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue