User management form
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
130
OpenSaveCloudClient/AddUser.Designer.cs
generated
Normal file
130
OpenSaveCloudClient/AddUser.Designer.cs
generated
Normal file
@@ -0,0 +1,130 @@
|
||||
namespace OpenSaveCloudClient
|
||||
{
|
||||
partial class AddUser
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AddUser));
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.label3 = new System.Windows.Forms.Label();
|
||||
this.UsernameBox = new System.Windows.Forms.TextBox();
|
||||
this.PasswordBox = new System.Windows.Forms.TextBox();
|
||||
this.button1 = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// label1
|
||||
//
|
||||
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.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(154, 32);
|
||||
this.label1.TabIndex = 0;
|
||||
this.label1.Text = "Create a user";
|
||||
//
|
||||
// label2
|
||||
//
|
||||
this.label2.AutoSize = true;
|
||||
this.label2.Location = new System.Drawing.Point(12, 72);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(60, 15);
|
||||
this.label2.TabIndex = 1;
|
||||
this.label2.Text = "Username";
|
||||
//
|
||||
// label3
|
||||
//
|
||||
this.label3.AutoSize = true;
|
||||
this.label3.Location = new System.Drawing.Point(12, 129);
|
||||
this.label3.Name = "label3";
|
||||
this.label3.Size = new System.Drawing.Size(57, 15);
|
||||
this.label3.TabIndex = 2;
|
||||
this.label3.Text = "Password";
|
||||
//
|
||||
// UsernameBox
|
||||
//
|
||||
this.UsernameBox.Location = new System.Drawing.Point(12, 90);
|
||||
this.UsernameBox.Name = "UsernameBox";
|
||||
this.UsernameBox.Size = new System.Drawing.Size(457, 23);
|
||||
this.UsernameBox.TabIndex = 3;
|
||||
this.UsernameBox.TextChanged += new System.EventHandler(this.UsernameBox_TextChanged);
|
||||
//
|
||||
// PasswordBox
|
||||
//
|
||||
this.PasswordBox.Location = new System.Drawing.Point(12, 147);
|
||||
this.PasswordBox.Name = "PasswordBox";
|
||||
this.PasswordBox.Size = new System.Drawing.Size(457, 23);
|
||||
this.PasswordBox.TabIndex = 4;
|
||||
this.PasswordBox.TextChanged += new System.EventHandler(this.UsernameBox_TextChanged);
|
||||
//
|
||||
// button1
|
||||
//
|
||||
this.button1.Enabled = false;
|
||||
this.button1.Location = new System.Drawing.Point(394, 203);
|
||||
this.button1.Name = "button1";
|
||||
this.button1.Size = new System.Drawing.Size(75, 23);
|
||||
this.button1.TabIndex = 5;
|
||||
this.button1.Text = "Create";
|
||||
this.button1.UseVisualStyleBackColor = true;
|
||||
this.button1.Click += new System.EventHandler(this.button1_Click);
|
||||
//
|
||||
// AddUser
|
||||
//
|
||||
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(481, 238);
|
||||
this.Controls.Add(this.button1);
|
||||
this.Controls.Add(this.PasswordBox);
|
||||
this.Controls.Add(this.UsernameBox);
|
||||
this.Controls.Add(this.label3);
|
||||
this.Controls.Add(this.label2);
|
||||
this.Controls.Add(this.label1);
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
|
||||
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
||||
this.MaximumSize = new System.Drawing.Size(497, 277);
|
||||
this.MinimumSize = new System.Drawing.Size(497, 277);
|
||||
this.Name = "AddUser";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
|
||||
this.Text = "AddUser";
|
||||
this.Load += new System.EventHandler(this.AddUser_Load);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Label label1;
|
||||
private Label label2;
|
||||
private Label label3;
|
||||
private TextBox UsernameBox;
|
||||
private TextBox PasswordBox;
|
||||
private Button button1;
|
||||
}
|
||||
}
|
||||
92
OpenSaveCloudClient/AddUser.cs
Normal file
92
OpenSaveCloudClient/AddUser.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
using OpenSaveCloudClient.Core;
|
||||
using OpenSaveCloudClient.Models.Remote;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace OpenSaveCloudClient
|
||||
{
|
||||
public partial class AddUser : Form
|
||||
{
|
||||
|
||||
private ServerConnector serverConnector;
|
||||
private TaskManager taskManager;
|
||||
|
||||
public AddUser()
|
||||
{
|
||||
InitializeComponent();
|
||||
serverConnector = ServerConnector.GetInstance();
|
||||
taskManager = TaskManager.GetInstance();
|
||||
}
|
||||
|
||||
private void AddUser_Load(object sender, EventArgs e)
|
||||
{
|
||||
PasswordBox.Text = PasswordTool.GeneratePassword();
|
||||
}
|
||||
|
||||
private void UsernameBox_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
bool ok = true;
|
||||
if (UsernameBox.Text.Length < 3)
|
||||
{
|
||||
ok = false;
|
||||
}
|
||||
else if (!PasswordTool.CheckRequirements(PasswordBox.Text))
|
||||
{
|
||||
ok = false;
|
||||
}
|
||||
button1.Enabled = ok;
|
||||
}
|
||||
|
||||
private void button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
LockControls(true);
|
||||
new Thread(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
Registration registration = new()
|
||||
{
|
||||
Username = UsernameBox.Text,
|
||||
Password = PasswordBox.Text,
|
||||
};
|
||||
User? u = serverConnector.CreateUser(registration);
|
||||
if (u == null)
|
||||
{
|
||||
this.Invoke((MethodInvoker)delegate {
|
||||
MessageBox.Show("Failed to create the user. Refer to the server log to know why", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
LockControls(false);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Invoke((MethodInvoker)delegate {
|
||||
Close();
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.Invoke((MethodInvoker)delegate {
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
LockControls(false);
|
||||
});
|
||||
}
|
||||
}).Start();
|
||||
}
|
||||
|
||||
private void LockControls(bool value)
|
||||
{
|
||||
value = !value;
|
||||
UsernameBox.Enabled = value;
|
||||
PasswordBox.Enabled = value;
|
||||
button1.Enabled = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
2280
OpenSaveCloudClient/AddUser.resx
Normal file
2280
OpenSaveCloudClient/AddUser.resx
Normal file
File diff suppressed because it is too large
Load Diff
29
OpenSaveCloudClient/Core/PasswordTool.cs
Normal file
29
OpenSaveCloudClient/Core/PasswordTool.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using PasswordGenerator;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OpenSaveCloudClient.Core
|
||||
{
|
||||
public class PasswordTool
|
||||
{
|
||||
private PasswordTool() { }
|
||||
|
||||
public static bool CheckRequirements(string password)
|
||||
{
|
||||
if (password.Length < 6)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static string GeneratePassword()
|
||||
{
|
||||
Password pwd = new(12);
|
||||
return pwd.Next();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -679,7 +679,7 @@ namespace OpenSaveCloudClient.Core
|
||||
return null;
|
||||
}
|
||||
|
||||
public User? DeleteUser(long userId)
|
||||
public bool DeleteUser(long userId)
|
||||
{
|
||||
logManager.AddInformation("Delete a user and all his datas");
|
||||
string uuidTask = taskManager.StartTask("Deleting user", true, 1);
|
||||
@@ -692,7 +692,7 @@ namespace OpenSaveCloudClient.Core
|
||||
{
|
||||
string responseText = response.Content.ReadAsStringAsync().Result;
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Ended);
|
||||
return JsonSerializer.Deserialize<User>(responseText);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -705,7 +705,7 @@ namespace OpenSaveCloudClient.Core
|
||||
logManager.AddError(ex);
|
||||
taskManager.UpdateTaskStatus(uuidTask, AsyncTaskStatus.Failed);
|
||||
}
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool ChangePassword(NewPassword password)
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="IGDB" Version="2.3.1" />
|
||||
<PackageReference Include="PasswordGenerator" Version="2.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
149
OpenSaveCloudClient/UserManagementForm.Designer.cs
generated
149
OpenSaveCloudClient/UserManagementForm.Designer.cs
generated
@@ -37,11 +37,24 @@
|
||||
this.UserSettingsButton = new System.Windows.Forms.Button();
|
||||
this.AddButton = new System.Windows.Forms.Button();
|
||||
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||
this.saveUsernameButton = new System.Windows.Forms.Button();
|
||||
this.groupBox2 = new System.Windows.Forms.GroupBox();
|
||||
this.SavePasswordButton = new System.Windows.Forms.Button();
|
||||
this.label3 = new System.Windows.Forms.Label();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.PasswordAgainBox = new System.Windows.Forms.TextBox();
|
||||
this.NewPasswordBox = new System.Windows.Forms.TextBox();
|
||||
this.UsernameBox = new System.Windows.Forms.TextBox();
|
||||
this.label4 = new System.Windows.Forms.Label();
|
||||
this.panel1.SuspendLayout();
|
||||
this.groupBox1.SuspendLayout();
|
||||
this.groupBox2.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// listView1
|
||||
//
|
||||
this.listView1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
|
||||
this.name});
|
||||
this.listView1.Location = new System.Drawing.Point(12, 86);
|
||||
@@ -50,6 +63,7 @@
|
||||
this.listView1.TabIndex = 0;
|
||||
this.listView1.UseCompatibleStateImageBehavior = false;
|
||||
this.listView1.View = System.Windows.Forms.View.Details;
|
||||
this.listView1.SelectedIndexChanged += new System.EventHandler(this.listView1_SelectedIndexChanged);
|
||||
//
|
||||
// name
|
||||
//
|
||||
@@ -93,6 +107,7 @@
|
||||
this.DeleteButton.TabIndex = 1;
|
||||
this.DeleteButton.Text = "\r\n\r\nDelete";
|
||||
this.DeleteButton.UseVisualStyleBackColor = true;
|
||||
this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click);
|
||||
//
|
||||
// UserSettingsButton
|
||||
//
|
||||
@@ -118,9 +133,17 @@
|
||||
this.AddButton.TabIndex = 0;
|
||||
this.AddButton.Text = "\r\n\r\nAdd";
|
||||
this.AddButton.UseVisualStyleBackColor = true;
|
||||
this.AddButton.Click += new System.EventHandler(this.AddButton_Click);
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.groupBox1.Controls.Add(this.saveUsernameButton);
|
||||
this.groupBox1.Controls.Add(this.groupBox2);
|
||||
this.groupBox1.Controls.Add(this.UsernameBox);
|
||||
this.groupBox1.Controls.Add(this.label4);
|
||||
this.groupBox1.Location = new System.Drawing.Point(252, 86);
|
||||
this.groupBox1.Name = "groupBox1";
|
||||
this.groupBox1.Size = new System.Drawing.Size(536, 352);
|
||||
@@ -128,10 +151,119 @@
|
||||
this.groupBox1.TabStop = false;
|
||||
this.groupBox1.Text = "Detail";
|
||||
//
|
||||
// saveUsernameButton
|
||||
//
|
||||
this.saveUsernameButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.saveUsernameButton.Enabled = false;
|
||||
this.saveUsernameButton.Location = new System.Drawing.Point(444, 83);
|
||||
this.saveUsernameButton.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.saveUsernameButton.Name = "saveUsernameButton";
|
||||
this.saveUsernameButton.Size = new System.Drawing.Size(75, 23);
|
||||
this.saveUsernameButton.TabIndex = 4;
|
||||
this.saveUsernameButton.Text = "Save";
|
||||
this.saveUsernameButton.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// groupBox2
|
||||
//
|
||||
this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.groupBox2.Controls.Add(this.SavePasswordButton);
|
||||
this.groupBox2.Controls.Add(this.label3);
|
||||
this.groupBox2.Controls.Add(this.label1);
|
||||
this.groupBox2.Controls.Add(this.PasswordAgainBox);
|
||||
this.groupBox2.Controls.Add(this.NewPasswordBox);
|
||||
this.groupBox2.Location = new System.Drawing.Point(5, 135);
|
||||
this.groupBox2.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.groupBox2.Name = "groupBox2";
|
||||
this.groupBox2.Padding = new System.Windows.Forms.Padding(2);
|
||||
this.groupBox2.Size = new System.Drawing.Size(526, 158);
|
||||
this.groupBox2.TabIndex = 8;
|
||||
this.groupBox2.TabStop = false;
|
||||
this.groupBox2.Text = "Change password";
|
||||
//
|
||||
// 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(439, 124);
|
||||
this.SavePasswordButton.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.SavePasswordButton.Name = "SavePasswordButton";
|
||||
this.SavePasswordButton.Size = new System.Drawing.Size(75, 23);
|
||||
this.SavePasswordButton.TabIndex = 2;
|
||||
this.SavePasswordButton.Text = "Save";
|
||||
this.SavePasswordButton.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// label3
|
||||
//
|
||||
this.label3.AutoSize = true;
|
||||
this.label3.Location = new System.Drawing.Point(14, 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";
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(14, 24);
|
||||
this.label1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(84, 15);
|
||||
this.label1.TabIndex = 2;
|
||||
this.label1.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.Enabled = false;
|
||||
this.PasswordAgainBox.Location = new System.Drawing.Point(14, 89);
|
||||
this.PasswordAgainBox.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.PasswordAgainBox.Name = "PasswordAgainBox";
|
||||
this.PasswordAgainBox.Size = new System.Drawing.Size(500, 23);
|
||||
this.PasswordAgainBox.TabIndex = 1;
|
||||
this.PasswordAgainBox.UseSystemPasswordChar = true;
|
||||
//
|
||||
// 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.Enabled = false;
|
||||
this.NewPasswordBox.Location = new System.Drawing.Point(14, 41);
|
||||
this.NewPasswordBox.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.NewPasswordBox.Name = "NewPasswordBox";
|
||||
this.NewPasswordBox.Size = new System.Drawing.Size(500, 23);
|
||||
this.NewPasswordBox.TabIndex = 0;
|
||||
this.NewPasswordBox.UseSystemPasswordChar = true;
|
||||
//
|
||||
// UsernameBox
|
||||
//
|
||||
this.UsernameBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.UsernameBox.CausesValidation = false;
|
||||
this.UsernameBox.Enabled = false;
|
||||
this.UsernameBox.Location = new System.Drawing.Point(19, 44);
|
||||
this.UsernameBox.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.UsernameBox.Name = "UsernameBox";
|
||||
this.UsernameBox.Size = new System.Drawing.Size(500, 23);
|
||||
this.UsernameBox.TabIndex = 9;
|
||||
//
|
||||
// label4
|
||||
//
|
||||
this.label4.AutoSize = true;
|
||||
this.label4.Location = new System.Drawing.Point(19, 27);
|
||||
this.label4.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
|
||||
this.label4.Name = "label4";
|
||||
this.label4.Size = new System.Drawing.Size(60, 15);
|
||||
this.label4.TabIndex = 10;
|
||||
this.label4.Text = "Username";
|
||||
//
|
||||
// UserManagementForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
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(800, 450);
|
||||
this.Controls.Add(this.groupBox1);
|
||||
@@ -146,6 +278,10 @@
|
||||
this.Load += new System.EventHandler(this.UserManagementForm_Load);
|
||||
this.panel1.ResumeLayout(false);
|
||||
this.panel1.PerformLayout();
|
||||
this.groupBox1.ResumeLayout(false);
|
||||
this.groupBox1.PerformLayout();
|
||||
this.groupBox2.ResumeLayout(false);
|
||||
this.groupBox2.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
@@ -160,5 +296,14 @@
|
||||
private GroupBox groupBox1;
|
||||
private Label label2;
|
||||
private Button UserSettingsButton;
|
||||
private Button saveUsernameButton;
|
||||
private GroupBox groupBox2;
|
||||
private Button SavePasswordButton;
|
||||
private Label label3;
|
||||
private Label label1;
|
||||
private TextBox PasswordAgainBox;
|
||||
private TextBox NewPasswordBox;
|
||||
private TextBox UsernameBox;
|
||||
private Label label4;
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,11 @@ namespace OpenSaveCloudClient
|
||||
}
|
||||
|
||||
private void UserManagementForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadUsers();
|
||||
}
|
||||
|
||||
private void LoadUsers()
|
||||
{
|
||||
new Thread(() =>
|
||||
{
|
||||
@@ -45,7 +50,14 @@ namespace OpenSaveCloudClient
|
||||
|
||||
private void UpdateRemoteList(List<User> users)
|
||||
{
|
||||
if (serverConnector.ConnectedUser == null)
|
||||
{
|
||||
Close();
|
||||
return;
|
||||
}
|
||||
foreach (User user in users)
|
||||
{
|
||||
if (user.Username != serverConnector.ConnectedUser.Username)
|
||||
{
|
||||
ListViewItem lvi = listView1.Items.Add(user.Username);
|
||||
lvi.SubItems.Add(Convert.ToString(user.Id));
|
||||
@@ -53,4 +65,98 @@ namespace OpenSaveCloudClient
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
NewPasswordBox.Text = "";
|
||||
PasswordAgainBox.Text = "";
|
||||
bool singleActivate = (listView1.SelectedItems.Count == 1);
|
||||
bool multiActivate = (listView1.SelectedItems.Count > 0);
|
||||
DeleteButton.Enabled = multiActivate;
|
||||
UsernameBox.Enabled = singleActivate;
|
||||
NewPasswordBox.Enabled = singleActivate;
|
||||
PasswordAgainBox.Enabled = singleActivate;
|
||||
if (singleActivate)
|
||||
{
|
||||
ListViewItem item = listView1.SelectedItems[0];
|
||||
UsernameBox.Text = item.Text;
|
||||
}
|
||||
else
|
||||
{
|
||||
UsernameBox.Text = "";
|
||||
}
|
||||
}
|
||||
|
||||
private void AddButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
AddUser form = new();
|
||||
form.ShowDialog();
|
||||
listView1.Items.Clear();
|
||||
LoadUsers();
|
||||
}
|
||||
|
||||
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);
|
||||
if (dialogResult == DialogResult.Yes)
|
||||
{
|
||||
LockControls(true);
|
||||
List<long> ids = new();
|
||||
foreach (ListViewItem item in listView1.SelectedItems)
|
||||
{
|
||||
long userId = Convert.ToInt64(item.SubItems[1].Text);
|
||||
ids.Add(userId);
|
||||
}
|
||||
new Thread(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (long id in ids)
|
||||
{
|
||||
serverConnector.DeleteUser(id);
|
||||
}
|
||||
this.Invoke((MethodInvoker)delegate
|
||||
{
|
||||
listView1.Items.Clear();
|
||||
LoadUsers();
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.Invoke((MethodInvoker)delegate {
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
});
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.Invoke((MethodInvoker)delegate
|
||||
{
|
||||
LockControls(false);
|
||||
});
|
||||
}
|
||||
}).Start();
|
||||
}
|
||||
}
|
||||
|
||||
private void LockControls(bool v)
|
||||
{
|
||||
v = !v;
|
||||
AddButton.Enabled = v;
|
||||
DeleteButton.Enabled = v;
|
||||
UserSettingsButton.Enabled = v;
|
||||
listView1.Enabled = v;
|
||||
UsernameBox.Enabled = v;
|
||||
NewPasswordBox.Enabled = v;
|
||||
PasswordAgainBox.Enabled = v;
|
||||
if (v)
|
||||
{
|
||||
listView1_SelectedIndexChanged(null, null);
|
||||
}
|
||||
if (!v)
|
||||
{
|
||||
saveUsernameButton.Enabled = v;
|
||||
SavePasswordButton.Enabled = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user