2025-07-12 21:33:44 +03:30
|
|
|
@using Common.Dtos
|
|
|
|
@using Common.Validation
|
2025-07-11 20:37:28 +03:30
|
|
|
@using HushianWebApp.Service
|
|
|
|
@using HushianWebApp.Services
|
|
|
|
@inject UserService userService;
|
|
|
|
@inject NavigationManager NavigationManager
|
|
|
|
@inject AuthService authService;
|
|
|
|
@inject ILocalStorageService localStorageService;
|
|
|
|
<form style="background-color: #ffffff; padding: 20px; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); display: flex; flex-direction: column;">
|
|
|
|
|
|
|
|
<label style="margin-bottom: 8px; font-size: 14px; color: #333;" for="oldpass">رمز عبور قبلی:</label>
|
2025-07-12 21:33:44 +03:30
|
|
|
<input dir="ltr" style="text-align:center" @bind="@dto.OldPassWord" type="password" class="form-control" placeholder="رمز عبور قبلی" />
|
2025-07-11 20:37:28 +03:30
|
|
|
|
|
|
|
|
|
|
|
<label style="margin-bottom: 8px; font-size: 14px; color: #333; margin-top:15px" for="newpass">رمز عبور جدید:</label>
|
2025-07-12 21:33:44 +03:30
|
|
|
<input dir="ltr" style="text-align:center" @bind="@dto.NewPassWord" type="password" class="form-control" placeholder="رمز عبور جدید" />
|
2025-07-11 20:37:28 +03:30
|
|
|
|
|
|
|
<label style="margin-bottom: 8px; font-size: 14px; color: #333; margin-top:15px" for="newpass2">تکرار رمز عبور جدید:</label>
|
|
|
|
<input dir="ltr" style="text-align:center" @bind="RePassword" type="password" class="form-control" placeholder="تکرار رمز عبور جدید" />
|
|
|
|
<ul style="padding-right:10px; padding-top:10px">
|
|
|
|
<li style="color:red">رمز عبور باید حداقل دارای یک کاراکتر باشد</li>
|
|
|
|
<li style="color:red">رمز عبور باید حداقل دارای یک کاراکتر انگلیسی بزرگ باشد</li>
|
|
|
|
<li style="color:red">رمز عبور باید حداقل دارای یک کاراکتر انگلیسی کوچک باشد</li>
|
|
|
|
<li style="color:red">رمز عبور باید حداقل دارای یک عدد باشد</li>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
<div class="d-grid gap-2">
|
|
|
|
<Button style="margin-top:15px" Loading="SpinnerVisible" onclick="@Click" Color="ButtonColor.Primary"> تغییر کلمه عبور </Button>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
|
|
|
|
@code {
|
|
|
|
[Inject] protected ToastService ToastService { get; set; } = default!;
|
|
|
|
public bool SpinnerVisible { get; set; }
|
2025-07-12 21:33:44 +03:30
|
|
|
public ChangePasswordDto dto { get; set; } = new();
|
2025-07-11 20:37:28 +03:30
|
|
|
public string RePassword { get; set; } = "";
|
|
|
|
public string Username { get; set; } = "";
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
|
|
{
|
2025-07-12 21:33:44 +03:30
|
|
|
// Username = await localStorageService.GetItem<string>("Username");
|
|
|
|
// dto = new() { UserName = Username };
|
2025-07-11 20:37:28 +03:30
|
|
|
await base.OnParametersSetAsync();
|
|
|
|
}
|
|
|
|
async Task Click()
|
|
|
|
{
|
2025-07-12 21:33:44 +03:30
|
|
|
if (string.IsNullOrEmpty(dto.OldPassWord) || string.IsNullOrEmpty(dto.NewPassWord))
|
2025-07-11 20:37:28 +03:30
|
|
|
return;
|
|
|
|
|
2025-07-12 21:33:44 +03:30
|
|
|
if (dto.NewPassWord != RePassword)
|
2025-07-11 20:37:28 +03:30
|
|
|
{
|
|
|
|
ToastService.Notify(new ToastMessage(ToastType.Danger, "کلمه عبور با تکرار متفاوت است"));
|
|
|
|
return;
|
|
|
|
}
|
2025-07-12 21:33:44 +03:30
|
|
|
|
|
|
|
List<string> errors = new();
|
|
|
|
if (!dto.NewPassWord.CheckLawPassword(ref errors))
|
|
|
|
{
|
|
|
|
ToastService.Notify(new(ToastType.Danger, errors.First()));
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
2025-07-11 20:37:28 +03:30
|
|
|
SpinnerVisible = true;
|
|
|
|
var result = await userService.ChangePasswordYourself(dto);
|
|
|
|
if (result)
|
|
|
|
{
|
|
|
|
ToastService.Notify(new ToastMessage(ToastType.Success, "تغییر کلمه عبور با موفقیت انجام شد"));
|
|
|
|
|
|
|
|
await authService.Logout();
|
|
|
|
NavigationManager.NavigateTo("/login");
|
|
|
|
}
|
|
|
|
else ToastService.Notify(new ToastMessage(ToastType.Danger, "خطا در تغییر کلمه عبور"));
|
|
|
|
|
|
|
|
SpinnerVisible = false;
|
|
|
|
}
|
|
|
|
}
|