Merge branch 'dev-v7' into dev-v6
This commit is contained in:
commit
5c0ac0d728
9 changed files with 54 additions and 30 deletions
|
@ -33,7 +33,7 @@ public class AuthenticationService : IAuthenticationService
|
||||||
private readonly IOptions<ApiConfig> _apiConfig;
|
private readonly IOptions<ApiConfig> _apiConfig;
|
||||||
private readonly ILogger<AuthenticationService> _logger;
|
private readonly ILogger<AuthenticationService> _logger;
|
||||||
private readonly IUserInfoService _infoService;
|
private readonly IUserInfoService _infoService;
|
||||||
private readonly UserPreferenceService _preference;
|
private readonly UserPreferenceService _preferenceService;
|
||||||
private readonly ILocalStorageService _localStorage;
|
private readonly ILocalStorageService _localStorage;
|
||||||
|
|
||||||
public AuthenticationService(
|
public AuthenticationService(
|
||||||
|
@ -42,7 +42,7 @@ public class AuthenticationService : IAuthenticationService
|
||||||
IOptions<ApiConfig> apiConfig,
|
IOptions<ApiConfig> apiConfig,
|
||||||
ILogger<AuthenticationService> logger,
|
ILogger<AuthenticationService> logger,
|
||||||
IUserInfoService infoService,
|
IUserInfoService infoService,
|
||||||
UserPreferenceService preference,
|
UserPreferenceService preferenceService,
|
||||||
ILocalStorageService localStorage
|
ILocalStorageService localStorage
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
@ -51,7 +51,7 @@ public class AuthenticationService : IAuthenticationService
|
||||||
_apiConfig = apiConfig;
|
_apiConfig = apiConfig;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_infoService = infoService;
|
_infoService = infoService;
|
||||||
_preference = preference;
|
_preferenceService = preferenceService;
|
||||||
_localStorage = localStorage;
|
_localStorage = localStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,10 +70,12 @@ public class AuthenticationService : IAuthenticationService
|
||||||
var resContent = await response.Content.ReadAsStringAsync();
|
var resContent = await response.Content.ReadAsStringAsync();
|
||||||
|
|
||||||
if (!response.IsSuccessStatusCode)
|
if (!response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
return new AuthResponseView
|
return new AuthResponseView
|
||||||
{
|
{
|
||||||
IsSuccess = false, ErrorMessage = "Kontroller indtastning"
|
IsSuccess = false, ErrorMessage = "Kontroller indtastning"
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// process response content
|
// process response content
|
||||||
var data = JsonSerializer.Deserialize<AuthResponseView>(resContent, _options);
|
var data = JsonSerializer.Deserialize<AuthResponseView>(resContent, _options);
|
||||||
|
@ -86,7 +88,7 @@ public class AuthenticationService : IAuthenticationService
|
||||||
|
|
||||||
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", data.AccessToken);
|
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", data.AccessToken);
|
||||||
|
|
||||||
var userInfo = await UserInfo();
|
var userInfo = await UserInfo(true);
|
||||||
|
|
||||||
await _infoService.SetUserInfo(userInfo);
|
await _infoService.SetUserInfo(userInfo);
|
||||||
|
|
||||||
|
@ -99,9 +101,10 @@ public class AuthenticationService : IAuthenticationService
|
||||||
public async Task<string> RefreshToken()
|
public async Task<string> RefreshToken()
|
||||||
{
|
{
|
||||||
var refreshToken = await _infoService.GetRefreshToken();
|
var refreshToken = await _infoService.GetRefreshToken();
|
||||||
await Task.Delay(250);
|
// await Task.Delay(250);
|
||||||
if (string.IsNullOrWhiteSpace(refreshToken))
|
if (string.IsNullOrWhiteSpace(refreshToken))
|
||||||
{
|
{
|
||||||
|
_client.DefaultRequestHeaders.Authorization = null;
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,43 +116,50 @@ public class AuthenticationService : IAuthenticationService
|
||||||
|
|
||||||
var response = await _client.PostAsync(_apiConfig.Value.ServicesAuth, new FormUrlEncodedContent(credentials));
|
var response = await _client.PostAsync(_apiConfig.Value.ServicesAuth, new FormUrlEncodedContent(credentials));
|
||||||
var content = await response.Content.ReadAsStringAsync();
|
var content = await response.Content.ReadAsStringAsync();
|
||||||
|
|
||||||
if (!response.IsSuccessStatusCode || string.IsNullOrWhiteSpace(content))
|
if (!response.IsSuccessStatusCode || string.IsNullOrWhiteSpace(content))
|
||||||
{
|
{
|
||||||
|
_client.DefaultRequestHeaders.Authorization = null;
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
var data = JsonSerializer.Deserialize<AuthResponseView>(content, _options);
|
var data = JsonSerializer.Deserialize<AuthResponseView>(content, _options) ?? new AuthResponseView();
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(data.AccessToken))
|
if (string.IsNullOrWhiteSpace(data.AccessToken))
|
||||||
{
|
{
|
||||||
|
_client.DefaultRequestHeaders.Authorization = null;
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set default request headers using access_token
|
// set default request headers using access_token
|
||||||
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", data.AccessToken);
|
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", data.AccessToken);
|
||||||
|
|
||||||
await _infoService.SetAccessToken(data.AccessToken);
|
await _infoService.SetAccessToken(data.AccessToken);
|
||||||
await _infoService.SetRefreshToken(data.RefreshToken);
|
await _infoService.SetRefreshToken(data.RefreshToken);
|
||||||
await _infoService.SetExpiration((int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds + data.ExpiresIn - 60);
|
await _infoService.SetExpiration((int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds + data.ExpiresIn - 60);
|
||||||
|
|
||||||
return data.AccessToken;
|
return data.AccessToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Logout()
|
public async Task Logout()
|
||||||
{
|
{
|
||||||
_client.DefaultRequestHeaders.Authorization = null;
|
_client.DefaultRequestHeaders.Authorization = null;
|
||||||
var profileBackup = await _preference.GetProfile();
|
var km = await _preferenceService.GetKmMorning();
|
||||||
var km = profileBackup.KmMorning;
|
|
||||||
await _localStorage.ClearAsync();
|
await _localStorage.ClearAsync();
|
||||||
await _preference.SetKmMorning(km);
|
await _preferenceService.SetKmMorning(km);
|
||||||
((AuthStateProvider)_authStateProvider).NotifyUserLogout();
|
((AuthStateProvider)_authStateProvider).NotifyUserLogout();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<UserManagerEditView> UserInfo(bool write = false)
|
public async Task<UserManagerEditView> UserInfo(bool write = false)
|
||||||
{
|
{
|
||||||
var response = await _client.GetAsync(_apiConfig.Value.UserInfoAuth).ConfigureAwait(true);
|
var response = await _client.GetAsync(_apiConfig.Value.UserInfoAuth).ConfigureAwait(true);
|
||||||
|
|
||||||
var content = await response.Content.ReadAsStringAsync();
|
var content = await response.Content.ReadAsStringAsync();
|
||||||
var userInfo = JsonSerializer.Deserialize<UserManagerEditView>(content, _options) ?? new UserManagerEditView();
|
var userInfo = JsonSerializer.Deserialize<UserManagerEditView>(content, _options) ?? new UserManagerEditView();
|
||||||
if (write)
|
if (write)
|
||||||
|
{
|
||||||
await _infoService.SetUserInfo(userInfo);
|
await _infoService.SetUserInfo(userInfo);
|
||||||
|
}
|
||||||
return userInfo;
|
return userInfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -43,6 +43,8 @@ public class UserInfoService : IUserInfoService
|
||||||
var x = await GetUserInfo();
|
var x = await GetUserInfo();
|
||||||
return x.UserId;
|
return x.UserId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task<bool> IsSupervisor()
|
public async Task<bool> IsSupervisor()
|
||||||
{
|
{
|
||||||
var x = await GetUserInfo();
|
var x = await GetUserInfo();
|
||||||
|
|
|
@ -27,7 +27,6 @@ public record UserPreference
|
||||||
public string ItemSort { get; set; } = "name";
|
public string ItemSort { get; set; } = "name";
|
||||||
public string PageSize { get; set; } = "10";
|
public string PageSize { get; set; } = "10";
|
||||||
public string WorkDate { get; set; } = "";
|
public string WorkDate { get; set; } = "";
|
||||||
public int KmMorning { get; set; }
|
|
||||||
public bool DateConfirmed { get; set; }
|
public bool DateConfirmed { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,6 +37,7 @@ public class UserPreferenceService
|
||||||
private const string KeyKm = "kmstart";
|
private const string KeyKm = "kmstart";
|
||||||
public event Action<UserPreference>? OnChange;
|
public event Action<UserPreference>? OnChange;
|
||||||
|
|
||||||
|
|
||||||
public UserPreferenceService(ILocalStorageService localStorageService)
|
public UserPreferenceService(ILocalStorageService localStorageService)
|
||||||
{
|
{
|
||||||
_localStorageService = localStorageService;
|
_localStorageService = localStorageService;
|
||||||
|
@ -46,13 +46,13 @@ public class UserPreferenceService
|
||||||
|
|
||||||
public async Task SetKmMorning(int kmMorning)
|
public async Task SetKmMorning(int kmMorning)
|
||||||
{
|
{
|
||||||
await _localStorageService.SetItemAsync(KeyName, kmMorning);
|
await _localStorageService.SetItemAsync(KeyKm, kmMorning);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task<int> GetKmMorning()
|
public async Task<int> GetKmMorning()
|
||||||
{
|
{
|
||||||
return await _localStorageService.GetItemAsync<int>(KeyName);
|
return await _localStorageService.GetItemAsync<int>(KeyKm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -81,6 +81,7 @@ public class UserPreferenceService
|
||||||
OnChange?.Invoke(newPreferences);
|
OnChange?.Invoke(newPreferences);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task SetWorkDate(DateTime workDate)
|
public async Task SetWorkDate(DateTime workDate)
|
||||||
{
|
{
|
||||||
var preferences = await GetProfile();
|
var preferences = await GetProfile();
|
||||||
|
@ -93,6 +94,7 @@ public class UserPreferenceService
|
||||||
OnChange?.Invoke(newPreferences);
|
OnChange?.Invoke(newPreferences);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task SetCompanySearch(string companySearch)
|
public async Task SetCompanySearch(string companySearch)
|
||||||
{
|
{
|
||||||
var preferences = await GetProfile();
|
var preferences = await GetProfile();
|
||||||
|
@ -102,6 +104,7 @@ public class UserPreferenceService
|
||||||
OnChange?.Invoke(newPreferences);
|
OnChange?.Invoke(newPreferences);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task SetCompanySort(string companySort)
|
public async Task SetCompanySort(string companySort)
|
||||||
{
|
{
|
||||||
var preferences = await GetProfile();
|
var preferences = await GetProfile();
|
||||||
|
@ -111,6 +114,7 @@ public class UserPreferenceService
|
||||||
OnChange?.Invoke(newPreferences);
|
OnChange?.Invoke(newPreferences);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task SetItemSearch(string itemSearch)
|
public async Task SetItemSearch(string itemSearch)
|
||||||
{
|
{
|
||||||
var preferences = await GetProfile();
|
var preferences = await GetProfile();
|
||||||
|
@ -120,6 +124,7 @@ public class UserPreferenceService
|
||||||
OnChange?.Invoke(newPreferences);
|
OnChange?.Invoke(newPreferences);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task SetItemSort(string itemSort)
|
public async Task SetItemSort(string itemSort)
|
||||||
{
|
{
|
||||||
var preferences = await GetProfile();
|
var preferences = await GetProfile();
|
||||||
|
@ -129,6 +134,7 @@ public class UserPreferenceService
|
||||||
OnChange?.Invoke(newPreferences);
|
OnChange?.Invoke(newPreferences);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task SetPageSize(string pageSize)
|
public async Task SetPageSize(string pageSize)
|
||||||
{
|
{
|
||||||
var preferences = await GetProfile();
|
var preferences = await GetProfile();
|
||||||
|
@ -138,11 +144,13 @@ public class UserPreferenceService
|
||||||
OnChange?.Invoke(newPreferences);
|
OnChange?.Invoke(newPreferences);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task<UserPreference> GetProfile()
|
public async Task<UserPreference> GetProfile()
|
||||||
{
|
{
|
||||||
return await _localStorageService.GetItemAsync<UserPreference>(KeyName) ?? new UserPreference();
|
return await _localStorageService.GetItemAsync<UserPreference>(KeyName) ?? new UserPreference();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task SetProfile(UserPreference profile)
|
public async Task SetProfile(UserPreference profile)
|
||||||
{
|
{
|
||||||
await _localStorageService.SetItemAsync(KeyName, profile);
|
await _localStorageService.SetItemAsync(KeyName, profile);
|
||||||
|
|
|
@ -76,10 +76,10 @@
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Report.Figures.KmMorning = Preference.KmMorning;
|
Report.Figures.KmMorning = KmMorning;
|
||||||
<td>
|
<td>
|
||||||
<input type="time" id="checkIn" class="form-control"
|
<input type="time" id="checkIn" class="form-control"
|
||||||
@bind-Value="CheckIn" @bind-Value:event="oninput" @onchange="OnTimeChanged"/>
|
@bind-Value="CheckIn" @bind-Value:event="oninput" onchange="@OnTimeChanged"/>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<input type="time" id="checkOut" class="form-control"
|
<input type="time" id="checkOut" class="form-control"
|
||||||
|
|
|
@ -61,6 +61,7 @@ public partial class AdvisorReportCreatePage : IDisposable
|
||||||
private int CurrKmMonth { get; set; }
|
private int CurrKmMonth { get; set; }
|
||||||
private int CurrKmPrivate { get; set; }
|
private int CurrKmPrivate { get; set; }
|
||||||
private bool IsSupervisor { get; set; }
|
private bool IsSupervisor { get; set; }
|
||||||
|
private int KmMorning { get; set; }
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -81,6 +82,8 @@ public partial class AdvisorReportCreatePage : IDisposable
|
||||||
PreferenceService.OnChange += ProfileServiceOnOnChange;
|
PreferenceService.OnChange += ProfileServiceOnOnChange;
|
||||||
|
|
||||||
Preference = await PreferenceService.GetProfile();
|
Preference = await PreferenceService.GetProfile();
|
||||||
|
KmMorning = await PreferenceService.GetKmMorning();
|
||||||
|
|
||||||
Logger.LogDebug("{}", JsonSerializer.Serialize(Preference));
|
Logger.LogDebug("{}", JsonSerializer.Serialize(Preference));
|
||||||
|
|
||||||
WorkDate = Preference.WorkDate;
|
WorkDate = Preference.WorkDate;
|
||||||
|
@ -151,7 +154,7 @@ public partial class AdvisorReportCreatePage : IDisposable
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Report.Figures.KmMorning = Preference.KmMorning;
|
Report.Figures.KmMorning = KmMorning;
|
||||||
}
|
}
|
||||||
|
|
||||||
NoFigures = false;
|
NoFigures = false;
|
||||||
|
|
|
@ -24,27 +24,27 @@
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-6">
|
<div class="col-sm-6">
|
||||||
<h3>@Company.Name</h3>
|
<h2>@Company.Name</h2>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-3 d-flex">
|
<div class="col-sm-3">
|
||||||
<a class="btn btn-primary mx-auto" href="/advisor/customers/@CompanyId"><i class="bi-chevron-left"></i> Stamkort</a>
|
<a class="btn btn-primary" href="/advisor/customers/@CompanyId"><i class="bi-chevron-left"></i> Stamkort</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-3 d-flex">
|
<div class="col-sm-3">
|
||||||
<a class="btn btn-primary mx-auto" href="/advisor/customers/@CompanyId/workplaces/new"><i class="bi-plus-lg"></i> Arbejdssted</a>
|
<a class="btn btn-primary" href="/advisor/customers/@CompanyId/workplaces/new"><i class="bi-plus-lg"></i> Arbejdssted</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
@if (Workplaces.Any())
|
@if (Workplaces.Any())
|
||||||
{
|
{
|
||||||
<div class="list-group">
|
<div class="list-group list-group-flush">
|
||||||
<div class="list-group-item">
|
<div class="list-group-item">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col">
|
<div class="col-sm-4">
|
||||||
<h3>Navn</h3>
|
<h4>Arbejdssted</h4>
|
||||||
</div>
|
</div>
|
||||||
<div class="col">
|
<div class="col-sm-4">
|
||||||
<h3>Beskrivelse</h3>
|
<h4>Beskrivelse</h4>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -147,10 +147,10 @@
|
||||||
<div class="fw-bold mb-1">@docView.VariantName.ToUpperInvariant()</div>
|
<div class="fw-bold mb-1">@docView.VariantName.ToUpperInvariant()</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-4">
|
<div class="col-sm-4">
|
||||||
<span class="me-4">APB</span> <a class="btn btn-outline-dark btn-sm" href="@docView.ApbDocLink" target="_blank">@docView.ApbDocLink</a>
|
<span class="pe-2">APB</span><a class="btn btn-outline-dark btn-sm" href="@docView.ApbDocLink" target="_blank">@docView.ApbDocLink</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-4">
|
<div class="col-sm-4">
|
||||||
<span class="me-3">KAPV</span> <a class="btn btn-outline-dark btn-sm" href="@docView.ApvDocLink" target="_blank">@docView.ApvDocLink</a>
|
<span class="pe-1">KAPV</span><a class="btn btn-outline-dark btn-sm" href="@docView.ApvDocLink" target="_blank">@docView.ApvDocLink</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-2">
|
<div class="col-sm-2">
|
||||||
<button type="button" class="btn btn-danger btn-sm" @onclick="@(() => OnRemoveVariant(docView.ProductId, docView.VariantId))">
|
<button type="button" class="btn btn-danger btn-sm" @onclick="@(() => OnRemoveVariant(docView.ProductId, docView.VariantId))">
|
||||||
|
|
|
@ -110,6 +110,7 @@ public class AuthStateProvider : AuthenticationStateProvider
|
||||||
|
|
||||||
public void NotifyUserLogout()
|
public void NotifyUserLogout()
|
||||||
{
|
{
|
||||||
|
_client.DefaultRequestHeaders.Authorization = null;
|
||||||
var authState = Task.FromResult(_anonymous);
|
var authState = Task.FromResult(_anonymous);
|
||||||
NotifyAuthenticationStateChanged(authState);
|
NotifyAuthenticationStateChanged(authState);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
"Default": "Debug",
|
"Default": "Debug",
|
||||||
"System": "Debug",
|
"System": "Debug",
|
||||||
"Microsoft": "None"
|
"Microsoft": "Information"
|
||||||
},
|
},
|
||||||
"Debug": {
|
"Debug": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
|
|
Loading…
Reference in a new issue