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

@@ -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;
}
}
}