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