Password changing

This commit is contained in:
Aurélie Delhaie
2022-05-29 17:55:34 +02:00
parent 4cf1d4b3b0
commit 2e76c8cd6a
23 changed files with 325 additions and 113 deletions

View File

@@ -25,6 +25,7 @@ namespace OpenSaveCloudClient.Core
private bool bind;
private bool connected;
private ServerInformation? serverInformation;
private User? connectedUser;
private LogManager logManager;
private TaskManager taskManager;
@@ -36,6 +37,7 @@ namespace OpenSaveCloudClient.Core
public int Port { get { return port; } }
public bool Bind { get { return bind; } }
public bool Connected { get { return connected; } }
public User? ConnectedUser { get { return connectedUser; } }
public ServerInformation? ServerInformation { get { return serverInformation; } }
private ServerConnector()
@@ -96,6 +98,7 @@ namespace OpenSaveCloudClient.Core
{
token = accessToken.Token;
connected = true;
connectedUser = GetConnectedUserInformation();
SaveToConfig();
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Ended);
}
@@ -138,6 +141,7 @@ namespace OpenSaveCloudClient.Core
if (accessToken != null && accessToken.Valid)
{
connected = true;
connectedUser = GetConnectedUserInformation();
SaveToConfig();
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Ended);
}
@@ -509,6 +513,69 @@ namespace OpenSaveCloudClient.Core
return false;
}
public User? GetConnectedUserInformation()
{
logManager.AddInformation("Getting user information from the server database");
string uuidTask = taskManager.StartTask("Getting user information", true, 1);
try
{
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Add("Authorization", "bearer " + token);
HttpResponseMessage response = client.GetAsync(string.Format("{0}:{1}/api/v1/user/information", host, port)).Result;
if (response.IsSuccessStatusCode)
{
string responseText = response.Content.ReadAsStringAsync().Result;
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Ended);
return JsonSerializer.Deserialize<User>(responseText);
}
else
{
logManager.AddError(String.Format("Received HTTP Status {0} from the server", response.StatusCode.ToString()));
}
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
}
}
catch (Exception ex)
{
logManager.AddError(ex);
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
}
return null;
}
public bool ChangePassword(NewPassword password)
{
logManager.AddInformation("Changing password");
string uuidTask = taskManager.StartTask("Changing password", true, 1);
try
{
HttpClient client = new HttpClient();
string json = JsonSerializer.Serialize(password);
HttpContent content = new StringContent(json, Encoding.UTF8, "application/json");
client.DefaultRequestHeaders.Add("Authorization", "bearer " + token);
HttpResponseMessage response = client.PostAsync(string.Format("{0}:{1}/api/v1/user/passwd", host, port), content).Result;
if (response.IsSuccessStatusCode)
{
logManager.AddInformation("Password changed");
string responseText = response.Content.ReadAsStringAsync().Result;
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Ended);
return true;
}
else
{
logManager.AddError(String.Format("Received HTTP Status {0} from the server", response.StatusCode.ToString()));
}
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
}
catch (Exception ex)
{
logManager.AddError(ex);
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
}
return false;
}
/// <summary>
/// method <c>UpdateCache</c> update the GameSave object with the server data
/// </summary>

View File

@@ -48,9 +48,15 @@ namespace OpenSaveCloudClient
{
foreach (Game game in remoteGames)
{
ListViewItem lvi = RemoteList.Items.Add(game.Name);
lvi.SubItems.Add(Convert.ToString(game.Id));
lvi.SubItems.Add("");
if (game.Available)
{
if (!saveManager.Saves.Exists(g => g.Id == game.Id))
{
ListViewItem lvi = RemoteList.Items.Add(game.Name);
lvi.SubItems.Add(Convert.ToString(game.Id));
lvi.SubItems.Add("");
}
}
}
}
LockControls(false);

View File

@@ -38,6 +38,7 @@
this.DownloadButton = new System.Windows.Forms.ToolStripButton();
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this.SettingButton = new System.Windows.Forms.ToolStripButton();
this.UserSettingsButton = new System.Windows.Forms.ToolStripButton();
this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
this.LogoutButton = new System.Windows.Forms.ToolStripButton();
this.LogButton = new System.Windows.Forms.ToolStripButton();
@@ -46,7 +47,6 @@
this.TasksButton = new System.Windows.Forms.ToolStripDropDownButton();
this.StatusLabel = new System.Windows.Forms.ToolStripStatusLabel();
this.MainProgressBar = new System.Windows.Forms.ToolStripProgressBar();
this.UserSettingsButton = new System.Windows.Forms.ToolStripButton();
this.toolStrip1.SuspendLayout();
this.statusStrip1.SuspendLayout();
this.SuspendLayout();
@@ -56,12 +56,13 @@
this.listView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.listView1.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.listView1.LargeImageList = this.coverList;
this.listView1.Location = new System.Drawing.Point(0, 33);
this.listView1.Location = new System.Drawing.Point(0, 31);
this.listView1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.listView1.MultiSelect = false;
this.listView1.Name = "listView1";
this.listView1.ShowGroups = false;
this.listView1.ShowItemToolTips = true;
this.listView1.Size = new System.Drawing.Size(1506, 702);
this.listView1.Size = new System.Drawing.Size(1004, 450);
this.listView1.TabIndex = 2;
this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1.DoubleClick += new System.EventHandler(this.listView1_DoubleClick);
@@ -91,8 +92,8 @@
this.AboutButton});
this.toolStrip1.Location = new System.Drawing.Point(0, 0);
this.toolStrip1.Name = "toolStrip1";
this.toolStrip1.Padding = new System.Windows.Forms.Padding(0, 0, 3, 0);
this.toolStrip1.Size = new System.Drawing.Size(1506, 33);
this.toolStrip1.Padding = new System.Windows.Forms.Padding(0, 0, 2, 0);
this.toolStrip1.Size = new System.Drawing.Size(1004, 31);
this.toolStrip1.TabIndex = 3;
this.toolStrip1.Text = "toolStrip1";
//
@@ -103,7 +104,7 @@
this.AddButton.Image = ((System.Drawing.Image)(resources.GetObject("AddButton.Image")));
this.AddButton.ImageTransparentColor = System.Drawing.Color.Magenta;
this.AddButton.Name = "AddButton";
this.AddButton.Size = new System.Drawing.Size(34, 28);
this.AddButton.Size = new System.Drawing.Size(28, 28);
this.AddButton.Text = "Add";
this.AddButton.Click += new System.EventHandler(this.AddButton_Click);
//
@@ -114,7 +115,7 @@
this.SyncButton.Image = ((System.Drawing.Image)(resources.GetObject("SyncButton.Image")));
this.SyncButton.ImageTransparentColor = System.Drawing.Color.Magenta;
this.SyncButton.Name = "SyncButton";
this.SyncButton.Size = new System.Drawing.Size(34, 28);
this.SyncButton.Size = new System.Drawing.Size(28, 28);
this.SyncButton.Text = "Sync";
this.SyncButton.Click += new System.EventHandler(this.SyncButton_Click);
//
@@ -125,14 +126,14 @@
this.DownloadButton.Image = ((System.Drawing.Image)(resources.GetObject("DownloadButton.Image")));
this.DownloadButton.ImageTransparentColor = System.Drawing.Color.Magenta;
this.DownloadButton.Name = "DownloadButton";
this.DownloadButton.Size = new System.Drawing.Size(34, 28);
this.DownloadButton.Size = new System.Drawing.Size(28, 28);
this.DownloadButton.Text = "Download from server";
this.DownloadButton.Click += new System.EventHandler(this.DownloadButton_Click);
//
// toolStripSeparator1
//
this.toolStripSeparator1.Name = "toolStripSeparator1";
this.toolStripSeparator1.Size = new System.Drawing.Size(6, 33);
this.toolStripSeparator1.Size = new System.Drawing.Size(6, 31);
//
// SettingButton
//
@@ -140,14 +141,25 @@
this.SettingButton.Image = ((System.Drawing.Image)(resources.GetObject("SettingButton.Image")));
this.SettingButton.ImageTransparentColor = System.Drawing.Color.Magenta;
this.SettingButton.Name = "SettingButton";
this.SettingButton.Size = new System.Drawing.Size(34, 28);
this.SettingButton.Size = new System.Drawing.Size(28, 28);
this.SettingButton.Text = "Settings";
this.SettingButton.Click += new System.EventHandler(this.ConfigButton_Click);
//
// UserSettingsButton
//
this.UserSettingsButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.UserSettingsButton.Enabled = false;
this.UserSettingsButton.Image = ((System.Drawing.Image)(resources.GetObject("UserSettingsButton.Image")));
this.UserSettingsButton.ImageTransparentColor = System.Drawing.Color.Magenta;
this.UserSettingsButton.Name = "UserSettingsButton";
this.UserSettingsButton.Size = new System.Drawing.Size(28, 28);
this.UserSettingsButton.Text = "User settings";
this.UserSettingsButton.Click += new System.EventHandler(this.UserSettingsButton_Click);
//
// toolStripSeparator2
//
this.toolStripSeparator2.Name = "toolStripSeparator2";
this.toolStripSeparator2.Size = new System.Drawing.Size(6, 33);
this.toolStripSeparator2.Size = new System.Drawing.Size(6, 31);
//
// LogoutButton
//
@@ -156,7 +168,7 @@
this.LogoutButton.Image = ((System.Drawing.Image)(resources.GetObject("LogoutButton.Image")));
this.LogoutButton.ImageTransparentColor = System.Drawing.Color.Magenta;
this.LogoutButton.Name = "LogoutButton";
this.LogoutButton.Size = new System.Drawing.Size(34, 28);
this.LogoutButton.Size = new System.Drawing.Size(28, 28);
this.LogoutButton.Text = "Logout";
this.LogoutButton.Click += new System.EventHandler(this.LogoutButton_Click);
//
@@ -166,7 +178,7 @@
this.LogButton.Image = ((System.Drawing.Image)(resources.GetObject("LogButton.Image")));
this.LogButton.ImageTransparentColor = System.Drawing.Color.Magenta;
this.LogButton.Name = "LogButton";
this.LogButton.Size = new System.Drawing.Size(34, 28);
this.LogButton.Size = new System.Drawing.Size(28, 28);
this.LogButton.Text = "Show logs";
this.LogButton.Click += new System.EventHandler(this.LogButton_Click);
//
@@ -177,7 +189,7 @@
this.AboutButton.Image = ((System.Drawing.Image)(resources.GetObject("AboutButton.Image")));
this.AboutButton.ImageTransparentColor = System.Drawing.Color.Magenta;
this.AboutButton.Name = "AboutButton";
this.AboutButton.Size = new System.Drawing.Size(34, 28);
this.AboutButton.Size = new System.Drawing.Size(28, 28);
this.AboutButton.Text = "About";
this.AboutButton.Click += new System.EventHandler(this.AboutButton_Click);
//
@@ -188,10 +200,9 @@
this.TasksButton,
this.StatusLabel,
this.MainProgressBar});
this.statusStrip1.Location = new System.Drawing.Point(0, 735);
this.statusStrip1.Location = new System.Drawing.Point(0, 481);
this.statusStrip1.Name = "statusStrip1";
this.statusStrip1.Padding = new System.Windows.Forms.Padding(2, 0, 21, 0);
this.statusStrip1.Size = new System.Drawing.Size(1506, 31);
this.statusStrip1.Size = new System.Drawing.Size(1004, 30);
this.statusStrip1.TabIndex = 4;
this.statusStrip1.Text = "statusStrip1";
//
@@ -210,39 +221,29 @@
//
this.StatusLabel.BackColor = System.Drawing.Color.Transparent;
this.StatusLabel.Name = "StatusLabel";
this.StatusLabel.Size = new System.Drawing.Size(0, 24);
this.StatusLabel.Size = new System.Drawing.Size(0, 25);
//
// MainProgressBar
//
this.MainProgressBar.MarqueeAnimationSpeed = 20;
this.MainProgressBar.Name = "MainProgressBar";
this.MainProgressBar.Size = new System.Drawing.Size(150, 23);
this.MainProgressBar.Size = new System.Drawing.Size(100, 24);
this.MainProgressBar.Style = System.Windows.Forms.ProgressBarStyle.Marquee;
this.MainProgressBar.Visible = false;
//
// UserSettingsButton
//
this.UserSettingsButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.UserSettingsButton.Enabled = false;
this.UserSettingsButton.Image = ((System.Drawing.Image)(resources.GetObject("UserSettingsButton.Image")));
this.UserSettingsButton.ImageTransparentColor = System.Drawing.Color.Magenta;
this.UserSettingsButton.Name = "UserSettingsButton";
this.UserSettingsButton.Size = new System.Drawing.Size(34, 28);
this.UserSettingsButton.Text = "User settings";
this.UserSettingsButton.Click += new System.EventHandler(this.UserSettingsButton_Click);
//
// GameLibrary
//
this.AutoScaleDimensions = new System.Drawing.SizeF(144F, 144F);
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
this.BackColor = System.Drawing.SystemColors.Window;
this.ClientSize = new System.Drawing.Size(1506, 766);
this.ClientSize = new System.Drawing.Size(1004, 511);
this.Controls.Add(this.listView1);
this.Controls.Add(this.statusStrip1);
this.Controls.Add(this.toolStrip1);
this.DoubleBuffered = true;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MinimumSize = new System.Drawing.Size(1519, 797);
this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.MinimumSize = new System.Drawing.Size(1018, 544);
this.Name = "GameLibrary";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Game Library";

View File

@@ -65,7 +65,7 @@
AAEAAAD/////AQAAAAAAAAAMAgAAAEZTeXN0ZW0uV2luZG93cy5Gb3JtcywgQ3VsdHVyZT1uZXV0cmFs
LCBQdWJsaWNLZXlUb2tlbj1iNzdhNWM1NjE5MzRlMDg5BQEAAAAmU3lzdGVtLldpbmRvd3MuRm9ybXMu
SW1hZ2VMaXN0U3RyZWFtZXIBAAAABERhdGEHAgIAAAAJAwAAAA8DAAAA7OMCAAJNU0Z0AUkBTAMBAQAB
YAEBAWABAQEIAQEBdgEBBP8BGQEACP8BQgFNATYHAAE2AwABKAMAASABBAIAAXYBAQIAAQEBAAEYBQAB
aAEBAWgBAQEIAQEBdgEBBP8BGQEACP8BQgFNATYHAAE2AwABKAMAASABBAIAAXYBAQIAAQEBAAEYBQAB
QAEUARIRAANSA1EBUgFRBVICUQNSAlEDUgJRAVIEUQFSBVEBUg1RAVAIUQFQAlEBUAFRAVADUQFQAVEE
UAFRAVABUQJQAVECUAFRAVABUQ5QAU8BUAFPAlADTwZQAU8BUAFPAVADTwNQAU8CUAZPAVABTwFQBU8B
UAZPAU4ETwFOBE8BTgVPAU4DTwJOBE8CTgJPAU4BTwFOAU8HTgFPCE4BTwdOAU0GTgJNBE4BTQNOAk0B
@@ -3231,7 +3231,7 @@
<data name="AddButton.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAAFiUAABYlAUlSJPAAAADsSURBVEhLvdU9DgFRFIbhkUjYjL1QKDRKoVTZgEKD5SDY
YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAADsSURBVEhLvdU9DgFRFIbhkUjYjL1QKDRKoVTZgEKD5SDY
AEq9TqEioeY74igm7/yY3HGSp/nuzxk3cW/0j6pIS0YphlKXQjWXZw4LKdTkJrQhKdSENkqzFTrGuKbY
8eMmocwEB0K5Cg6EhGGSnexjWRYMyVmqUpPHJ8sDQ3IUr4vQHIIhKaXBSvrSk7Z4dcUysxRa6zB0Dckq
m0NrHYZuLf4L7Ku9OmLZQDZCax2GxM7d6yQ0h2BISm9wF/sP2G1qVwDNIRgmOXzQWBIMQ/rpwfnV+za1
@@ -3241,7 +3241,7 @@
<data name="SyncButton.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAAFiUAABYlAUlSJPAAAAGfSURBVEhL3dU7L0RBGMbxdY0oaCVa94iGhApfgIKWaIiG
YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAGfSURBVEhL3dU7L0RBGMbxdY0oaCVa94iGhApfgIKWaIiG
xDXiE7iXhESIQiFx+QI+hAqFUqhcC4mQ8H/sjrxnds45OuJJfsmeObPz7u6ZfSfzF1KAJgxhFlMYQB3i
0o/e7Mv4lGISV/iIcYkRlMBlEe5+gwZCacEF7GJJzlALu7h0Iy9deIadeIdDLGMVx3iEnfPqXUtegRrc
w014whjK4KccM3iBXdTKK3AKd/MajUjLLuyiVqSALtyNN7QiKdpda7AL+iIF9uBurGsgJXOwi4VECmxD
@@ -3254,7 +3254,7 @@
<data name="DownloadButton.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAAFiUAABYlAUlSJPAAAAE8SURBVEhL7dRPK0RRGMfxs1CEzSQLZWHBYjZ4AxorxY5i
YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAE8SURBVEhL7dRPK0RRGMfxs1CEzSQLZWHBYjZ4AxorxY5i
pSykycRGyrwPzd4LULK0srIQG6VISWzZTBqL8ff73O4zHcdzdbpjYTG/+izuOed5zv3vOmknPVjDAU5x
iB0Mou2M4xafhjoWkDsjeITVXL1jBhNYxRz6EZV9WE1DL/jwju8wiV8zgFf4jXzS0G8aukYXMjMNq1DN
Qm6HNacyr6IXu7CK1HDKmlNT+JExPMAq8MVsUEUBrfThHtbiUMwG4gmtK9mGtUhtYQkN6AbPmIecrVUj
@@ -3266,7 +3266,7 @@
<data name="SettingButton.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAAFiUAABYlAUlSJPAAAAFZSURBVEhLrdRJSsRAFMbxgIqI7VI9gPNCt251oScSxGmn
YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAFZSURBVEhLrdRJSsRAFMbxgIqI7VI9gPNCt251oScSxGmn
jQsVHHYK6iH0MCrOJ3BCQdH/F+pBESvpVKgPfnR3pfplqFfJOqQHM063BlJmAQ/4de4wjySZxCesuPnA
OKLSxheKxeQaI46+h+aUUc0tZK9uIGQHll2E5lR5QX6WqjsYxRhu3FhdqrmJYJKuQVnURfew4reYQ9Ko
96edLg14mcIRLnGICSTLIvS4/Mf3juA+0SIuYTnCE1RUTaDushZ+hM1RTdWO7g6f9oeiLgsdv0L0BvLl
@@ -3278,7 +3278,7 @@
<data name="UserSettingsButton.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAAFiUAABYlAUlSJPAAAAFsSURBVEhL7dW/K0VhHMfxg+RXyWCQDEabP8BiUFjsWFD8
YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAFsSURBVEhL7dW/K0VhHMfxg+RXyWCQDEabP8BiUFjsWFD8
AYQySGSwSBkMLJTJJAx+JIuUSKEMlDKRH5sfkXh/bvfcvvf03DzO2eRTr27P9z7n27nnec5zgz+bSszg
Bu+4xBhKkTg1uMaXwzHKkSibcDUPzSF2auFqaj2jBLHSAlfTqDrESgNcDaOqEStFeICraegUidIHV2P5
RDOi6cAoulIjj/TjBbb5E9rhyi005zU18kwVujEMNa5AmHzMoxcrsDeyjh4sohCxosa2aS4DyIr2dyd0
@@ -3290,7 +3290,7 @@
<data name="LogoutButton.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAAFiUAABYlAUlSJPAAAAEySURBVEhLxdWxSgMxGMDxUxE6WGgFu3TUN+jW+hAddBLf
YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAEySURBVEhLxdWxSgMxGMDxUxE6WGgFu3TUN+jW+hAddBLf
QqhDQelUcO/eoS+gg046OTjo0EFQ8Q2Elq6C+v/OpnzJ5eRCrP7hBzbJXeAwd8lfVsUhOsoRdhDdPqb4
9HhGVC28w3dzEb3BFczNXnCG/lwX28hrF/JYV9JfOc1gNvjpZr4mkOuGWJMBX+bmIrQPmGvPUUKm39pA
XGMDVnpBaPpa4w6bWKQn3eQMvEKvKeIeW0jTE27H0PMhHlGHNeh2Aj0fagxrwC12A3lU1oBbzCN6QA3W
@@ -3301,7 +3301,7 @@
<data name="LogButton.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAAFiUAABYlAUlSJPAAAAEYSURBVEhLrdU9SgRBFMTxAVM9hRquoHgLvY5uZC6ixzBQ
YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAEYSURBVEhLrdU9SgRBFMTxAVM9hRquoHgLvY5uZC6ixzBQ
UNBAr7HGmpkopgYa+PEv6IFH82psei34MTu99ZplZqGHxuziFm/FTVn7l+zjEz+VD+xhqaziBfXmo1es
oTk7eMA36s0esV7oc/29ZhbQHjYq1IOjU4w5Q9YR7WHzhWxI9Ks3sImnspbRHjbZQA+brNzDJiv3sMnK
PWyycg+bWHrHVbnG9RY2sXSgBXII3V9gRQtJZoizNrF0j61y1f0zjjBPnCPO2sTSMmyycg+bWLqDnm18
@@ -3312,7 +3312,7 @@
<data name="AboutButton.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAAFiUAABYlAUlSJPAAAAIdSURBVEhLlZU5ixVBFEYfqCjIgIMbjo7Lz1BBFBQURtE/
YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIdSURBVEhLlZU5ixVBFEYfqCjIgIMbjo7Lz1BBFBQURtE/
oYN7aqKxgYGha2BoNIlLJjjMgJGBgUtgqMxkOgbuek5P30d1vd7eBweqblXd7v7qdtWgQ7vhEjyHd/Ct
xLaxizANY2sn3IHf8K+DP/AY9kIvnYYViARLcB/OwkyJbWPLEPO+wilo1RXwjVzwCUy0FprkmHOc6xrX
XoZa+eaRfAG2Q19thhcQDxn5kl0QtryE9TCuXDMP5tCuKRjqATjgp241kGgdXIeP4Bz5Ca/hDKTaBp/B
@@ -3330,7 +3330,7 @@
<data name="TasksButton.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAAFiUAABYlAUlSJPAAAAEzSURBVEhL7dXPK8RBGMfx4eCEC7VXhX/ByUGOamudKbm4
YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAEzSURBVEhL7dXPK8RBGMfx4eCEC7VXhX/ByUGOamudKbm4
rNpCKSkXSu3FP+FM4uIvoJSTknV23LY9KNnF+zM7j8baNPtDCp961cyzNU/TzHfW/VQmUcCgn/U4Y3jA
K9Sk6yxgBwMYxS20eBnaiWUC99BvKZ6wB1cNhRNchPEjphFnHfECKbS2y+MlFKSGHJqjHZQQL/AV7WAX
PiuwJqsqfEfmkG0Mf0GKqGDGz7qMrudwY+izBTuoJRVC+rGIzUQb0MVw19B1msUy7LAP0QeLFrfGqe7g

View File

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
namespace OpenSaveCloudClient.Models.Remote
{
public class NewPassword
{
[JsonPropertyName("password")]
public string Password { get; set; }
[JsonPropertyName("verify_password")]
public string VerifyPassword { get; set; }
}
}

View File

@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
namespace OpenSaveCloudClient.Models.Remote
{
public class User
{
[JsonPropertyName("id")]
public long Id { get; set; }
[JsonPropertyName("username")]
public string Username { get; set; }
[JsonPropertyName("role")]
public string Role { get; set; }
[JsonPropertyName("is_admin")]
public bool IsAdmin { get; set; }
}
}

View File

@@ -30,13 +30,13 @@
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(UserForm));
this.label1 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.UsernameBox = new System.Windows.Forms.TextBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.SavePasswordButton = new System.Windows.Forms.Button();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.PasswordAgainBox = new System.Windows.Forms.TextBox();
this.NewPasswordBox = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
@@ -46,21 +46,24 @@
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("Segoe UI", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.label1.ForeColor = System.Drawing.SystemColors.Highlight;
this.label1.Location = new System.Drawing.Point(12, 9);
this.label1.Location = new System.Drawing.Point(8, 6);
this.label1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(287, 48);
this.label1.Size = new System.Drawing.Size(193, 32);
this.label1.TabIndex = 0;
this.label1.Text = "User information";
//
// textBox1
// UsernameBox
//
this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
this.UsernameBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.textBox1.Location = new System.Drawing.Point(12, 122);
this.textBox1.Name = "textBox1";
this.textBox1.ReadOnly = true;
this.textBox1.Size = new System.Drawing.Size(543, 31);
this.textBox1.TabIndex = 1;
this.UsernameBox.CausesValidation = false;
this.UsernameBox.Location = new System.Drawing.Point(8, 81);
this.UsernameBox.Margin = new System.Windows.Forms.Padding(2);
this.UsernameBox.Name = "UsernameBox";
this.UsernameBox.ReadOnly = true;
this.UsernameBox.Size = new System.Drawing.Size(363, 23);
this.UsernameBox.TabIndex = 3;
//
// groupBox1
//
@@ -70,86 +73,101 @@
this.groupBox1.Controls.Add(this.SavePasswordButton);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.textBox3);
this.groupBox1.Controls.Add(this.textBox2);
this.groupBox1.Location = new System.Drawing.Point(12, 184);
this.groupBox1.Controls.Add(this.PasswordAgainBox);
this.groupBox1.Controls.Add(this.NewPasswordBox);
this.groupBox1.Location = new System.Drawing.Point(8, 123);
this.groupBox1.Margin = new System.Windows.Forms.Padding(2);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(543, 225);
this.groupBox1.Padding = new System.Windows.Forms.Padding(2);
this.groupBox1.Size = new System.Drawing.Size(362, 150);
this.groupBox1.TabIndex = 3;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Change password";
//
// textBox2
//
this.textBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.textBox2.Location = new System.Drawing.Point(6, 74);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(531, 31);
this.textBox2.TabIndex = 0;
//
// textBox3
//
this.textBox3.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.textBox3.Location = new System.Drawing.Point(6, 135);
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(531, 31);
this.textBox3.TabIndex = 1;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(6, 46);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(129, 25);
this.label2.TabIndex = 2;
this.label2.Text = "New password";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(6, 108);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(207, 25);
this.label3.TabIndex = 3;
this.label3.Text = "The new password again";
//
// SavePasswordButton
//
this.SavePasswordButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.SavePasswordButton.Enabled = false;
this.SavePasswordButton.Location = new System.Drawing.Point(425, 185);
this.SavePasswordButton.Location = new System.Drawing.Point(283, 123);
this.SavePasswordButton.Margin = new System.Windows.Forms.Padding(2);
this.SavePasswordButton.Name = "SavePasswordButton";
this.SavePasswordButton.Size = new System.Drawing.Size(112, 34);
this.SavePasswordButton.TabIndex = 4;
this.SavePasswordButton.Size = new System.Drawing.Size(75, 23);
this.SavePasswordButton.TabIndex = 2;
this.SavePasswordButton.Text = "Save";
this.SavePasswordButton.UseVisualStyleBackColor = true;
this.SavePasswordButton.Click += new System.EventHandler(this.SavePasswordButton_Click);
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(4, 72);
this.label3.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(136, 15);
this.label3.TabIndex = 3;
this.label3.Text = "The new password again";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(4, 31);
this.label2.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(84, 15);
this.label2.TabIndex = 2;
this.label2.Text = "New password";
//
// PasswordAgainBox
//
this.PasswordAgainBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.PasswordAgainBox.Location = new System.Drawing.Point(4, 90);
this.PasswordAgainBox.Margin = new System.Windows.Forms.Padding(2);
this.PasswordAgainBox.Name = "PasswordAgainBox";
this.PasswordAgainBox.Size = new System.Drawing.Size(355, 23);
this.PasswordAgainBox.TabIndex = 1;
this.PasswordAgainBox.UseSystemPasswordChar = true;
this.PasswordAgainBox.TextChanged += new System.EventHandler(this.NewPasswordBox_TextChanged);
//
// NewPasswordBox
//
this.NewPasswordBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.NewPasswordBox.Location = new System.Drawing.Point(4, 49);
this.NewPasswordBox.Margin = new System.Windows.Forms.Padding(2);
this.NewPasswordBox.Name = "NewPasswordBox";
this.NewPasswordBox.Size = new System.Drawing.Size(355, 23);
this.NewPasswordBox.TabIndex = 0;
this.NewPasswordBox.UseSystemPasswordChar = true;
this.NewPasswordBox.TextChanged += new System.EventHandler(this.NewPasswordBox_TextChanged);
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(12, 94);
this.label4.Location = new System.Drawing.Point(8, 63);
this.label4.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(91, 25);
this.label4.Size = new System.Drawing.Size(60, 15);
this.label4.TabIndex = 4;
this.label4.Text = "Username";
//
// UserForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(144F, 144F);
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
this.BackColor = System.Drawing.SystemColors.Window;
this.ClientSize = new System.Drawing.Size(567, 421);
this.ClientSize = new System.Drawing.Size(382, 292);
this.Controls.Add(this.label4);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.UsernameBox);
this.Controls.Add(this.label1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MinimumSize = new System.Drawing.Size(589, 477);
this.Margin = new System.Windows.Forms.Padding(2);
this.MinimumSize = new System.Drawing.Size(398, 331);
this.Name = "UserForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "User information";
this.Load += new System.EventHandler(this.UserForm_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.ResumeLayout(false);
@@ -160,10 +178,10 @@
#endregion
private Label label1;
private TextBox textBox1;
private TextBox UsernameBox;
private GroupBox groupBox1;
private TextBox textBox2;
private TextBox textBox3;
private TextBox NewPasswordBox;
private TextBox PasswordAgainBox;
private Button SavePasswordButton;
private Label label3;
private Label label2;

View File

@@ -1,4 +1,6 @@
using System;
using OpenSaveCloudClient.Core;
using OpenSaveCloudClient.Models.Remote;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
@@ -12,9 +14,80 @@ namespace OpenSaveCloudClient
{
public partial class UserForm : Form
{
private ServerConnector serverConnector;
public UserForm()
{
InitializeComponent();
serverConnector = ServerConnector.GetInstance();
}
private void UserForm_Load(object sender, EventArgs e)
{
User? u = serverConnector.ConnectedUser;
if (u == null)
{
Close();
return;
}
UsernameBox.Text = u.Username;
}
private void SavePasswordButton_Click(object sender, EventArgs e)
{
LockControls(true);
SavePasswordButton.Enabled = false;
if (string.IsNullOrEmpty(NewPasswordBox.Text) || string.IsNullOrEmpty(PasswordAgainBox.Text))
{
MessageBox.Show(
"Password fields are empty",
"Change password",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
LockControls(false);
return;
}
if (NewPasswordBox.Text != PasswordAgainBox.Text)
{
MessageBox.Show(
"Passwords not matches",
"Change password",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
LockControls(false);
return;
}
new Thread(() =>
{
serverConnector.ChangePassword(new NewPassword { Password = NewPasswordBox.Text, VerifyPassword = PasswordAgainBox.Text });
this.Invoke((MethodInvoker)delegate {
NewPasswordBox.Clear();
PasswordAgainBox.Clear();
LockControls(false);
});
}).Start();
}
private void LockControls(bool l)
{
l = !l;
NewPasswordBox.Enabled = l;
PasswordAgainBox.Enabled = l;
}
private void NewPasswordBox_TextChanged(object sender, EventArgs e)
{
bool valid = true;
if (string.IsNullOrEmpty(NewPasswordBox.Text) || string.IsNullOrEmpty(PasswordAgainBox.Text))
{
valid = false;
}
else if (NewPasswordBox.Text != PasswordAgainBox.Text)
{
valid = false;
}
SavePasswordButton.Enabled = valid;
}
}
}