Compare commits
No commits in common. "master" and "6.3.2" have entirely different histories.
@ -7,11 +7,10 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Meziantou.Framework.Win32.CredentialManager" Version="1.7.6" />
|
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.16" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.16" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="9.0.9" />
|
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="9.0.5" />
|
||||||
<PackageReference Include="RestSharp" Version="112.1.0" />
|
<PackageReference Include="RestSharp" Version="112.1.0" />
|
||||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.14.0" />
|
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.10.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -15,8 +15,6 @@ namespace QtCNETAPI.Services.ApiService
|
|||||||
private RestClient _client;
|
private RestClient _client;
|
||||||
private LoggingService _loggingService;
|
private LoggingService _loggingService;
|
||||||
|
|
||||||
private CredentialService _credService = new();
|
|
||||||
|
|
||||||
internal string? sessionToken;
|
internal string? sessionToken;
|
||||||
internal string apiUri;
|
internal string apiUri;
|
||||||
|
|
||||||
@ -237,9 +235,9 @@ namespace QtCNETAPI.Services.ApiService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ServiceResponse<string>> LoginAsync(UserLoginDto userLoginDto)
|
public async Task<ServiceResponse<User>> LoginAsync(UserLoginDto userLoginDto)
|
||||||
{
|
{
|
||||||
var serviceResponse = new ServiceResponse<string>();
|
var serviceResponse = new ServiceResponse<User>();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -259,11 +257,13 @@ namespace QtCNETAPI.Services.ApiService
|
|||||||
{
|
{
|
||||||
SessionToken = response.Data!;
|
SessionToken = response.Data!;
|
||||||
|
|
||||||
|
await File.WriteAllTextAsync("./session.token", response.Message);
|
||||||
|
|
||||||
var user = await SetCurrentUser();
|
var user = await SetCurrentUser();
|
||||||
|
|
||||||
serviceResponse.Success = true;
|
serviceResponse.Success = true;
|
||||||
if (response.Message != null) serviceResponse.Message = response.Message;
|
if (response.Message != null) serviceResponse.Message = response.Message;
|
||||||
serviceResponse.Data = response.Message;
|
serviceResponse.Data = user;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -413,23 +413,21 @@ namespace QtCNETAPI.Services.ApiService
|
|||||||
public async Task<ServiceResponse<string>> RefreshSessionIfInvalid()
|
public async Task<ServiceResponse<string>> RefreshSessionIfInvalid()
|
||||||
{
|
{
|
||||||
var tokenHandler = new JwtSecurityTokenHandler();
|
var tokenHandler = new JwtSecurityTokenHandler();
|
||||||
var refToken = _credService.GetAccessToken(); // fuck CA1416, if this is being ran on linux it should just crash (theoretically)
|
var refToken = await File.ReadAllTextAsync("./session.token");
|
||||||
|
|
||||||
if (refToken == null)
|
|
||||||
{
|
|
||||||
// treat as session expired
|
|
||||||
return new ServiceResponse<string> { Success = false, Message = "Refresh Token Not Found. Session Expired." };
|
|
||||||
}
|
|
||||||
|
|
||||||
JwtSecurityToken token = tokenHandler.ReadJwtToken(SessionToken);
|
JwtSecurityToken token = tokenHandler.ReadJwtToken(SessionToken);
|
||||||
|
|
||||||
if(DateTime.Compare(DateTime.UtcNow, token.ValidTo) > 0)
|
if(DateTime.Compare(DateTime.UtcNow, token.ValidTo) > 0)
|
||||||
{
|
{
|
||||||
|
if (!File.Exists("./session.token")) { return new ServiceResponse<string> { Success = false, Message = "Session File Not Found. Session Expired." }; }
|
||||||
|
|
||||||
var result = await RefreshLogin(refToken);
|
var result = await RefreshLogin(refToken);
|
||||||
|
|
||||||
if (result == null || result.Success == false)
|
if (result == null || result.Success == false)
|
||||||
{
|
{
|
||||||
return new ServiceResponse<string> { Success = false, Message = "Session Expired." }; // logging in again should overwrite old token
|
File.Delete("./session.token");
|
||||||
|
|
||||||
|
return new ServiceResponse<string> { Success = false, Message = "Session Expired." };
|
||||||
} else return new ServiceResponse<string> { Success = true, Data = refToken };
|
} else return new ServiceResponse<string> { Success = true, Data = refToken };
|
||||||
} else return new ServiceResponse<string> { Success = true, Data = refToken };
|
} else return new ServiceResponse<string> { Success = true, Data = refToken };
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ namespace QtCNETAPI.Services.ApiService
|
|||||||
public Task<ServiceResponse<List<UserInformationDto>>> GetOnlineUsersAsync();
|
public Task<ServiceResponse<List<UserInformationDto>>> GetOnlineUsersAsync();
|
||||||
public Task<ServiceResponse<List<UserInformationDto>>> GetAllUsersAsync();
|
public Task<ServiceResponse<List<UserInformationDto>>> GetAllUsersAsync();
|
||||||
public Task<ServiceResponse<User>> DeleteUserById(string id);
|
public Task<ServiceResponse<User>> DeleteUserById(string id);
|
||||||
public Task<ServiceResponse<string>> LoginAsync(UserLoginDto userLoginDto);
|
public Task<ServiceResponse<User>> LoginAsync(UserLoginDto userLoginDto);
|
||||||
public Task<ServiceResponse<bool>> ResendVerificationEmail(string email);
|
public Task<ServiceResponse<bool>> ResendVerificationEmail(string email);
|
||||||
public Task<ServiceResponse<bool>> SendPasswordResetEmail(string email);
|
public Task<ServiceResponse<bool>> SendPasswordResetEmail(string email);
|
||||||
public Task<ServiceResponse<bool>> ResetPassword(UserPasswordResetDto request);
|
public Task<ServiceResponse<bool>> ResetPassword(UserPasswordResetDto request);
|
||||||
|
@ -1,26 +0,0 @@
|
|||||||
using Meziantou.Framework.Win32;
|
|
||||||
|
|
||||||
namespace QtCNETAPI.Services
|
|
||||||
{
|
|
||||||
public class CredentialService()
|
|
||||||
{
|
|
||||||
public void SaveAccessToken(string username, string accessToken)
|
|
||||||
{
|
|
||||||
string applicationName = "QtC.NET";
|
|
||||||
if (System.Diagnostics.Debugger.IsAttached) applicationName = "QtC.NET.Development";
|
|
||||||
|
|
||||||
CredentialManager.WriteCredential(applicationName, username, accessToken, $"Access Token For User {username} On QtC.NET", CredentialPersistence.LocalMachine);
|
|
||||||
}
|
|
||||||
|
|
||||||
public string? GetAccessToken()
|
|
||||||
{
|
|
||||||
string applicationName = "QtC.NET";
|
|
||||||
if (System.Diagnostics.Debugger.IsAttached) applicationName = "QtC.NET.Development";
|
|
||||||
|
|
||||||
var credential = CredentialManager.ReadCredential(applicationName);
|
|
||||||
if (credential == null) return null;
|
|
||||||
|
|
||||||
return credential.Password;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
4
qtc-net-client-2/Forms/Login.Designer.cs
generated
4
qtc-net-client-2/Forms/Login.Designer.cs
generated
@ -1,6 +1,6 @@
|
|||||||
namespace qtc_net_client_2.Forms
|
namespace qtc_net_client_2.Forms
|
||||||
{
|
{
|
||||||
partial class Login
|
partial class llblForgotPassword
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required designer variable.
|
/// Required designer variable.
|
||||||
@ -28,7 +28,7 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Login));
|
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(llblForgotPassword));
|
||||||
pbLoginBanner = new PictureBox();
|
pbLoginBanner = new PictureBox();
|
||||||
tbEmail = new TextBox();
|
tbEmail = new TextBox();
|
||||||
lblEmail = new Label();
|
lblEmail = new Label();
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
using QtCNETAPI.Services.ApiService;
|
using QtCNETAPI.Services.ApiService;
|
||||||
using QtCNETAPI.Services;
|
|
||||||
using QtCNETAPI.Dtos.User;
|
using QtCNETAPI.Dtos.User;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -10,15 +9,13 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using qtc_net_client_2.Services;
|
|
||||||
|
|
||||||
namespace qtc_net_client_2.Forms
|
namespace qtc_net_client_2.Forms
|
||||||
{
|
{
|
||||||
public partial class Login : Form
|
public partial class llblForgotPassword : Form
|
||||||
{
|
{
|
||||||
private IApiService _apiService;
|
private IApiService _apiService;
|
||||||
private CredentialService _credService = new();
|
public llblForgotPassword(IApiService apiService)
|
||||||
public Login(IApiService apiService)
|
|
||||||
{
|
{
|
||||||
_apiService = apiService;
|
_apiService = apiService;
|
||||||
|
|
||||||
@ -27,14 +24,14 @@ namespace qtc_net_client_2.Forms
|
|||||||
|
|
||||||
private async void frmLogin_Load(object sender, EventArgs e)
|
private async void frmLogin_Load(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
string? accessToken = _credService.GetAccessToken();
|
if (File.Exists("./session.token"))
|
||||||
|
|
||||||
if (accessToken != null)
|
|
||||||
{
|
{
|
||||||
ToggleControls(false, false);
|
ToggleControls(false, false);
|
||||||
|
|
||||||
// try logging in with the token in cred storage
|
// try logging in with the token in the file
|
||||||
var result = await _apiService.RefreshLogin(accessToken);
|
string token = File.ReadAllText("./session.token");
|
||||||
|
|
||||||
|
var result = await _apiService.RefreshLogin(token);
|
||||||
if (result.Success)
|
if (result.Success)
|
||||||
{
|
{
|
||||||
DialogResult = DialogResult.OK;
|
DialogResult = DialogResult.OK;
|
||||||
@ -58,9 +55,8 @@ namespace qtc_net_client_2.Forms
|
|||||||
RememberMe = cbRememberMe.Checked
|
RememberMe = cbRememberMe.Checked
|
||||||
});
|
});
|
||||||
|
|
||||||
if (result.Success && result.Data != null)
|
if (result.Success)
|
||||||
{
|
{
|
||||||
_credService.SaveAccessToken(_apiService.CurrentUser.Username, result.Data);
|
|
||||||
DialogResult = DialogResult.OK;
|
DialogResult = DialogResult.OK;
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ namespace qtc_net_client_2
|
|||||||
if (_apiService.CurrentUser == null)
|
if (_apiService.CurrentUser == null)
|
||||||
{
|
{
|
||||||
// not logged in, load the login form
|
// not logged in, load the login form
|
||||||
Login frmLogin = new Login(_apiService);
|
llblForgotPassword frmLogin = new llblForgotPassword(_apiService);
|
||||||
var result = frmLogin.ShowDialog();
|
var result = frmLogin.ShowDialog();
|
||||||
|
|
||||||
if (result == DialogResult.OK)
|
if (result == DialogResult.OK)
|
||||||
@ -60,7 +60,7 @@ namespace qtc_net_client_2
|
|||||||
private async void llblSignIn_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
|
private async void llblSignIn_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
|
||||||
{
|
{
|
||||||
// just reshow the login dialog lol
|
// just reshow the login dialog lol
|
||||||
Login frmLogin = new Login(_apiService);
|
llblForgotPassword frmLogin = new llblForgotPassword(_apiService);
|
||||||
var result = frmLogin.ShowDialog();
|
var result = frmLogin.ShowDialog();
|
||||||
|
|
||||||
if (result == DialogResult.OK)
|
if (result == DialogResult.OK)
|
||||||
|
@ -81,7 +81,7 @@ namespace qtc_net_client_2.Properties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to 6.3.4.
|
/// Looks up a localized string similar to 6.3.2.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static string AssemblyVersion {
|
internal static string AssemblyVersion {
|
||||||
get {
|
get {
|
||||||
|
@ -173,7 +173,7 @@
|
|||||||
<value>..\Icons\MessageIcon.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
<value>..\Icons\MessageIcon.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="AssemblyVersion" xml:space="preserve">
|
<data name="AssemblyVersion" xml:space="preserve">
|
||||||
<value>6.3.4</value>
|
<value>6.3.2</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="cobalt_sittingatputer" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
<data name="cobalt_sittingatputer" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
<value>..\Resources\cobalt_sittingatputer.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
<value>..\Resources\cobalt_sittingatputer.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user