Merge pull request #66 from Qtoss-AI/hdongDev
hdong: add simple login API for new login type.
This commit is contained in:
commit
0e9dd8a85e
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in a new issue