Skip to content

Commit

Permalink
password change - added snackbar
Browse files Browse the repository at this point in the history
  • Loading branch information
iammukeshm committed Mar 18, 2021
1 parent 514a972 commit 4ddafd7
Show file tree
Hide file tree
Showing 26 changed files with 52 additions and 112 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BlazorHero.CleanArchitecture.Application.Features.Dashboard.GetData
namespace BlazorHero.CleanArchitecture.Application.Features.Dashboard.GetData
{
public class DashboardDataResponse
{
Expand All @@ -13,4 +7,4 @@ public class DashboardDataResponse
public int UserCount { get; set; }
public int RoleCount { get; set; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
using BlazorHero.CleanArchitecture.Shared.Wrapper;
using MediatR;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

Expand All @@ -27,6 +23,7 @@ public GetDashboardDataQueryHandler(IUnitOfWork unitOfWork, IUserService userSer
_userService = userService;
_roleService = roleService;
}

public async Task<Result<DashboardDataResponse>> Handle(GetDashboardDataQuery query, CancellationToken cancellationToken)
{
var response = new DashboardDataResponse();
Expand All @@ -38,4 +35,4 @@ public async Task<Result<DashboardDataResponse>> Handle(GetDashboardDataQuery qu
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using BlazorHero.CleanArchitecture.Domain.Entities.Catalog;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BlazorHero.CleanArchitecture.Application.Interfaces.Repositories
namespace BlazorHero.CleanArchitecture.Application.Interfaces.Repositories
{
public interface IBrandRepository
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using BlazorHero.CleanArchitecture.Domain.Entities.Catalog;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Threading.Tasks;

namespace BlazorHero.CleanArchitecture.Application.Interfaces.Repositories
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using BlazorHero.CleanArchitecture.Domain.Contracts;
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

Expand All @@ -9,7 +8,9 @@ namespace BlazorHero.CleanArchitecture.Application.Interfaces.Repositories
public interface IUnitOfWork : IDisposable
{
IRepositoryAsync<T> Repository<T>() where T : AuditableEntity;

Task<int> Commit(CancellationToken cancellationToken);

Task Rollback();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace BlazorHero.CleanArchitecture.Application.Interfaces.Services.Identity
public interface IRoleService : IService
{
Task<Result<List<RoleResponse>>> GetAllAsync();

Task<int> GetCountAsync();

Task<Result<RoleResponse>> GetByIdAsync(string id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace BlazorHero.CleanArchitecture.Application.Interfaces.Services.Identity
public interface IUserService : IService
{
Task<Result<List<UserResponse>>> GetAllAsync();

Task<int> GetCountAsync();

Task<IResult<UserResponse>> GetAsync(string userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,17 @@ public void MarkUserAsLoggedOut()

NotifyAuthenticationStateChanged(authState);
}
public async Task<ClaimsPrincipal> GetAuthenticationStateProviderUserAsync()

public async Task<ClaimsPrincipal> GetAuthenticationStateProviderUserAsync()
{
ClaimsPrincipal AuthenticationStateProviderUser = new ClaimsPrincipal();
var state = await this.GetAuthenticationStateAsync();
AuthenticationStateProviderUser = state.User;
return AuthenticationStateProviderUser;
}

public ClaimsPrincipal AuthenticationStateUser { get; set; }

public override async Task<AuthenticationState> GetAuthenticationStateAsync()
{
var savedToken = await _localStorage.GetItemAsync<string>("authToken");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
using BlazorHero.CleanArchitecture.Client.Infrastructure.Extensions;
using BlazorHero.CleanArchitecture.Shared.Wrapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace BlazorHero.CleanArchitecture.Client.Infrastructure.Managers.Dashboard
Expand All @@ -29,10 +26,8 @@ public async Task<IResult<DashboardDataResponse>> GetDataAsync()
}
catch (Exception ex)
{

throw;
}

}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ namespace BlazorHero.CleanArchitecture.Client.Infrastructure.Managers.Dashboard
public interface IDashboardManager : IManager
{
Task<IResult<DashboardDataResponse>> GetDataAsync();

}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BlazorHero.CleanArchitecture.Client.Infrastructure.Routes
namespace BlazorHero.CleanArchitecture.Client.Infrastructure.Routes
{
public class DashboardEndpoint
{
public static string GetData = "api/v1/dashboard";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ public static string GetAllPaged(int pageNumber, int pageSize)
{
return $"api/v1/products?pageNumber={pageNumber}&pageSize={pageSize}";
}

public static string GetCount = "api/v1/products/count";

public static string GetProductImage(int productId)
{
return $"api/v1/products/image/{productId}";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Migrations;
using System;

namespace BlazorHero.CleanArchitecture.Infrastructure.Migrations
{
Expand Down Expand Up @@ -314,4 +314,4 @@ protected override void Down(MigrationBuilder migrationBuilder)
schema: "Identity");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using BlazorHero.CleanArchitecture.Application.Interfaces.Repositories;
using BlazorHero.CleanArchitecture.Domain.Entities.Catalog;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BlazorHero.CleanArchitecture.Infrastructure.Repositories
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public async Task<Result<string>> UpdatePermissionsAsync(PermissionRequest reque
return Result<string>.Fail(ex.Message);
}
}

public async Task<int> GetCountAsync()
{
var count = await _roleManager.Roles.CountAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public void Cancel()

private async Task SaveAsync()
{

form.Validate();
if (form.IsValid)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using BlazorHero.CleanArchitecture.Application.Features.Products.Queries.GetAllPaged;
using BlazorHero.CleanArchitecture.Application.Requests.Catalog;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
using MudBlazor;
using System;
using System.Collections.Generic;
Expand All @@ -25,12 +23,14 @@ private async Task<TableData<GetAllPagedProductsResponse>> ServerReload(TableSta
await LoadData(state.Page, state.PageSize);
return new TableData<GetAllPagedProductsResponse>() { TotalItems = totalItems, Items = pagedData };
}

private ClaimsPrincipal AuthenticationStateProviderUser { get; set; }

protected override async Task OnParametersSetAsync()
{
AuthenticationStateProviderUser = await _stateProvider.GetAuthenticationStateProviderUserAsync();
}

private async Task LoadData(int pageNumber, int pageSize)
{
var request = new GetAllPagedProductsRequest { PageSize = pageSize, PageNumber = pageNumber + 1 };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<MudGrid>
<MudItem xs="12" sm="6" md="3">
<MudPaper Elevation="25" Class="d-flex flex-row pt-6 pb-4" Style="height:100px;">
<MudIcon Icon="@Icons.Material.Filled.Euro" Color="Color.Primary" Class="mx-4" Style="width:54px; height:54px;"></MudIcon>
<MudIcon Icon="@Icons.Material.Filled.ViewCarousel" Color="Color.Primary" Class="mx-4" Style="width:54px; height:54px;"></MudIcon>
<div>
<MudText Typo="Typo.subtitle1" Class="mud-text-secondary mb-n1">Products</MudText>
<MudText Typo="Typo.h5">@ProductCount</MudText>
Expand All @@ -13,7 +13,7 @@
</MudItem>
<MudItem xs="12" sm="6" md="3">
<MudPaper Elevation="25" Class="d-flex flex-row pt-6 pb-4" Style="height:100px;">
<MudIcon Icon="@Icons.Material.Filled.Home" Color="Color.Secondary" Class="mx-4" Style="width:54px; height:54px;"></MudIcon>
<MudIcon Icon="@Icons.Material.Filled.PanoramaPhotosphereSelect" Color="Color.Secondary" Class="mx-4" Style="width:54px; height:54px;"></MudIcon>
<div>
<MudText Typo="Typo.subtitle1" Class="mud-text-secondary mb-n1">Brands</MudText>
<MudText Typo="Typo.h5">@BrandCount</MudText>
Expand All @@ -22,7 +22,7 @@
</MudItem>
<MudItem xs="12" sm="6" md="3">
<MudPaper Elevation="25" Class="d-flex flex-row pt-6 pb-4" Style="height:100px;">
<MudIcon Icon="@Icons.Material.Filled.Public" Color="Color.Success" Class="mx-4" Style="width:54px; height:54px;"></MudIcon>
<MudIcon Icon="@Icons.Material.Filled.Face" Color="Color.Success" Class="mx-4" Style="width:54px; height:54px;"></MudIcon>
<div>
<MudText Typo="Typo.subtitle1" Class="mud-text-secondary mb-n1">Registered Users</MudText>
<MudText Typo="Typo.h5">@UserCount</MudText>
Expand All @@ -31,7 +31,7 @@
</MudItem>
<MudItem xs="12" sm="6" md="3">
<MudPaper Elevation="25" Class="d-flex flex-row pt-6 pb-4" Style="height:100px;">
<MudIcon Icon="@Icons.Custom.Uncategorized.Radioactive" Color="Color.Warning" Class="mx-4" Style="width:54px; height:54px;"></MudIcon>
<MudIcon Icon="@Icons.Material.Filled.Groups" Color="Color.Warning" Class="mx-4" Style="width:54px; height:54px;"></MudIcon>
<div>
<MudText Typo="Typo.subtitle1" Class="mud-text-secondary mb-n1">Registered Roles</MudText>
<MudText Typo="Typo.h5">@RoleCount</MudText>
Expand Down Expand Up @@ -64,12 +64,12 @@
private async Task LoadDataAsync()
{
var data = await _dashboardManager.GetDataAsync();
if(data.Succeeded)
if (data.Succeeded)
{
ProductCount = data.Data.ProductCount;
BrandCount = data.Data.BrandCount;
UserCount = data.Data.UserCount;
RoleCount = data.Data.RoleCount;
}
}
}
}
43 changes: 0 additions & 43 deletions BlazorHero.CleanArchitecture/Client/Pages/Content/Resources.razor

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,21 @@ protected override void OnInitialized()

private async Task ChangePasswordAsync()
{
await _accountManager.ChangePasswordAsync(passwordModel);
var response = await _accountManager.ChangePasswordAsync(passwordModel);
if(response.Succeeded)
{
_snackBar.Add("Password Changed!",Severity.Success);
passwordModel.Password = string.Empty;
passwordModel.NewPassword = string.Empty;
passwordModel.ConfirmNewPassword = string.Empty;
}
else
{
foreach(var error in response.Messages)
{
_snackBar.Add(error, Severity.Error);
}
}
}

private IEnumerable<string> PasswordStrength(string pw)
Expand Down
2 changes: 0 additions & 2 deletions BlazorHero.CleanArchitecture/Client/Shared/NavMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
}
}


<MudListSubheader Class="mt-2 mb-n2">@localizer["Communication"]</MudListSubheader>
<MudNavLink Href="/chat" Icon="@Icons.Material.Outlined.Chat">
@localizer["Chat"]
Expand All @@ -63,7 +62,6 @@
</MudNavLink>
}
}

</MudNavMenu>

@code {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public async Task<IActionResult> GetById(int id)
var brand = await _mediator.Send(new GetBrandByIdQuery() { Id = id });
return Ok(brand);
}

[Authorize(Policy = Permissions.Brands.Create)]
[HttpPost]
public async Task<IActionResult> Post(AddEditBrandCommand command)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public async Task<IActionResult> GetProductImageAsync(int id)
var result = await _mediator.Send(new GetProductImageQuery(id));
return Ok(result);
}

[Authorize(Policy = Permissions.Products.Create)]
[HttpPost]
public async Task<IActionResult> Post(AddEditProductCommand command)
Expand Down
Loading

0 comments on commit 4ddafd7

Please sign in to comment.