Merge pull request #23 from Qtoss-AI/hdongDev

Hdong dev
This commit is contained in:
Haiping 2024-10-12 07:04:43 -05:00 committed by GitHub
commit 4ac8db59b6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 43 additions and 4 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)

View file

@ -13,7 +13,7 @@ public partial class MongoRepository
public User? GetUserByPhone(string phone)
{
var user = _dc.Users.AsQueryable().FirstOrDefault(x => x.Phone == phone);
var user = _dc.Users.AsQueryable().FirstOrDefault(x => x.Phone == phone && x.Type != UserType.Affiliate);
return user != null ? user.ToUser() : null;
}