-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[#935] Add change password feature #938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| <Project> | ||
| <PropertyGroup> | ||
| <Authors>Ray</Authors> | ||
| <Version>3.2.2</Version> | ||
| <Version>3.2.3</Version> | ||
| <NoWarn>$(NoWarn);CS1591;CS0436</NoWarn> | ||
| </PropertyGroup> | ||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| @page "/Admin" | ||
| @using Microsoft.AspNetCore.Authorization | ||
| @rendermode InteractiveServer | ||
| @attribute [Authorize] | ||
|
|
||
| <PageTitle>Change Password</PageTitle> | ||
|
|
||
| <MudText Typo="Typo.h5">Change Password</MudText> | ||
|
|
||
| <MudCard Class="mx-auto my-4" Style="max-width: 500px;"> | ||
| <MudCardContent> | ||
| @if (!string.IsNullOrEmpty(_errorMessage)) | ||
| { | ||
| <MudAlert Severity="Severity.Error" Class="mb-3">@_errorMessage</MudAlert> | ||
| } | ||
| @if (!string.IsNullOrEmpty(_successMessage)) | ||
| { | ||
| <MudAlert Severity="Severity.Success" Class="mb-3">@_successMessage</MudAlert> | ||
| } | ||
| <MudTextField @bind-Value="_username" Label="New User Name" Required="true" RequiredError="Username cannot be empty" /> | ||
| <MudTextField @bind-Value="_currentPassword" Label="Current Password" Required="true" RequiredError="Password cannot be empty" | ||
| InputType="@_currentPasswordInput" Adornment="Adornment.End" | ||
| AdornmentIcon="@_currentPasswordInputIcon" OnAdornmentClick="ToggleCurrentPasswordVisibility" /> | ||
| <MudTextField @bind-Value="_newPassword" Label="New Password" Required="true" RequiredError="Password cannot be empty" | ||
| InputType="@_passwordInput" Adornment="Adornment.End" | ||
| AdornmentIcon="@_passwordInputIcon" OnAdornmentClick="TogglePasswordVisibility" /> | ||
| <MudTextField @bind-Value="_confirmPassword" Label="Confirm Password" Required="true" RequiredError="Password cannot be empty" | ||
| InputType="@_passwordInput" Adornment="Adornment.End" | ||
| AdornmentIcon="@_passwordInputIcon" OnAdornmentClick="TogglePasswordVisibility" /> | ||
| </MudCardContent> | ||
| <MudCardActions> | ||
| <MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="ChangePasswordAsync" | ||
| Class="ml-auto">Submit</MudButton> | ||
| </MudCardActions> | ||
| </MudCard> | ||
|
|
||
| <MudThemeProvider/> | ||
| <MudDialogProvider/> | ||
| <MudSnackbarProvider/> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| using Microsoft.AspNetCore.Components; | ||
| using MudBlazor; | ||
| using Ray.BiliBiliTool.Web.Services; | ||
|
|
||
| namespace Ray.BiliBiliTool.Web.Components.Pages; | ||
|
|
||
| public partial class Admin : ComponentBase | ||
| { | ||
| [Inject] | ||
| private NavigationManager NavigationManager { get; set; } = null!; | ||
|
|
||
| [Inject] | ||
| private IAuthService AuthService { get; set; } = null!; | ||
|
|
||
| private string _username = ""; | ||
| private string _currentPassword = ""; | ||
| private string _newPassword = ""; | ||
| private string _confirmPassword = ""; | ||
| private string _errorMessage = ""; | ||
| private string _successMessage = ""; | ||
|
|
||
| private bool _passwordVisibility; | ||
| private InputType _passwordInput = InputType.Password; | ||
| private string _passwordInputIcon = Icons.Material.Filled.VisibilityOff; | ||
|
|
||
| private bool _currentPasswordVisibility; | ||
| private InputType _currentPasswordInput = InputType.Password; | ||
| private string _currentPasswordInputIcon = Icons.Material.Filled.VisibilityOff; | ||
|
|
||
| private void TogglePasswordVisibility() | ||
| { | ||
| if (_passwordVisibility) | ||
| { | ||
| _passwordVisibility = false; | ||
| _passwordInputIcon = Icons.Material.Filled.VisibilityOff; | ||
| _passwordInput = InputType.Password; | ||
| } | ||
| else | ||
| { | ||
| _passwordVisibility = true; | ||
| _passwordInputIcon = Icons.Material.Filled.Visibility; | ||
| _passwordInput = InputType.Text; | ||
| } | ||
| } | ||
|
|
||
| private void ToggleCurrentPasswordVisibility() | ||
| { | ||
| if (_currentPasswordVisibility) | ||
| { | ||
| _currentPasswordVisibility = false; | ||
| _currentPasswordInputIcon = Icons.Material.Filled.VisibilityOff; | ||
| _currentPasswordInput = InputType.Password; | ||
| } | ||
| else | ||
| { | ||
| _currentPasswordVisibility = true; | ||
| _currentPasswordInputIcon = Icons.Material.Filled.Visibility; | ||
| _currentPasswordInput = InputType.Text; | ||
| } | ||
| } | ||
|
|
||
| protected override async Task OnInitializedAsync() | ||
| { | ||
| _username = await AuthService.GetAdminUserNameAsync(); | ||
| } | ||
|
|
||
| private async Task ChangePasswordAsync() | ||
| { | ||
| _errorMessage = ""; | ||
| _successMessage = ""; | ||
|
|
||
| if (_newPassword != _confirmPassword) | ||
| { | ||
| _errorMessage = "The new password and the confirm password do not match"; | ||
| return; | ||
| } | ||
|
|
||
| if (string.IsNullOrWhiteSpace(_newPassword)) | ||
| { | ||
| _errorMessage = "Password cannot be empty"; | ||
| return; | ||
| } | ||
|
|
||
| try | ||
| { | ||
| await AuthService.ChangePasswordAsync(_username, _currentPassword, _newPassword); | ||
| _successMessage = "Update Successful, you will be logged out in 2 seconds"; | ||
| await Task.Delay(2000); | ||
| _currentPassword = ""; | ||
| _newPassword = ""; | ||
| _confirmPassword = ""; | ||
| NavigationManager.NavigateTo("/auth/logout", true); | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| _errorMessage = e.Message; | ||
| } | ||
| } | ||
| } |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| export class Admin { | ||
|
|
||
| } | ||
|
|
||
| window.Admin = Admin; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a hardcoded user ID may lead to issues in multi-user environments. Consider querying the user based on the provided username or another flexible identifier.