63 lines
1.9 KiB
C#
63 lines
1.9 KiB
C#
namespace Xylem.Common.Ui.GenesisToolBox.Ctls
|
|
{
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Windows.Forms;
|
|
|
|
using Xylem.Common.Ui.GenesisToolBox.Infrastructure;
|
|
|
|
public partial class ChangePassword : UserControl, IIdentityForm
|
|
{
|
|
private readonly Action<ChangePassword> closeOnSuccessOrCancel;
|
|
private readonly IDictionary<string, Control> fields;
|
|
|
|
public ChangePassword()
|
|
{
|
|
this.InitializeComponent();
|
|
|
|
this.Dock = DockStyle.Fill;
|
|
}
|
|
|
|
public ChangePassword(Action<Control> closeOnSuccess) : this()
|
|
{
|
|
this.closeOnSuccessOrCancel = closeOnSuccess;
|
|
|
|
this.fields = new Dictionary<string, Control>
|
|
{
|
|
{ "OldPassword", this.oldPassword },
|
|
{ "NewPassword", this.newPassword },
|
|
{ "ConfirmPassword", this.confirmPassword },
|
|
};
|
|
}
|
|
|
|
private void OnCancellationClick(Object sender, EventArgs args)
|
|
{
|
|
this.closeOnSuccessOrCancel?.Invoke(this);
|
|
}
|
|
|
|
private void OnFormSubmittedClick(Object sender, EventArgs args)
|
|
{
|
|
this.ChangePasswordErrorProvider.Clear();
|
|
|
|
this.errorLbl.Text = default(string);
|
|
|
|
if (!Software.ChangePassword(this.oldPassword.Text, this.newPassword.Text, this.confirmPassword.Text, out var errors))
|
|
{
|
|
this.errorLbl.Text = "Password change failed.";
|
|
|
|
foreach (var kvp in errors)
|
|
{
|
|
if (this.fields.TryGetValue(kvp.Key, out var control))
|
|
{
|
|
this.ChangePasswordErrorProvider.SetError(control, kvp.Value);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
this.closeOnSuccessOrCancel?.Invoke(this);
|
|
}
|
|
}
|
|
}
|
|
}
|