This commit is contained in:
2022-04-19 00:05:16 +02:00
parent e7c2ae7b8d
commit d7f2348f0d
20 changed files with 924 additions and 49 deletions

View File

@@ -6,23 +6,53 @@ namespace APP;
public partial class Main : Form
{
private Auth? _auth;
private bool _authSucc;
private ImageList _imageListSeason;
private List<SeasonAnime>? _seasonAnime;
private List<Anime>? _seasonAnime;
private User? _user;
public Main()
{
InitializeComponent();
_imageListSeason = new ImageList();
Load += OnLoad;
Load += OnLoadEv;
}
private async void OnLoad(object? sender, EventArgs e)
private async void OnLoadEv(object? sender, EventArgs e)
{
await UpdateData();
_auth = await SaveBoy.ReadAuth();
if (_auth != null)
{
// check if we exist
var users = await BackendComms.GetUser();
if (users == null || users.All(u => u.Username != _auth.Username))
{
// We dont exist
SaveBoy.DeleteAuth();
_auth = null;
}
else
{
// try auth
if (await BackendComms.Auth(_auth.Username, _auth.Secret))
{
// Login successful
loginToolStripMenuItem.Visible = false;
_authSucc = true;
await UpdateUser();
}
else
{
_authSucc = false;
}
}
}
await UpdateSeason();
}
private async Task UpdateData()
private async Task UpdateSeason()
{
_seasonAnime = await BackendComms.GetSeason();
if (_seasonAnime == null)
@@ -40,8 +70,11 @@ public partial class Main : Form
});
}
}
}
_user = await BackendComms.GetUser("ultrasn0w");
private async Task UpdateUser()
{
_user = await BackendComms.GetUser(_auth?.Username);
if (_user == null)
{
ShowError("Fehler beim User abrufen");
@@ -57,7 +90,10 @@ public partial class Main : Form
userLabelInfo.Visible = true;
userLabelInfoData.Text = StringAssemble.UserData(_user);
userLabelInfoData.Visible = true;
userImage.LoadAsync(_user.ImageUrl);
if (!string.IsNullOrWhiteSpace(_user.ImageUrl))
{
userImage.LoadAsync(_user.ImageUrl);
}
}
}
@@ -66,12 +102,38 @@ public partial class Main : Form
MessageBox.Show(text, @"FEHLER", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
private void loginToolStripMenuItem_Click(object sender, EventArgs e)
private async void loginToolStripMenuItem_Click(object sender, EventArgs e)
{
// TODO search for user in backend
if (_authSucc) return;
var users = await BackendComms.GetUser();
if (DoRegister(users))
{
await UpdateUser();
}
}
private void userLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
private bool DoRegister(List<User>? users)
{
// Register promt
var regWin = new RegisterWin(_auth, users);
regWin.ShowDialog();
if (regWin.Cancelled)
{
regWin.Dispose();
return false;
}
_auth = new Auth
{
Username = regWin.Auth.Username,
Secret = regWin.Auth.Secret
};
loginToolStripMenuItem.Visible = false;
regWin.Dispose();
return true;
}
private async void userLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
if (string.IsNullOrWhiteSpace(_user?.Url)) return;
try
@@ -85,7 +147,14 @@ public partial class Main : Form
}
catch (Exception ex)
{
Console.Error.WriteLineAsync(ex.Message);
await Console.Error.WriteLineAsync(ex.Message);
}
}
private void logToolStripMenuItem_Click(object sender, EventArgs e)
{
var logWin = new LogWin(LogBoy.GetLog());
logWin.ShowDialog();
logWin.Dispose();
}
}