hdong: Fix to avoid Email/Phone duplicate when user register again.(check first:phone, then email, then userName)

This commit is contained in:
YouWeiDH 2024-10-12 15:13:46 +08:00
parent 312c58fd3e
commit c72ea4af2f
3 changed files with 42 additions and 3 deletions

View file

@ -13,6 +13,7 @@ public interface IUserService
Task<User> GetMyProfile();
Task<bool> VerifyUserNameExisting(string userName);
Task<bool> VerifyEmailExisting(string email);
Task<bool> VerifyPhoneExisting(string phone);
Task<bool> SendVerificationCodeResetPasswordNoLogin(User user);
Task<bool> SendVerificationCodeResetPasswordLogin();
Task<bool> ResetUserPassword(User user);

View file

@ -45,7 +45,19 @@ public class UserService : IUserService
}
var db = _services.GetRequiredService<IBotSharpRepository>();
var record = db.GetUserByUserName(user.UserName);
var record = db.GetUserByPhone(user.Phone);
if (record == null)
{
record = db.GetUserByEmail(user.Email);
}
if (record == null)
{
record = db.GetUserByUserName(user.UserName);
}
if (record != null)
{
@ -428,6 +440,23 @@ public class UserService : IUserService
return false;
}
public async Task<bool> VerifyPhoneExisting(string phone)
{
if (string.IsNullOrEmpty(phone))
{
return true;
}
var db = _services.GetRequiredService<IBotSharpRepository>();
var UserByphone = db.GetUserByPhone(phone);
if (UserByphone != null && UserByphone.Verified)
{
return true;
}
return false;
}
public async Task<bool> SendVerificationCodeResetPasswordNoLogin(User user)
{
var db = _services.GetRequiredService<IBotSharpRepository>();
@ -540,7 +569,8 @@ public class UserService : IUserService
var curUser = await GetMyProfile();
var db = _services.GetRequiredService<IBotSharpRepository>();
var record = db.GetUserById(curUser.Id);
if (record == null)
var existEmail = db.GetUserByEmail(email);
if (record == null || existEmail != null)
{
return false;
}
@ -554,8 +584,9 @@ public class UserService : IUserService
var curUser = await GetMyProfile();
var db = _services.GetRequiredService<IBotSharpRepository>();
var record = db.GetUserById(curUser.Id);
var existPhone = db.GetUserByPhone(phone);
if (record == null)
if (record == null || existPhone != null)
{
return false;
}

View file

@ -109,6 +109,13 @@ public class UserController : ControllerBase
return await _userService.VerifyEmailExisting(email);
}
[AllowAnonymous]
[HttpGet("/user/phone/existing")]
public async Task<bool> VerifyPhoneExisting([FromQuery] string phone)
{
return await _userService.VerifyPhoneExisting(phone);
}
[AllowAnonymous]
[HttpPost("/user/verifycode-out")]
public async Task<bool> SendVerificationCodeResetPassword([FromBody] UserCreationModel user)