feat: Add regionCode to mobile number judgment

This commit is contained in:
AnonymousDotNet 2024-11-08 19:17:16 +08:00
parent 1f72006cfd
commit d3053d3fec
5 changed files with 9 additions and 9 deletions

View file

@ -18,7 +18,7 @@ public interface IBotSharpRepository : IHaveServiceProvider
#region User
User? GetUserByEmail(string email) => throw new NotImplementedException();
User? GetUserByPhone(string phone) => throw new NotImplementedException();
User? GetUserByPhone(string phone, string regionCode = "CN") => throw new NotImplementedException();
User? GetAffiliateUserByPhone(string phone) => throw new NotImplementedException();
User? GetUserById(string id) => throw new NotImplementedException();
List<User> GetUserByIds(List<string> ids) => throw new NotImplementedException();

View file

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

View file

@ -487,7 +487,7 @@ public class UserService : IUserService
return false;
}
public async Task<bool> VerifyPhoneExisting(string phone)
public async Task<bool> VerifyPhoneExisting(string phone, string regionCode)
{
if (string.IsNullOrEmpty(phone))
{
@ -495,7 +495,7 @@ public class UserService : IUserService
}
var db = _services.GetRequiredService<IBotSharpRepository>();
var UserByphone = db.GetUserByPhone(phone);
var UserByphone = db.GetUserByPhone(phone, regionCode);
if (UserByphone != null && UserByphone.Verified)
{
return true;

View file

@ -1,5 +1,5 @@
using BotSharp.Abstraction.Users.Settings;
using BotSharp.Abstraction.Users.Enums;
using BotSharp.Abstraction.Users.Settings;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using System.ComponentModel.DataAnnotations;
@ -124,9 +124,9 @@ public class UserController : ControllerBase
[AllowAnonymous]
[HttpGet("/user/phone/existing")]
public async Task<bool> VerifyPhoneExisting([FromQuery] string phone)
public async Task<bool> VerifyPhoneExisting([FromQuery] string phone, [FromQuery] string regionCode = "CN")
{
return await _userService.VerifyPhoneExisting(phone);
return await _userService.VerifyPhoneExisting(phone, regionCode);
}
[AllowAnonymous]

View file

@ -13,7 +13,7 @@ public partial class MongoRepository
return user != null ? user.ToUser() : null;
}
public User? GetUserByPhone(string phone)
public User? GetUserByPhone(string phone, string regionCode = "CN")
{
string phoneSecond = string.Empty;
// 如果电话号码长度小于 4直接返回 null
@ -29,7 +29,7 @@ public partial class MongoRepository
{
phoneSecond = phone.Replace("+86", "");
}
var user = _dc.Users.AsQueryable().FirstOrDefault(x => (x.Phone == phone || x.Phone == phoneSecond) && x.Type != UserType.Affiliate);
var user = _dc.Users.AsQueryable().FirstOrDefault(x => (x.Phone == phone || x.Phone == phoneSecond) && x.Type != UserType.Affiliate && x.RegionCode == regionCode);
return user != null ? user.ToUser() : null;
}