hdong: add simple login API for new login type.

This commit is contained in:
YouWeiDH 2025-01-13 20:17:28 +08:00
parent be6996c667
commit 3f64f36753
2 changed files with 39 additions and 1 deletions

View file

@ -25,6 +25,7 @@ public interface IUserService
Task<bool> VerifyPhoneExisting(string phone, string regionCode);
Task<bool> SendVerificationCodeResetPasswordNoLogin(User user);
Task<bool> SendVerificationCodeResetPasswordLogin();
Task<bool> SetUserPassword(User user);
Task<bool> ResetUserPassword(User user);
Task<bool> ModifyUserEmail(string email);
Task<bool> ModifyUserPhone(string phone, string regionCode);

View file

@ -95,7 +95,11 @@ public class UserService : IUserService
record.Phone = Regex.Match(user.Phone, @"\d+").Value;
}
record.Salt = Guid.NewGuid().ToString("N");
record.Password = Utilities.HashTextMd5($"{user.Password}{record.Salt}");
if (!string.IsNullOrWhiteSpace(user.Password))
{
record.Password = Utilities.HashTextMd5($"{user.Password}{record.Salt}");
}
if (_setting.NewUserVerification)
{
@ -689,6 +693,39 @@ public class UserService : IUserService
return true;
}
public async Task<bool> SetUserPassword(User user)
{
if (!string.IsNullOrEmpty(user.Id) && !string.IsNullOrEmpty(user.Email) && !string.IsNullOrEmpty(user.Phone))
{
return false;
}
var db = _services.GetRequiredService<IBotSharpRepository>();
User? record = null;
if (!string.IsNullOrEmpty(user.Id))
{
record = db.GetUserById(user.Id);
}
else if (!string.IsNullOrEmpty(user.Phone))
{
record = db.GetUserByPhone(user.Phone, regionCode: (string.IsNullOrWhiteSpace(user.RegionCode) ? "CN" : user.RegionCode));
}
else if (!string.IsNullOrEmpty(user.Email))
{
record = db.GetUserByEmail(user.Email);
}
if (record == null)
{
return false;
}
var newPassword = Utilities.HashTextMd5($"{user.Password}{record.Salt}");
db.UpdateUserPassword(record.Id, newPassword);
return true;
}
public async Task<bool> ModifyUserEmail(string email)
{
var curUser = await GetMyProfile();