- @if (_adviserInfo != null)
+ @if (UserInfoAdmin != null)
{
@@ -52,7 +52,7 @@
Sælgernr.
- @_adviserInfo.Adviser
+ @UserInfoAdmin.Adviser
|
Landekode
diff --git a/Wonky.Client/Pages/AdminAdviserView.razor.cs b/Wonky.Client/Pages/AdminAdviserView.razor.cs
index e2d53834..de101b12 100644
--- a/Wonky.Client/Pages/AdminAdviserView.razor.cs
+++ b/Wonky.Client/Pages/AdminAdviserView.razor.cs
@@ -18,9 +18,9 @@ public partial class AdminAdviserView : IDisposable
[Inject] private ILogger _logger { get; set; }
[Inject] private NavigationManager _navigator { get; set; }
[Inject] private IToastService _toast { get; set; }
- private AdviserInfoView _adviserInfo { get; set; } = new();
+ private UserInfoAdminView UserInfoAdmin { get; set; } = new();
private EditContext _editContext { get; set; }
- private AdviserUpdateDto _updateInfo { get; set; } = new();
+ private UserUpdateDto _updateInfo { get; set; } = new();
private AdminResetPasswordDto _passwords { get; set; } = new();
private EditContext _passwdContext { get; set; }
private bool _pwInvalid = true;
@@ -38,14 +38,14 @@ public partial class AdminAdviserView : IDisposable
_interceptor.RegisterEvent();
_interceptor.RegisterBeforeSendEvent();
- _adviserInfo = await _userRepo.GetAdviserInfo(UserId);
+ UserInfoAdmin = await _userRepo.GetAdviserInfo(UserId);
- _updateInfo.Email = _adviserInfo.Email;
- _updateInfo.CountryCode = _adviserInfo.CountryCode;
- _updateInfo.FirstName = _adviserInfo.FirstName;
- _updateInfo.LastName = _adviserInfo.LastName;
- _updateInfo.PhoneNumber = _adviserInfo.PhoneNumber;
- _updateInfo.LockoutEnabled = _adviserInfo.LockoutEnabled;
+ _updateInfo.Email = UserInfoAdmin.Email;
+ _updateInfo.CountryCode = UserInfoAdmin.CountryCode;
+ _updateInfo.FirstName = UserInfoAdmin.FirstName;
+ _updateInfo.LastName = UserInfoAdmin.LastName;
+ _updateInfo.PhoneNumber = UserInfoAdmin.PhoneNumber;
+ _updateInfo.LockoutEnabled = UserInfoAdmin.LockoutEnabled;
_passwdContext.OnFieldChanged += PwHandleFieldChanged;
_passwdContext.OnValidationStateChanged += PwValidationChanged;
diff --git a/Wonky.Client/Pages/AdminOfficeLandingPage.razor b/Wonky.Client/Pages/AdminOfficeLandingPage.razor
new file mode 100644
index 00000000..89e01a65
--- /dev/null
+++ b/Wonky.Client/Pages/AdminOfficeLandingPage.razor
@@ -0,0 +1,9 @@
+@page "/admin/users/office"
+
+
+
+@code {
+
+}
\ No newline at end of file
diff --git a/Wonky.Client/Pages/AdminOfficeList.razor b/Wonky.Client/Pages/AdminOfficeList.razor
new file mode 100644
index 00000000..9b40cb90
--- /dev/null
+++ b/Wonky.Client/Pages/AdminOfficeList.razor
@@ -0,0 +1,13 @@
+@using Wonky.Client.Components
+@using Microsoft.AspNetCore.Authorization
+@attribute [Authorize(Roles = "Admin")]
+@page "/admin/users/office/{CountryCode}"
+
+
\ No newline at end of file
diff --git a/Wonky.Client/Pages/AdminOfficeList.razor.cs b/Wonky.Client/Pages/AdminOfficeList.razor.cs
new file mode 100644
index 00000000..898e6e39
--- /dev/null
+++ b/Wonky.Client/Pages/AdminOfficeList.razor.cs
@@ -0,0 +1,30 @@
+using Microsoft.AspNetCore.Components;
+using Wonky.Client.HttpInterceptors;
+using Wonky.Client.HttpRepository;
+using Wonky.Entity.DTO;
+
+namespace Wonky.Client.Pages;
+
+public partial class AdminOfficeList : IDisposable
+{
+ [Parameter] public string CountryCode { get; set; } = "";
+ [Inject] private HttpInterceptorService _interceptor { get; set; }
+ [Inject] private IUserHttpRepository _userRepo { get; set; }
+ private List _adminUsers { get; set; } = new();
+
+
+ protected override async Task OnInitializedAsync()
+ {
+ _interceptor.RegisterEvent();
+ _interceptor.RegisterBeforeSendEvent();
+ var adviserList = await _userRepo.GetAdminUsers();
+ _adminUsers = adviserList
+ .Where(x => x.CountryCode.ToLower() == CountryCode)
+ .ToList();
+ }
+
+ public void Dispose()
+ {
+ _interceptor.DisposeEvent();
+ }
+}
\ No newline at end of file
diff --git a/Wonky.Client/Pages/AdminOfficeView.razor b/Wonky.Client/Pages/AdminOfficeView.razor
new file mode 100644
index 00000000..3de328cd
--- /dev/null
+++ b/Wonky.Client/Pages/AdminOfficeView.razor
@@ -0,0 +1,115 @@
+@page "/admin/users/office/{CountryCode}/{UserId}/view"
+@using Microsoft.AspNetCore.Authorization
+@attribute [Authorize(Roles = "Admin")]
+
+
+
+
+ @if (UserInfoAdmin != null)
+ {
+
+
+
+
+
+
+
+
+ Fornavn
+ |
+
+
+
+ |
+
+ Efternavn
+ |
+
+
+
+ |
+
+
+
+ Email
+ |
+
+
+
+ |
+
+ Mobilnummer
+ |
+
+
+
+ |
+
+
+
+ Sælgernr.
+ |
+
+ @UserInfoAdmin.Adviser
+ |
+
+ Landekode
+ |
+
+ @_updateInfo.CountryCode
+ |
+
+
+
+ Spærret
+ |
+
+
+
+ |
+
+
+
+
+
+
+
+
+
+ NULSTIL ADGANGSKODE
+
+
+
+
+ }
+ else
+ {
+
+ }
+
+
\ No newline at end of file
diff --git a/Wonky.Client/Pages/AdminOfficeView.razor.cs b/Wonky.Client/Pages/AdminOfficeView.razor.cs
new file mode 100644
index 00000000..b93d2073
--- /dev/null
+++ b/Wonky.Client/Pages/AdminOfficeView.razor.cs
@@ -0,0 +1,93 @@
+using System.Security.Policy;
+using System.Text.Json;
+using Blazored.Toast.Services;
+using Microsoft.AspNetCore.Components;
+using Microsoft.AspNetCore.Components.Forms;
+using Wonky.Client.HttpInterceptors;
+using Wonky.Client.HttpRepository;
+using Wonky.Entity.DTO;
+
+namespace Wonky.Client.Pages;
+
+public partial class AdminOfficeView : IDisposable
+{
+ [Parameter] public string UserId { get; set; } = "";
+ [Parameter] public string CountryCode { get; set; } = "";
+ [Inject] private HttpInterceptorService _interceptor { get; set; }
+ [Inject] private IUserHttpRepository _userRepo { get; set; }
+ [Inject] private ILogger _logger { get; set; }
+ [Inject] private NavigationManager _navigator { get; set; }
+ [Inject] private IToastService _toast { get; set; }
+ private UserInfoAdminView UserInfoAdmin { get; set; } = new();
+ private EditContext _editContext { get; set; }
+ private UserUpdateDto _updateInfo { get; set; } = new();
+ private AdminResetPasswordDto _passwords { get; set; } = new();
+ private EditContext _passwdContext { get; set; }
+ private bool _pwInvalid = true;
+
+ private readonly JsonSerializerOptions? _options = new JsonSerializerOptions
+ {
+ PropertyNameCaseInsensitive = true
+ };
+
+ protected override async Task OnParametersSetAsync()
+ {
+ _editContext = new EditContext(_updateInfo);
+ _passwdContext = new EditContext(_passwords);
+
+ _interceptor.RegisterEvent();
+ _interceptor.RegisterBeforeSendEvent();
+
+ UserInfoAdmin = await _userRepo.GetAdminUserInfo(UserId);
+
+ _updateInfo.Email = UserInfoAdmin.Email;
+ _updateInfo.CountryCode = UserInfoAdmin.CountryCode;
+ _updateInfo.FirstName = UserInfoAdmin.FirstName;
+ _updateInfo.LastName = UserInfoAdmin.LastName;
+ _updateInfo.PhoneNumber = UserInfoAdmin.PhoneNumber;
+ _updateInfo.LockoutEnabled = UserInfoAdmin.LockoutEnabled;
+
+ _passwdContext.OnFieldChanged += PwHandleFieldChanged;
+ _passwdContext.OnValidationStateChanged += PwValidationChanged;
+
+ }
+
+ private async Task UpdateUser()
+ {
+ _toast.ShowInfo("Sender data til server ...");
+ await _userRepo.UpdateAdminUser(UserId, _updateInfo);
+ }
+
+ private void PwHandleFieldChanged(object sender, FieldChangedEventArgs e)
+ {
+ _pwInvalid = !_passwdContext.Validate();
+
+ StateHasChanged();
+ }
+ private void PwValidationChanged(object sender, ValidationStateChangedEventArgs e)
+ {
+ _pwInvalid = true;
+
+ _passwdContext.OnFieldChanged -= PwHandleFieldChanged;
+ _passwdContext.OnValidationStateChanged -= PwValidationChanged;
+
+ _passwdContext = new EditContext(_passwords);
+
+ _passwdContext.OnFieldChanged += PwHandleFieldChanged;
+ _passwdContext.OnValidationStateChanged += PwValidationChanged;
+ }
+
+ private async Task SetPassword()
+ {
+ await _userRepo.ResetUserPassword(UserId, _passwords.NewPassword, _passwords.ConfirmPassword);
+ _toast.ShowInfo("Password er nulstillet.");
+ _passwords.NewPassword = "";
+ _passwords.ConfirmPassword = "";
+ }
+ public void Dispose()
+ {
+ _interceptor.DisposeEvent();
+ _passwdContext.OnFieldChanged -= PwHandleFieldChanged;
+ _passwdContext.OnValidationStateChanged -= PwValidationChanged;
+ }
+}
\ No newline at end of file
diff --git a/Wonky.Client/Pages/Index.razor b/Wonky.Client/Pages/Index.razor
index 0ae814b6..7fe69c47 100644
--- a/Wonky.Client/Pages/Index.razor
+++ b/Wonky.Client/Pages/Index.razor
@@ -23,18 +23,7 @@
@attribute [Authorize(Roles = "Adviser,Admin,Supervisor")]
-
-
-
-
-
-
+
@code{
-
-
}
diff --git a/Wonky.Client/Services/AuthenticationService.cs b/Wonky.Client/Services/AuthenticationService.cs
index db6aaff3..2c490cda 100644
--- a/Wonky.Client/Services/AuthenticationService.cs
+++ b/Wonky.Client/Services/AuthenticationService.cs
@@ -58,7 +58,6 @@ namespace Wonky.Client.Services
var resContent = await response.Content.ReadAsStringAsync();
- // if not success - return error status
if (!response.IsSuccessStatusCode)
return new AuthResponseView
{
@@ -71,10 +70,11 @@ namespace Wonky.Client.Services
await _localStorage.SetItemAsync("_xr", data.RefreshToken);
await _localStorage.SetItemAsync("_xe", (int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds + data.ExpiresIn - 60);
- // set default request headers using access_token
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", data.AccessToken);
+
var userInfo = await UserInfo();
await _localStorage.SetItemAsync("_xu", userInfo);
+
// notify system on state change
((AuthStateProvider)_authStateProvider).NotifyUserAuthenticationAsync(data.AccessToken);
data.IsSuccess = true;
@@ -90,9 +90,15 @@ namespace Wonky.Client.Services
["refresh_token"] = refreshToken
};
var response = await _client.PostAsync(_apiConfig.Value.TokenUri, new FormUrlEncodedContent(credentials));
- if (!response.IsSuccessStatusCode) return string.Empty;
+ if (!response.IsSuccessStatusCode)
+ return string.Empty;
+
var resContent = await response.Content.ReadAsStringAsync();
var data = JsonSerializer.Deserialize(resContent, _options);
+
+ if (string.IsNullOrWhiteSpace(data.AccessToken))
+ return string.Empty;
+
// set default request headers using access_token
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", data.AccessToken);
await _localStorage.SetItemAsync("_xa", data.AccessToken);
diff --git a/Wonky.Client/Shared/AuthStateProvider.cs b/Wonky.Client/Shared/AuthStateProvider.cs
index 738e194c..d542f0f5 100644
--- a/Wonky.Client/Shared/AuthStateProvider.cs
+++ b/Wonky.Client/Shared/AuthStateProvider.cs
@@ -36,17 +36,14 @@ namespace Wonky.Client.Shared
public override async Task GetAuthenticationStateAsync()
{
- // fetch token from localStorage
var token = await _storage.GetItemAsync("_xa");
if (string.IsNullOrEmpty(token))
- // return anonymous if empty
return _anonymous;
- // create an authorized user
+
var userInfo = await _storage.GetItemAsync("_xu");
if (userInfo == null)
return _anonymous;
- // set client authorization header
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", token);
var exp = await _storage.GetItemAsync("_xe");
var roles = ExtractRoles(userInfo);
@@ -69,18 +66,12 @@ namespace Wonky.Client.Shared
public async void NotifyUserAuthenticationAsync(string token)
{
if (string.IsNullOrEmpty(token))
- // do nothing
return;
- // set client authorization header
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", token);
- // create an authorized user
- var userInfo = await _storage.GetItemAsync("_xu")
- ;
-
- var exp = await _storage.GetItemAsync("_xe")
- ;
+ var userInfo = await _storage.GetItemAsync("_xu");
+ var exp = await _storage.GetItemAsync("_xe");
var roles = ExtractRoles(userInfo);
var claims = new List
@@ -91,13 +82,12 @@ namespace Wonky.Client.Shared
new(ClaimTypes.Expiration, exp)
};
claims.AddRange(roles.Select(role => new Claim(ClaimTypes.Role, role)));
- // create authState
+
var authState = Task.FromResult(
new AuthenticationState(
new ClaimsPrincipal(
new ClaimsIdentity(claims, "token"))));
- // send authState to notifier
NotifyAuthenticationStateChanged(authState);
}
public void NotifyUserLogout()
diff --git a/Wonky.Client/Shared/NavMenu.razor b/Wonky.Client/Shared/NavMenu.razor
index a516e7b2..1fe86461 100644
--- a/Wonky.Client/Shared/NavMenu.razor
+++ b/Wonky.Client/Shared/NavMenu.razor
@@ -42,10 +42,15 @@
-
+
Sælgere
+
+
+ Admins
+
+
diff --git a/Wonky.Client/wwwroot/appsettings.json b/Wonky.Client/wwwroot/appsettings.json
index 7be9bce0..c52ff250 100644
--- a/Wonky.Client/wwwroot/appsettings.json
+++ b/Wonky.Client/wwwroot/appsettings.json
@@ -1,7 +1,7 @@
{
"appInfo": {
"name": "Wonky Client",
- "version": "0.8.44",
+ "version": "0.8.51",
"isBeta": true,
"image": "grumpy-coder.png"
},
@@ -23,6 +23,7 @@
"productUri": "history/products",
"syncUri": "history/sync",
"adminAdviserUri": "api/v2/admin/users/advisers",
+ "adminUserUri": "api/v2/admin/users/office",
"adminPasswdUri": "api/v2/admin/users/passwd",
"adminReportUri": "reports",
"adminCompanyUri": "companies"
diff --git a/Wonky.Entity/Configuration/ApiConfig.cs b/Wonky.Entity/Configuration/ApiConfig.cs
index 252c2084..5f33be71 100644
--- a/Wonky.Entity/Configuration/ApiConfig.cs
+++ b/Wonky.Entity/Configuration/ApiConfig.cs
@@ -35,6 +35,7 @@ public class ApiConfig
public string ProductUri { get; set; } = "";
public string SyncUri { get; set; } = "";
public string AdminAdviserUri { get; set; } = "";
+ public string AdminUserUri { get; set; } = "";
public string AdminPasswdUri { get; set; } = "";
diff --git a/Wonky.Entity/DTO/AdviserInfoView.cs b/Wonky.Entity/DTO/UserInfoAdminView.cs
similarity index 97%
rename from Wonky.Entity/DTO/AdviserInfoView.cs
rename to Wonky.Entity/DTO/UserInfoAdminView.cs
index f4e6dbde..429b0aca 100644
--- a/Wonky.Entity/DTO/AdviserInfoView.cs
+++ b/Wonky.Entity/DTO/UserInfoAdminView.cs
@@ -2,7 +2,7 @@ using System.ComponentModel.DataAnnotations;
namespace Wonky.Entity.DTO;
-public class AdviserInfoView
+public class UserInfoAdminView
{
[Required(ErrorMessage = "Fornavn skal angives.")]
[MaxLength(50,ErrorMessage = "Der kan højst bruges 50 tegn.")]
diff --git a/Wonky.Entity/DTO/AdminAdviserListView.cs b/Wonky.Entity/DTO/UserListAdminView.cs
similarity index 90%
rename from Wonky.Entity/DTO/AdminAdviserListView.cs
rename to Wonky.Entity/DTO/UserListAdminView.cs
index 30446c84..fa70f123 100644
--- a/Wonky.Entity/DTO/AdminAdviserListView.cs
+++ b/Wonky.Entity/DTO/UserListAdminView.cs
@@ -1,6 +1,6 @@
namespace Wonky.Entity.DTO;
-public class AdminAdviserListView
+public class UserListAdminView
{
public string UserId { get; set; } = "";
public string SalesRep { get; set; } = "";
diff --git a/Wonky.Entity/DTO/AdviserUpdateDto.cs b/Wonky.Entity/DTO/UserUpdateDto.cs
similarity index 96%
rename from Wonky.Entity/DTO/AdviserUpdateDto.cs
rename to Wonky.Entity/DTO/UserUpdateDto.cs
index 84bd1a95..a22a7a01 100644
--- a/Wonky.Entity/DTO/AdviserUpdateDto.cs
+++ b/Wonky.Entity/DTO/UserUpdateDto.cs
@@ -2,7 +2,7 @@ using System.ComponentModel.DataAnnotations;
namespace Wonky.Entity.DTO;
-public class AdviserUpdateDto
+public class UserUpdateDto
{
[Required(ErrorMessage = "Fornavn skal angives.")]
[MaxLength(50,ErrorMessage = "Der kan højst bruges 50 tegn.")]
|