Change username and password of other users

This commit is contained in:
Aurélie Delhaie
2022-07-14 18:33:30 +02:00
parent 8bf7c85112
commit 5d96a98b5e
21 changed files with 2960 additions and 2724 deletions

View File

@@ -35,12 +35,14 @@ namespace OpenSaveCloudClient.Core
{ {
Log log = new() Log log = new()
{ {
Timestamp = DateTime.Now,
Message = message, Message = message,
Severity = LogSeverity.Error, Severity = LogSeverity.Error,
}; };
messages.Add(log); messages.Add(log);
NewMessageEventArgs args = new() NewMessageEventArgs args = new()
{ {
Timestamp = DateTime.Now,
Message = message, Message = message,
Severity = LogSeverity.Error, Severity = LogSeverity.Error,
}; };
@@ -51,12 +53,14 @@ namespace OpenSaveCloudClient.Core
{ {
Log log = new() Log log = new()
{ {
Timestamp = DateTime.Now,
Message = message, Message = message,
Severity = LogSeverity.Information, Severity = LogSeverity.Information,
}; };
messages.Add(log); messages.Add(log);
NewMessageEventArgs args = new() NewMessageEventArgs args = new()
{ {
Timestamp = DateTime.Now,
Message = message, Message = message,
Severity = LogSeverity.Information, Severity = LogSeverity.Information,
}; };
@@ -67,12 +71,14 @@ namespace OpenSaveCloudClient.Core
{ {
Log log = new() Log log = new()
{ {
Timestamp = DateTime.Now,
Message = message, Message = message,
Severity = LogSeverity.Warning, Severity = LogSeverity.Warning,
}; };
messages.Add(log); messages.Add(log);
NewMessageEventArgs args = new() NewMessageEventArgs args = new()
{ {
Timestamp = DateTime.Now,
Message = message, Message = message,
Severity = LogSeverity.Warning, Severity = LogSeverity.Warning,
}; };
@@ -110,6 +116,7 @@ namespace OpenSaveCloudClient.Core
public class NewMessageEventArgs : EventArgs public class NewMessageEventArgs : EventArgs
{ {
public DateTime Timestamp { get; set; }
public string Message { get; set; } public string Message { get; set; }
public LogSeverity Severity { get; set; } public LogSeverity Severity { get; set; }
} }

View File

@@ -203,7 +203,7 @@ namespace OpenSaveCloudClient.Core
return JsonSerializer.Deserialize<Game>(responseText); return JsonSerializer.Deserialize<Game>(responseText);
} else } else
{ {
logManager.AddError(String.Format("Received HTTP Status {0} from the server", response.StatusCode.ToString())); LogServerError(response);
} }
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed); taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
} }
@@ -365,7 +365,7 @@ namespace OpenSaveCloudClient.Core
} }
else else
{ {
logManager.AddError(String.Format("Received HTTP Status {0} from the server", response.StatusCode.ToString())); LogServerError(response);
} }
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed); taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
} }
@@ -399,7 +399,7 @@ namespace OpenSaveCloudClient.Core
} }
else else
{ {
logManager.AddError(String.Format("Received HTTP Status {0} from the server", response.StatusCode.ToString())); LogServerError(response);
} }
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed); taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
} }
@@ -449,7 +449,7 @@ namespace OpenSaveCloudClient.Core
} }
else else
{ {
logManager.AddError(String.Format("Received HTTP Status {0} from the server", response.StatusCode.ToString())); LogServerError(response);
} }
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed); taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
} }
@@ -518,7 +518,7 @@ namespace OpenSaveCloudClient.Core
} }
else else
{ {
logManager.AddError(String.Format("Received HTTP Status {0} from the server", response.StatusCode.ToString())); LogServerError(response);
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed); taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
} }
} }
@@ -547,7 +547,7 @@ namespace OpenSaveCloudClient.Core
} }
else else
{ {
logManager.AddError(String.Format("Received HTTP Status {0} from the server", response.StatusCode.ToString())); LogServerError(response);
} }
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed); taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
} }
@@ -576,7 +576,7 @@ namespace OpenSaveCloudClient.Core
} }
else else
{ {
logManager.AddError(String.Format("Received HTTP Status {0} from the server", response.StatusCode.ToString())); LogServerError(response);
} }
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed); taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
} }
@@ -608,7 +608,7 @@ namespace OpenSaveCloudClient.Core
} }
else else
{ {
logManager.AddError(String.Format("Received HTTP Status {0} from the server", response.StatusCode.ToString())); LogServerError(response);
} }
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed); taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
} }
@@ -637,7 +637,7 @@ namespace OpenSaveCloudClient.Core
} }
else else
{ {
logManager.AddError(String.Format("Received HTTP Status {0} from the server", response.StatusCode.ToString())); LogServerError(response);
} }
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed); taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
} }
@@ -667,7 +667,7 @@ namespace OpenSaveCloudClient.Core
} }
else else
{ {
logManager.AddError(String.Format("Received HTTP Status {0} from the server", response.StatusCode.ToString())); LogServerError(response);
} }
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed); taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
} }
@@ -696,7 +696,7 @@ namespace OpenSaveCloudClient.Core
} }
else else
{ {
logManager.AddError(String.Format("Received HTTP Status {0} from the server", response.StatusCode.ToString())); LogServerError(response);
} }
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed); taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
} }
@@ -728,7 +728,7 @@ namespace OpenSaveCloudClient.Core
} }
else else
{ {
logManager.AddError(String.Format("Received HTTP Status {0} from the server", response.StatusCode.ToString())); LogServerError(response);
} }
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed); taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
} }
@@ -740,7 +740,7 @@ namespace OpenSaveCloudClient.Core
return false; return false;
} }
public bool ChangePassword(int userId, NewPassword password) public bool ChangePassword(long userId, NewPassword password)
{ {
logManager.AddInformation(string.Format("Changing password of user {0}", userId)); logManager.AddInformation(string.Format("Changing password of user {0}", userId));
string uuidTask = taskManager.StartTask("Changing password", true, 1); string uuidTask = taskManager.StartTask("Changing password", true, 1);
@@ -760,7 +760,39 @@ namespace OpenSaveCloudClient.Core
} }
else else
{ {
logManager.AddError(String.Format("Received HTTP Status {0} from the server", response.StatusCode.ToString())); LogServerError(response);
}
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
}
catch (Exception ex)
{
logManager.AddError(ex);
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
}
return false;
}
public bool ChangeUsername(UpdateUsername newUserInfo)
{
logManager.AddInformation(string.Format("Changing username of user {0}", newUserInfo.Id));
string uuidTask = taskManager.StartTask("Changing username", true, 1);
try
{
HttpClient client = new();
string json = JsonSerializer.Serialize(newUserInfo);
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/admin/user/username", host, port), content).Result;
if (response.IsSuccessStatusCode)
{
logManager.AddInformation("Username changed");
string responseText = response.Content.ReadAsStringAsync().Result;
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Ended);
return true;
}
else
{
LogServerError(response);
} }
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed); taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
} }
@@ -819,7 +851,7 @@ namespace OpenSaveCloudClient.Core
} }
else else
{ {
logManager.AddError(String.Format("Received HTTP Status {0} from the server", response.StatusCode.ToString())); LogServerError(response);
} }
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed); taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
} }
@@ -896,6 +928,19 @@ namespace OpenSaveCloudClient.Core
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed); taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
} }
private void LogServerError(HttpResponseMessage response)
{
string responseText = response.Content.ReadAsStringAsync().Result;
HttpError? error = JsonSerializer.Deserialize<HttpError>(responseText);
if (error != null)
{
logManager.AddError(String.Format("[Server error][{0}] {1}", error.Status, error.Message));
} else
{
logManager.AddError(String.Format("Received HTTP Status {0} from the server", response.StatusCode.ToString()));
}
}
/// <summary> /// <summary>
/// method <c>SaveToConfig</c> save the server connection information to the configuration file /// method <c>SaveToConfig</c> save the server connection information to the configuration file
/// </summary> /// </summary>

View File

@@ -34,6 +34,7 @@
this.Severity = new System.Windows.Forms.ColumnHeader(); this.Severity = new System.Windows.Forms.ColumnHeader();
this.toolStrip1 = new System.Windows.Forms.ToolStrip(); this.toolStrip1 = new System.Windows.Forms.ToolStrip();
this.toolStripButton1 = new System.Windows.Forms.ToolStripButton(); this.toolStripButton1 = new System.Windows.Forms.ToolStripButton();
this.Timestamp = new System.Windows.Forms.ColumnHeader();
this.toolStrip1.SuspendLayout(); this.toolStrip1.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
@@ -43,15 +44,15 @@
| System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.Timestamp,
this.Message, this.Message,
this.Severity}); this.Severity});
this.listView1.GridLines = true; this.listView1.GridLines = true;
this.listView1.Location = new System.Drawing.Point(0, 27); this.listView1.Location = new System.Drawing.Point(0, 40);
this.listView1.Margin = new System.Windows.Forms.Padding(2);
this.listView1.MultiSelect = false; this.listView1.MultiSelect = false;
this.listView1.Name = "listView1"; this.listView1.Name = "listView1";
this.listView1.ShowGroups = false; this.listView1.ShowGroups = false;
this.listView1.Size = new System.Drawing.Size(747, 344); this.listView1.Size = new System.Drawing.Size(1118, 514);
this.listView1.TabIndex = 0; this.listView1.TabIndex = 0;
this.listView1.UseCompatibleStateImageBehavior = false; this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1.View = System.Windows.Forms.View.Details; this.listView1.View = System.Windows.Forms.View.Details;
@@ -69,11 +70,13 @@
// toolStrip1 // toolStrip1
// //
this.toolStrip1.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden; this.toolStrip1.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden;
this.toolStrip1.ImageScalingSize = new System.Drawing.Size(24, 24);
this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripButton1}); this.toolStripButton1});
this.toolStrip1.Location = new System.Drawing.Point(0, 0); this.toolStrip1.Location = new System.Drawing.Point(0, 0);
this.toolStrip1.Name = "toolStrip1"; this.toolStrip1.Name = "toolStrip1";
this.toolStrip1.Size = new System.Drawing.Size(746, 26); this.toolStrip1.Padding = new System.Windows.Forms.Padding(0, 0, 3, 0);
this.toolStrip1.Size = new System.Drawing.Size(1119, 38);
this.toolStrip1.TabIndex = 1; this.toolStrip1.TabIndex = 1;
this.toolStrip1.Text = "toolStrip1"; this.toolStrip1.Text = "toolStrip1";
// //
@@ -83,20 +86,24 @@
this.toolStripButton1.Font = new System.Drawing.Font("Segoe MDL2 Assets", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); this.toolStripButton1.Font = new System.Drawing.Font("Segoe MDL2 Assets", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.toolStripButton1.ImageTransparentColor = System.Drawing.Color.Magenta; this.toolStripButton1.ImageTransparentColor = System.Drawing.Color.Magenta;
this.toolStripButton1.Name = "toolStripButton1"; this.toolStripButton1.Name = "toolStripButton1";
this.toolStripButton1.Size = new System.Drawing.Size(32, 23); this.toolStripButton1.Size = new System.Drawing.Size(46, 33);
this.toolStripButton1.Text = ""; this.toolStripButton1.Text = "";
this.toolStripButton1.Click += new System.EventHandler(this.toolStripButton1_Click); this.toolStripButton1.Click += new System.EventHandler(this.toolStripButton1_Click);
// //
// Timestamp
//
this.Timestamp.Text = "Timestamp";
this.Timestamp.Width = 140;
//
// LogsForm // LogsForm
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); this.AutoScaleDimensions = new System.Drawing.SizeF(144F, 144F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
this.ClientSize = new System.Drawing.Size(746, 369); this.ClientSize = new System.Drawing.Size(1119, 554);
this.Controls.Add(this.toolStrip1); this.Controls.Add(this.toolStrip1);
this.Controls.Add(this.listView1); this.Controls.Add(this.listView1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Margin = new System.Windows.Forms.Padding(2); this.MinimumSize = new System.Drawing.Size(750, 280);
this.MinimumSize = new System.Drawing.Size(507, 205);
this.Name = "LogsForm"; this.Name = "LogsForm";
this.Text = "Logs"; this.Text = "Logs";
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.LogForm_FormClosed); this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.LogForm_FormClosed);
@@ -115,5 +122,6 @@
private ColumnHeader Severity; private ColumnHeader Severity;
private ToolStrip toolStrip1; private ToolStrip toolStrip1;
private ToolStripButton toolStripButton1; private ToolStripButton toolStripButton1;
private ColumnHeader Timestamp;
} }
} }

View File

@@ -33,7 +33,8 @@ namespace OpenSaveCloudClient
{ {
this.Invoke((MethodInvoker)delegate this.Invoke((MethodInvoker)delegate
{ {
ListViewItem lvi = listView1.Items.Add(e.Message); ListViewItem lvi = listView1.Items.Add(e.Timestamp.ToString());
lvi.SubItems.Add(e.Message);
lvi.SubItems.Add(e.Severity.ToString()); lvi.SubItems.Add(e.Severity.ToString());
}); });
} }
@@ -47,7 +48,8 @@ namespace OpenSaveCloudClient
{ {
foreach (Log l in logManager.Messages) foreach (Log l in logManager.Messages)
{ {
ListViewItem lvi = listView1.Items.Add(l.Message); ListViewItem lvi = listView1.Items.Add(l.Timestamp.ToString());
lvi.SubItems.Add(l.Message);
lvi.SubItems.Add(l.Severity.ToString()); lvi.SubItems.Add(l.Severity.ToString());
} }
} }

View File

@@ -15,7 +15,7 @@ namespace OpenSaveCloudClient.Models
public class Log public class Log
{ {
public DateTime Timestamp { get; set; }
public string Message { get; set; } public string Message { get; set; }
public LogSeverity Severity { get; set; } public LogSeverity Severity { get; set; }
} }

View File

@@ -0,0 +1,23 @@
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 HttpError
{
[JsonPropertyName("status")]
public int Status { get; set; }
[JsonPropertyName("timestamp")]
public string Timestamp { get; set; }
[JsonPropertyName("error")]
public string Error { get; set; }
[JsonPropertyName("message")]
public string Message { get; set; }
[JsonPropertyName("path")]
public string Path { get; set; }
}
}

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 UpdateUsername
{
[JsonPropertyName("id")]
public long Id { get; set; }
[JsonPropertyName("username")]
public string Username { get; set; }
}
}

View File

@@ -58,6 +58,16 @@ namespace OpenSaveCloudClient
LockControls(false); LockControls(false);
return; return;
} }
if (!PasswordTool.CheckRequirements(NewPasswordBox.Text))
{
MessageBox.Show(
"Passwords need at least 6 characters",
"Change password",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
LockControls(false);
return;
}
ThreadPool.QueueUserWorkItem(delegate ThreadPool.QueueUserWorkItem(delegate
{ {
serverConnector.ChangePassword(new NewPassword { Password = NewPasswordBox.Text, VerifyPassword = PasswordAgainBox.Text }); serverConnector.ChangePassword(new NewPassword { Password = NewPasswordBox.Text, VerifyPassword = PasswordAgainBox.Text });
@@ -87,6 +97,10 @@ namespace OpenSaveCloudClient
{ {
valid = false; valid = false;
} }
else if (!PasswordTool.CheckRequirements(NewPasswordBox.Text))
{
valid = false;
}
SavePasswordButton.Enabled = valid; SavePasswordButton.Enabled = valid;
} }
} }

View File

@@ -28,262 +28,266 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(UserManagementForm)); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(UserManagementForm));
this.listView1 = new System.Windows.Forms.ListView(); this.listView1 = new System.Windows.Forms.ListView();
this.name = new System.Windows.Forms.ColumnHeader(); this.name = new System.Windows.Forms.ColumnHeader();
this.panel1 = new System.Windows.Forms.Panel(); this.panel1 = new System.Windows.Forms.Panel();
this.label2 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label();
this.DeleteButton = new System.Windows.Forms.Button(); this.DeleteButton = new System.Windows.Forms.Button();
this.UserSettingsButton = new System.Windows.Forms.Button(); this.UserSettingsButton = new System.Windows.Forms.Button();
this.AddButton = new System.Windows.Forms.Button(); this.AddButton = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox(); this.groupBox1 = new System.Windows.Forms.GroupBox();
this.saveUsernameButton = new System.Windows.Forms.Button(); this.saveUsernameButton = new System.Windows.Forms.Button();
this.groupBox2 = new System.Windows.Forms.GroupBox(); this.groupBox2 = new System.Windows.Forms.GroupBox();
this.SavePasswordButton = new System.Windows.Forms.Button(); this.SavePasswordButton = new System.Windows.Forms.Button();
this.label3 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label();
this.PasswordAgainBox = new System.Windows.Forms.TextBox(); this.PasswordAgainBox = new System.Windows.Forms.TextBox();
this.NewPasswordBox = new System.Windows.Forms.TextBox(); this.NewPasswordBox = new System.Windows.Forms.TextBox();
this.UsernameBox = new System.Windows.Forms.TextBox(); this.UsernameBox = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label();
this.panel1.SuspendLayout(); this.panel1.SuspendLayout();
this.groupBox1.SuspendLayout(); this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout(); this.groupBox2.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
// listView1 // listView1
// //
this.listView1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) this.listView1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left))); | System.Windows.Forms.AnchorStyles.Left)));
this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.name}); this.name});
this.listView1.Location = new System.Drawing.Point(12, 86); this.listView1.Location = new System.Drawing.Point(18, 129);
this.listView1.Name = "listView1"; this.listView1.Margin = new System.Windows.Forms.Padding(4);
this.listView1.Size = new System.Drawing.Size(234, 352); this.listView1.Name = "listView1";
this.listView1.TabIndex = 0; this.listView1.Size = new System.Drawing.Size(349, 503);
this.listView1.UseCompatibleStateImageBehavior = false; this.listView1.TabIndex = 0;
this.listView1.View = System.Windows.Forms.View.Details; this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1.SelectedIndexChanged += new System.EventHandler(this.listView1_SelectedIndexChanged); this.listView1.View = System.Windows.Forms.View.Details;
// this.listView1.SelectedIndexChanged += new System.EventHandler(this.listView1_SelectedIndexChanged);
// name //
// // name
this.name.Text = "Name"; //
this.name.Width = 220; this.name.Text = "Name";
// this.name.Width = 220;
// panel1 //
// // panel1
this.panel1.Controls.Add(this.label2); //
this.panel1.Controls.Add(this.DeleteButton); this.panel1.Controls.Add(this.label2);
this.panel1.Controls.Add(this.UserSettingsButton); this.panel1.Controls.Add(this.DeleteButton);
this.panel1.Controls.Add(this.AddButton); this.panel1.Controls.Add(this.UserSettingsButton);
this.panel1.Dock = System.Windows.Forms.DockStyle.Top; this.panel1.Controls.Add(this.AddButton);
this.panel1.Location = new System.Drawing.Point(0, 0); this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
this.panel1.MaximumSize = new System.Drawing.Size(0, 80); this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.MinimumSize = new System.Drawing.Size(0, 80); this.panel1.Margin = new System.Windows.Forms.Padding(4);
this.panel1.Name = "panel1"; this.panel1.MaximumSize = new System.Drawing.Size(0, 120);
this.panel1.Size = new System.Drawing.Size(800, 80); this.panel1.MinimumSize = new System.Drawing.Size(0, 120);
this.panel1.TabIndex = 6; this.panel1.Name = "panel1";
// this.panel1.Size = new System.Drawing.Size(1191, 120);
// label2 this.panel1.TabIndex = 6;
// //
this.label2.AutoSize = true; // label2
this.label2.Font = new System.Drawing.Font("Segoe UI", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); //
this.label2.ForeColor = System.Drawing.Color.LightGray; this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(138, 22); this.label2.Font = new System.Drawing.Font("Segoe UI", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.label2.Name = "label2"; this.label2.ForeColor = System.Drawing.Color.LightGray;
this.label2.Size = new System.Drawing.Size(20, 32); this.label2.Location = new System.Drawing.Point(207, 33);
this.label2.TabIndex = 9; this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label2.Text = "|"; this.label2.Name = "label2";
// this.label2.Size = new System.Drawing.Size(29, 48);
// DeleteButton this.label2.TabIndex = 9;
// this.label2.Text = "|";
this.DeleteButton.Enabled = false; //
this.DeleteButton.FlatAppearance.BorderSize = 0; // DeleteButton
this.DeleteButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat; //
this.DeleteButton.Font = new System.Drawing.Font("Segoe MDL2 Assets", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); this.DeleteButton.Enabled = false;
this.DeleteButton.Location = new System.Drawing.Point(75, 3); this.DeleteButton.FlatAppearance.BorderSize = 0;
this.DeleteButton.Name = "DeleteButton"; this.DeleteButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.DeleteButton.Size = new System.Drawing.Size(57, 74); this.DeleteButton.Font = new System.Drawing.Font("Segoe MDL2 Assets", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.DeleteButton.TabIndex = 1; this.DeleteButton.Location = new System.Drawing.Point(112, 4);
this.DeleteButton.Text = "\r\n\r\nDelete"; this.DeleteButton.Margin = new System.Windows.Forms.Padding(4);
this.DeleteButton.UseVisualStyleBackColor = true; this.DeleteButton.Name = "DeleteButton";
this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click); this.DeleteButton.Size = new System.Drawing.Size(86, 111);
// this.DeleteButton.TabIndex = 1;
// UserSettingsButton this.DeleteButton.Text = "\r\n\r\nDelete";
// this.DeleteButton.UseVisualStyleBackColor = true;
this.UserSettingsButton.FlatAppearance.BorderSize = 0; this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click);
this.UserSettingsButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat; //
this.UserSettingsButton.Font = new System.Drawing.Font("Segoe MDL2 Assets", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); // UserSettingsButton
this.UserSettingsButton.Location = new System.Drawing.Point(164, 3); //
this.UserSettingsButton.Name = "UserSettingsButton"; this.UserSettingsButton.FlatAppearance.BorderSize = 0;
this.UserSettingsButton.Size = new System.Drawing.Size(57, 74); this.UserSettingsButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.UserSettingsButton.TabIndex = 8; this.UserSettingsButton.Font = new System.Drawing.Font("Segoe MDL2 Assets", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.UserSettingsButton.Text = "\r\n\r\nMe"; this.UserSettingsButton.Location = new System.Drawing.Point(246, 4);
this.UserSettingsButton.UseVisualStyleBackColor = true; this.UserSettingsButton.Margin = new System.Windows.Forms.Padding(4);
this.UserSettingsButton.Click += new System.EventHandler(this.UserSettingsButton_Click); this.UserSettingsButton.Name = "UserSettingsButton";
// this.UserSettingsButton.Size = new System.Drawing.Size(86, 111);
// AddButton this.UserSettingsButton.TabIndex = 8;
// this.UserSettingsButton.Text = "\r\n\r\nMe";
this.AddButton.FlatAppearance.BorderSize = 0; this.UserSettingsButton.UseVisualStyleBackColor = true;
this.AddButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.UserSettingsButton.Click += new System.EventHandler(this.UserSettingsButton_Click);
this.AddButton.Font = new System.Drawing.Font("Segoe MDL2 Assets", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); //
this.AddButton.Location = new System.Drawing.Point(12, 3); // AddButton
this.AddButton.Name = "AddButton"; //
this.AddButton.Size = new System.Drawing.Size(57, 74); this.AddButton.FlatAppearance.BorderSize = 0;
this.AddButton.TabIndex = 0; this.AddButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.AddButton.Text = "\r\n\r\nAdd"; this.AddButton.Font = new System.Drawing.Font("Segoe MDL2 Assets", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.AddButton.UseVisualStyleBackColor = true; this.AddButton.Location = new System.Drawing.Point(18, 4);
this.AddButton.Click += new System.EventHandler(this.AddButton_Click); this.AddButton.Margin = new System.Windows.Forms.Padding(4);
// this.AddButton.Name = "AddButton";
// groupBox1 this.AddButton.Size = new System.Drawing.Size(86, 111);
// this.AddButton.TabIndex = 0;
this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) this.AddButton.Text = "\r\n\r\nAdd";
| System.Windows.Forms.AnchorStyles.Left) this.AddButton.UseVisualStyleBackColor = true;
| System.Windows.Forms.AnchorStyles.Right))); this.AddButton.Click += new System.EventHandler(this.AddButton_Click);
this.groupBox1.Controls.Add(this.saveUsernameButton); //
this.groupBox1.Controls.Add(this.groupBox2); // groupBox1
this.groupBox1.Controls.Add(this.UsernameBox); //
this.groupBox1.Controls.Add(this.label4); this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
this.groupBox1.Location = new System.Drawing.Point(252, 86); | System.Windows.Forms.AnchorStyles.Left)
this.groupBox1.Name = "groupBox1"; | System.Windows.Forms.AnchorStyles.Right)));
this.groupBox1.Size = new System.Drawing.Size(536, 352); this.groupBox1.Controls.Add(this.saveUsernameButton);
this.groupBox1.TabIndex = 7; this.groupBox1.Controls.Add(this.groupBox2);
this.groupBox1.TabStop = false; this.groupBox1.Controls.Add(this.UsernameBox);
this.groupBox1.Text = "Detail"; this.groupBox1.Controls.Add(this.label4);
// this.groupBox1.Location = new System.Drawing.Point(378, 129);
// saveUsernameButton this.groupBox1.Margin = new System.Windows.Forms.Padding(4);
// this.groupBox1.Name = "groupBox1";
this.saveUsernameButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.groupBox1.Padding = new System.Windows.Forms.Padding(4);
this.saveUsernameButton.Enabled = false; this.groupBox1.Size = new System.Drawing.Size(804, 503);
this.saveUsernameButton.Location = new System.Drawing.Point(444, 83); this.groupBox1.TabIndex = 7;
this.saveUsernameButton.Margin = new System.Windows.Forms.Padding(2); this.groupBox1.TabStop = false;
this.saveUsernameButton.Name = "saveUsernameButton"; this.groupBox1.Text = "Detail";
this.saveUsernameButton.Size = new System.Drawing.Size(75, 23); //
this.saveUsernameButton.TabIndex = 4; // saveUsernameButton
this.saveUsernameButton.Text = "Save"; //
this.saveUsernameButton.UseVisualStyleBackColor = true; this.saveUsernameButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
// this.saveUsernameButton.Enabled = false;
// groupBox2 this.saveUsernameButton.Location = new System.Drawing.Point(666, 99);
// this.saveUsernameButton.Name = "saveUsernameButton";
this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) this.saveUsernameButton.Size = new System.Drawing.Size(112, 34);
| System.Windows.Forms.AnchorStyles.Left) this.saveUsernameButton.TabIndex = 4;
| System.Windows.Forms.AnchorStyles.Right))); this.saveUsernameButton.Text = "Save";
this.groupBox2.Controls.Add(this.SavePasswordButton); this.saveUsernameButton.UseVisualStyleBackColor = true;
this.groupBox2.Controls.Add(this.label3); this.saveUsernameButton.Click += new System.EventHandler(this.saveUsernameButton_Click);
this.groupBox2.Controls.Add(this.label1); //
this.groupBox2.Controls.Add(this.PasswordAgainBox); // groupBox2
this.groupBox2.Controls.Add(this.NewPasswordBox); //
this.groupBox2.Location = new System.Drawing.Point(5, 135); this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
this.groupBox2.Margin = new System.Windows.Forms.Padding(2); | System.Windows.Forms.AnchorStyles.Left)
this.groupBox2.Name = "groupBox2"; | System.Windows.Forms.AnchorStyles.Right)));
this.groupBox2.Padding = new System.Windows.Forms.Padding(2); this.groupBox2.Controls.Add(this.SavePasswordButton);
this.groupBox2.Size = new System.Drawing.Size(526, 158); this.groupBox2.Controls.Add(this.label3);
this.groupBox2.TabIndex = 8; this.groupBox2.Controls.Add(this.label1);
this.groupBox2.TabStop = false; this.groupBox2.Controls.Add(this.PasswordAgainBox);
this.groupBox2.Text = "Change password"; this.groupBox2.Controls.Add(this.NewPasswordBox);
// this.groupBox2.Location = new System.Drawing.Point(8, 202);
// SavePasswordButton this.groupBox2.Name = "groupBox2";
// this.groupBox2.Size = new System.Drawing.Size(789, 212);
this.SavePasswordButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.groupBox2.TabIndex = 8;
this.SavePasswordButton.Enabled = false; this.groupBox2.TabStop = false;
this.SavePasswordButton.Location = new System.Drawing.Point(439, 124); this.groupBox2.Text = "Change password";
this.SavePasswordButton.Margin = new System.Windows.Forms.Padding(2); //
this.SavePasswordButton.Name = "SavePasswordButton"; // SavePasswordButton
this.SavePasswordButton.Size = new System.Drawing.Size(75, 23); //
this.SavePasswordButton.TabIndex = 2; this.SavePasswordButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.SavePasswordButton.Text = "Save"; this.SavePasswordButton.Enabled = false;
this.SavePasswordButton.UseVisualStyleBackColor = true; this.SavePasswordButton.Location = new System.Drawing.Point(658, 170);
// this.SavePasswordButton.Name = "SavePasswordButton";
// label3 this.SavePasswordButton.Size = new System.Drawing.Size(112, 34);
// this.SavePasswordButton.TabIndex = 2;
this.label3.AutoSize = true; this.SavePasswordButton.Text = "Save";
this.label3.Location = new System.Drawing.Point(14, 72); this.SavePasswordButton.UseVisualStyleBackColor = true;
this.label3.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); this.SavePasswordButton.Click += new System.EventHandler(this.SavePasswordButton_Click);
this.label3.Name = "label3"; //
this.label3.Size = new System.Drawing.Size(136, 15); // label3
this.label3.TabIndex = 3; //
this.label3.Text = "The new password again"; this.label3.AutoSize = true;
// this.label3.Location = new System.Drawing.Point(21, 108);
// label1 this.label3.Name = "label3";
// this.label3.Size = new System.Drawing.Size(207, 25);
this.label1.AutoSize = true; this.label3.TabIndex = 3;
this.label1.Location = new System.Drawing.Point(14, 24); this.label3.Text = "The new password again";
this.label1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); //
this.label1.Name = "label1"; // label1
this.label1.Size = new System.Drawing.Size(84, 15); //
this.label1.TabIndex = 2; this.label1.AutoSize = true;
this.label1.Text = "New password"; this.label1.Location = new System.Drawing.Point(21, 36);
// this.label1.Name = "label1";
// PasswordAgainBox this.label1.Size = new System.Drawing.Size(129, 25);
// this.label1.TabIndex = 2;
this.PasswordAgainBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) this.label1.Text = "New password";
| System.Windows.Forms.AnchorStyles.Right))); //
this.PasswordAgainBox.Enabled = false; // PasswordAgainBox
this.PasswordAgainBox.Location = new System.Drawing.Point(14, 89); //
this.PasswordAgainBox.Margin = new System.Windows.Forms.Padding(2); this.PasswordAgainBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
this.PasswordAgainBox.Name = "PasswordAgainBox"; | System.Windows.Forms.AnchorStyles.Right)));
this.PasswordAgainBox.Size = new System.Drawing.Size(500, 23); this.PasswordAgainBox.Enabled = false;
this.PasswordAgainBox.TabIndex = 1; this.PasswordAgainBox.Location = new System.Drawing.Point(21, 134);
this.PasswordAgainBox.UseSystemPasswordChar = true; this.PasswordAgainBox.Name = "PasswordAgainBox";
// this.PasswordAgainBox.Size = new System.Drawing.Size(748, 31);
// NewPasswordBox this.PasswordAgainBox.TabIndex = 1;
// this.PasswordAgainBox.UseSystemPasswordChar = true;
this.NewPasswordBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) this.PasswordAgainBox.TextChanged += new System.EventHandler(this.NewPasswordBox_TextChanged);
| System.Windows.Forms.AnchorStyles.Right))); //
this.NewPasswordBox.Enabled = false; // NewPasswordBox
this.NewPasswordBox.Location = new System.Drawing.Point(14, 41); //
this.NewPasswordBox.Margin = new System.Windows.Forms.Padding(2); this.NewPasswordBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
this.NewPasswordBox.Name = "NewPasswordBox"; | System.Windows.Forms.AnchorStyles.Right)));
this.NewPasswordBox.Size = new System.Drawing.Size(500, 23); this.NewPasswordBox.Enabled = false;
this.NewPasswordBox.TabIndex = 0; this.NewPasswordBox.Location = new System.Drawing.Point(21, 62);
this.NewPasswordBox.UseSystemPasswordChar = true; this.NewPasswordBox.Name = "NewPasswordBox";
// this.NewPasswordBox.Size = new System.Drawing.Size(748, 31);
// UsernameBox this.NewPasswordBox.TabIndex = 0;
// this.NewPasswordBox.UseSystemPasswordChar = true;
this.UsernameBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) this.NewPasswordBox.TextChanged += new System.EventHandler(this.NewPasswordBox_TextChanged);
| System.Windows.Forms.AnchorStyles.Right))); //
this.UsernameBox.CausesValidation = false; // UsernameBox
this.UsernameBox.Enabled = false; //
this.UsernameBox.Location = new System.Drawing.Point(19, 44); this.UsernameBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
this.UsernameBox.Margin = new System.Windows.Forms.Padding(2); | System.Windows.Forms.AnchorStyles.Right)));
this.UsernameBox.Name = "UsernameBox"; this.UsernameBox.CausesValidation = false;
this.UsernameBox.Size = new System.Drawing.Size(500, 23); this.UsernameBox.Enabled = false;
this.UsernameBox.TabIndex = 9; this.UsernameBox.Location = new System.Drawing.Point(28, 66);
// this.UsernameBox.Name = "UsernameBox";
// label4 this.UsernameBox.Size = new System.Drawing.Size(748, 31);
// this.UsernameBox.TabIndex = 9;
this.label4.AutoSize = true; this.UsernameBox.TextChanged += new System.EventHandler(this.UsernameBox_TextChanged);
this.label4.Location = new System.Drawing.Point(19, 27); //
this.label4.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); // label4
this.label4.Name = "label4"; //
this.label4.Size = new System.Drawing.Size(60, 15); this.label4.AutoSize = true;
this.label4.TabIndex = 10; this.label4.Location = new System.Drawing.Point(28, 40);
this.label4.Text = "Username"; this.label4.Name = "label4";
// this.label4.Size = new System.Drawing.Size(91, 25);
// UserManagementForm this.label4.TabIndex = 10;
// this.label4.Text = "Username";
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); //
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; // UserManagementForm
this.BackColor = System.Drawing.SystemColors.Window; //
this.ClientSize = new System.Drawing.Size(800, 450); this.AutoScaleDimensions = new System.Drawing.SizeF(144F, 144F);
this.Controls.Add(this.groupBox1); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
this.Controls.Add(this.panel1); this.BackColor = System.Drawing.SystemColors.Window;
this.Controls.Add(this.listView1); this.ClientSize = new System.Drawing.Size(1191, 650);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Controls.Add(this.groupBox1);
this.MaximumSize = new System.Drawing.Size(816, 489); this.Controls.Add(this.panel1);
this.MinimumSize = new System.Drawing.Size(816, 489); this.Controls.Add(this.listView1);
this.Name = "UserManagementForm"; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Margin = new System.Windows.Forms.Padding(4);
this.Text = "Management"; this.MaximumSize = new System.Drawing.Size(1213, 706);
this.Load += new System.EventHandler(this.UserManagementForm_Load); this.MinimumSize = new System.Drawing.Size(1213, 706);
this.panel1.ResumeLayout(false); this.Name = "UserManagementForm";
this.panel1.PerformLayout(); this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.groupBox1.ResumeLayout(false); this.Text = "Management";
this.groupBox1.PerformLayout(); this.Load += new System.EventHandler(this.UserManagementForm_Load);
this.groupBox2.ResumeLayout(false); this.panel1.ResumeLayout(false);
this.groupBox2.PerformLayout(); this.panel1.PerformLayout();
this.ResumeLayout(false); this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
this.ResumeLayout(false);
} }
#endregion #endregion

View File

@@ -1,162 +1,278 @@
using OpenSaveCloudClient.Core; using OpenSaveCloudClient.Core;
using OpenSaveCloudClient.Models.Remote; using OpenSaveCloudClient.Models.Remote;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Data; using System.Data;
using System.Drawing; using System.Drawing;
using System.Linq; 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;
namespace OpenSaveCloudClient namespace OpenSaveCloudClient
{ {
public partial class UserManagementForm : Form public partial class UserManagementForm : Form
{ {
private ServerConnector serverConnector; private ServerConnector serverConnector;
public UserManagementForm() public UserManagementForm()
{ {
InitializeComponent(); InitializeComponent();
serverConnector = ServerConnector.GetInstance(); serverConnector = ServerConnector.GetInstance();
} }
private void UserSettingsButton_Click(object sender, EventArgs e) private void UserSettingsButton_Click(object sender, EventArgs e)
{ {
UserForm frm = new(); UserForm frm = new();
frm.ShowDialog(); frm.ShowDialog();
} }
private void UserManagementForm_Load(object sender, EventArgs e) private void UserManagementForm_Load(object sender, EventArgs e)
{ {
LoadUsers(); LoadUsers();
} }
private void LoadUsers() private void LoadUsers()
{ {
ThreadPool.QueueUserWorkItem(delegate ThreadPool.QueueUserWorkItem(delegate
{ {
List<User>? users = serverConnector.GetUsers(); List<User>? users = serverConnector.GetUsers();
if (users != null) if (users != null)
{ {
this.Invoke((MethodInvoker)delegate { this.Invoke((MethodInvoker)delegate {
UpdateRemoteList(users); UpdateRemoteList(users);
}); });
} }
}); });
} }
private void UpdateRemoteList(List<User> users) private void UpdateRemoteList(List<User> users)
{ {
if (serverConnector.ConnectedUser == null) if (serverConnector.ConnectedUser == null)
{ {
Close(); Close();
return; return;
} }
foreach (User user in users) foreach (User user in users)
{ {
if (user.Username != serverConnector.ConnectedUser.Username) if (user.Username != serverConnector.ConnectedUser.Username)
{ {
ListViewItem lvi = listView1.Items.Add(user.Username); ListViewItem lvi = listView1.Items.Add(user.Username);
lvi.SubItems.Add(Convert.ToString(user.Id)); lvi.SubItems.Add(Convert.ToString(user.Id));
lvi.SubItems.Add(user.Role); lvi.SubItems.Add(user.Role);
} }
} }
} }
private void listView1_SelectedIndexChanged(object sender, EventArgs e) private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{ {
NewPasswordBox.Text = ""; NewPasswordBox.Text = "";
PasswordAgainBox.Text = ""; PasswordAgainBox.Text = "";
bool singleActivate = (listView1.SelectedItems.Count == 1); bool singleActivate = (listView1.SelectedItems.Count == 1);
bool multiActivate = (listView1.SelectedItems.Count > 0); bool multiActivate = (listView1.SelectedItems.Count > 0);
DeleteButton.Enabled = multiActivate; DeleteButton.Enabled = multiActivate;
UsernameBox.Enabled = singleActivate; UsernameBox.Enabled = singleActivate;
NewPasswordBox.Enabled = singleActivate; NewPasswordBox.Enabled = singleActivate;
PasswordAgainBox.Enabled = singleActivate; PasswordAgainBox.Enabled = singleActivate;
if (singleActivate) if (singleActivate)
{ {
ListViewItem item = listView1.SelectedItems[0]; ListViewItem item = listView1.SelectedItems[0];
UsernameBox.Text = item.Text; UsernameBox.Text = item.Text;
} }
else else
{ {
UsernameBox.Text = ""; UsernameBox.Text = "";
} }
} }
private void AddButton_Click(object sender, EventArgs e) private void AddButton_Click(object sender, EventArgs e)
{ {
AddUser form = new(); AddUser form = new();
form.ShowDialog(); form.ShowDialog();
listView1.Items.Clear(); listView1.Items.Clear();
LoadUsers(); LoadUsers();
} }
private void DeleteButton_Click(object sender, EventArgs e) private void DeleteButton_Click(object sender, EventArgs e)
{ {
DialogResult dialogResult = MessageBox.Show("Remove the selected users? This action cannot be undo", "Remove users", MessageBoxButtons.YesNo, MessageBoxIcon.Question); DialogResult dialogResult = MessageBox.Show("Remove the selected users? This action cannot be undo", "Remove users", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dialogResult == DialogResult.Yes) if (dialogResult == DialogResult.Yes)
{ {
LockControls(true); LockControls(true);
List<long> ids = new(); List<long> ids = new();
foreach (ListViewItem item in listView1.SelectedItems) foreach (ListViewItem item in listView1.SelectedItems)
{ {
long userId = Convert.ToInt64(item.SubItems[1].Text); long userId = Convert.ToInt64(item.SubItems[1].Text);
ids.Add(userId); ids.Add(userId);
} }
ThreadPool.QueueUserWorkItem(delegate ThreadPool.QueueUserWorkItem(delegate
{ {
try try
{ {
foreach (long id in ids) foreach (long id in ids)
{ {
serverConnector.DeleteUser(id); serverConnector.DeleteUser(id);
} }
this.Invoke((MethodInvoker)delegate this.Invoke((MethodInvoker)delegate
{ {
listView1.Items.Clear(); listView1.Items.Clear();
LoadUsers(); LoadUsers();
}); });
} }
catch (Exception ex) catch (Exception ex)
{ {
this.Invoke((MethodInvoker)delegate { this.Invoke((MethodInvoker)delegate {
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}); });
} }
finally finally
{ {
this.Invoke((MethodInvoker)delegate this.Invoke((MethodInvoker)delegate
{ {
LockControls(false); LockControls(false);
}); });
} }
}); });
} }
} }
private void LockControls(bool v) private void LockControls(bool v)
{ {
v = !v; v = !v;
AddButton.Enabled = v; AddButton.Enabled = v;
DeleteButton.Enabled = v; DeleteButton.Enabled = v;
UserSettingsButton.Enabled = v; UserSettingsButton.Enabled = v;
listView1.Enabled = v; listView1.Enabled = v;
UsernameBox.Enabled = v; UsernameBox.Enabled = v;
NewPasswordBox.Enabled = v; NewPasswordBox.Enabled = v;
PasswordAgainBox.Enabled = v; PasswordAgainBox.Enabled = v;
if (v) if (v)
{ {
listView1_SelectedIndexChanged(null, null); listView1_SelectedIndexChanged(null, null);
} }
if (!v) if (!v)
{ {
saveUsernameButton.Enabled = v; saveUsernameButton.Enabled = v;
SavePasswordButton.Enabled = v; SavePasswordButton.Enabled = v;
} }
} }
}
} private void NewPasswordBox_TextChanged(object sender, EventArgs e)
{
if (listView1.SelectedItems.Count == 1) {
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;
}
else
{
SavePasswordButton.Enabled = false;
}
}
private void SavePasswordButton_Click(object sender, EventArgs e)
{
if (listView1.SelectedItems.Count != 1)
{
return;
}
LockControls(true);
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;
}
if (!PasswordTool.CheckRequirements(NewPasswordBox.Text))
{
MessageBox.Show(
"Passwords need at least 6 characters",
"Change password",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
LockControls(false);
return;
}
long userId = Convert.ToInt64(listView1.SelectedItems[0].SubItems[1].Text);
ThreadPool.QueueUserWorkItem(delegate
{
serverConnector.ChangePassword(userId, new NewPassword { Password = NewPasswordBox.Text, VerifyPassword = PasswordAgainBox.Text });
this.Invoke((MethodInvoker)delegate {
NewPasswordBox.Clear();
PasswordAgainBox.Clear();
LockControls(false);
});
});
}
private void saveUsernameButton_Click(object sender, EventArgs e)
{
LockControls(true);
if (UsernameBox.Text.Length < 3)
{
MessageBox.Show(
"Username need at least 3 characters",
"Change username",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
LockControls(false);
return;
}
long userId = Convert.ToInt64(listView1.SelectedItems[0].SubItems[1].Text);
ThreadPool.QueueUserWorkItem(delegate
{
serverConnector.ChangeUsername(new UpdateUsername { Id = userId, Username = UsernameBox.Text });
this.Invoke((MethodInvoker)delegate {
listView1.SelectedItems[0].SubItems[0].Text = UsernameBox.Text;
LockControls(false);
});
});
}
private void UsernameBox_TextChanged(object sender, EventArgs e)
{
if (listView1.SelectedItems.Count == 1)
{
string currentUsername = listView1.SelectedItems[0].SubItems[0].Text;
bool valid = true;
if (UsernameBox.Text.Length < 3)
{
valid = false;
}
else if (UsernameBox.Text == currentUsername)
{
valid = false;
}
saveUsernameButton.Enabled = valid;
}
else
{
saveUsernameButton.Enabled = false;
}
}
}
}

File diff suppressed because it is too large Load Diff