UserServiceCurrentUserChangePasswordAsync Method

当前登录用户修改密码。

Definition

Namespace: QuickAdmin.Service.Admin
Assembly: QuickAdmin.Net (in QuickAdmin.Net.dll) Version: 2.0.11
C#
public virtual Task<IServiceResult> CurrentUserChangePasswordAsync(
	string oldPwd,
	string newPwd,
	CancellationToken cancellationToken = default
)

Parameters

oldPwd  string
旧密码。
newPwd  string
新密码。
cancellationToken  CancellationToken  (Optional)
用于取消操作的令牌。

Return Value

TaskIServiceResult
服务调用结果。

Implements

IUserServiceCurrentUserChangePasswordAsync(string, string, CancellationToken)

Remarks

新密码不能与旧密码相同。
方法内: 密码修改后,若要强制用户退出并重新登录,可重写此方法并返回指定结果,参见示例代码。

Example

按以下代码继承 UserService 并重写此方法,返回 Datatrue 的服务调用结果:
C#
public class MyUserService : UserService
{
    public override async Task<IServiceResult> CurrentUserChangePasswordAsync(string oldPwd, string newPwd, CancellationToken cancellationToken = default)
    {
        var result = await base.CurrentUserChangePasswordAsync(oldPwd, newPwd, cancellationToken);
        if (!result.Success)
            return result;
        return ServiceResult.Ok<bool>(true);
    }
}
然后在应用启动时注入派生类 MyUserService
C#
builder.Services.AddSingleton(typeof(IUserService), typeof(MyUserService));
将会使用户修改密码后被强制退出。

See Also