Add UserUpdating hook

This commit is contained in:
Haiping Chen 2024-10-13 18:24:36 -05:00
parent c84d7288c0
commit 263462302a
2 changed files with 18 additions and 6 deletions

View file

@ -8,6 +8,7 @@ public interface IAuthenticationHook
Task<User> Authenticate(string id, string password);
void AddClaims(List<Claim> claims);
void BeforeSending(Token token);
Task UserUpdating(User user);
Task UserCreated(User user);
Task VerificationCodeResetPassword(User user);
Task DelUsers(List<string> userIds);

View file

@ -491,7 +491,7 @@ public class UserService : IUserService
var hooks = _services.GetServices<IAuthenticationHook>();
foreach (var hook in hooks)
{
hook.VerificationCodeResetPassword(record);
await hook.VerificationCodeResetPassword(record);
}
return true;
@ -522,7 +522,7 @@ public class UserService : IUserService
var hooks = _services.GetServices<IAuthenticationHook>();
foreach (var hook in hooks)
{
hook.VerificationCodeResetPassword(record);
await hook.VerificationCodeResetPassword(record);
}
return true;
@ -574,7 +574,14 @@ public class UserService : IUserService
return false;
}
db.UpdateUserEmail(record.Id, email);
record.Email = email;
var hooks = _services.GetServices<IAuthenticationHook>();
foreach (var hook in hooks)
{
await hook.UserUpdating(record);
}
db.UpdateUserEmail(record.Id, record.Email);
return true;
}
@ -590,12 +597,16 @@ public class UserService : IUserService
return false;
}
if ((record.UserName.Substring(0, 3) == "+86" || record.FirstName.Substring(0, 3) == "+86") && phone.Substring(0, 3) != "+86")
record.Phone = phone;
var hooks = _services.GetServices<IAuthenticationHook>();
foreach (var hook in hooks)
{
phone = $"+86{phone}";
await hook.UserUpdating(record);
}
db.UpdateUserPhone(record.Id, phone);
db.UpdateUserPhone(record.Id, record.Phone);
return true;
}