78 lines
2.4 KiB
C#
78 lines
2.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Windows.Forms;
|
|
using Xylem.Common.Utils.UserAccessCtrl.Properties;
|
|
|
|
namespace Xylem.Common.Utils.UserAccessCtrl
|
|
{
|
|
public partial class ChangePassword : UserControl, IIdentityForm
|
|
{
|
|
private readonly Action<ChangePassword> closeOnSuccessOrCancel;
|
|
private readonly IDictionary<String, Control> fields;
|
|
|
|
public ChangePassword()
|
|
{
|
|
InitializeComponent();
|
|
|
|
Dock = DockStyle.Fill;
|
|
}
|
|
|
|
public ChangePassword(Action<Control> closeOnSuccess) : this()
|
|
{
|
|
closeOnSuccessOrCancel = closeOnSuccess;
|
|
|
|
fields = new Dictionary<String, Control>
|
|
{
|
|
{ "OldPassword", tbxOldPassword },
|
|
{ "NewPassword", newPassword },
|
|
{ "ConfirmPassword", confirmPassword },
|
|
};
|
|
lblOldPassword.Text = Resources.StrLblOldPassword;
|
|
lblNewPassword.Text = Resources.StrLblNewPassword;
|
|
lblConfirmPassword.Text = Resources.StrLblConfirmPasswort;
|
|
btnCHangePassword.Text = Resources.StrLblChangePassword;
|
|
btnCancel.Text = Resources.StrLblCancel;
|
|
}
|
|
|
|
private void OnCancellationClick(Object sender, EventArgs args)
|
|
{
|
|
closeOnSuccessOrCancel?.Invoke(this);
|
|
}
|
|
|
|
private void OnFormSubmittedClick(Object sender, EventArgs args)
|
|
{
|
|
ChangePasswordErrorProvider.Clear();
|
|
|
|
errorLbl.Text = default(String);
|
|
|
|
if (!Software.ChangePassword(tbxOldPassword.Text, newPassword.Text, confirmPassword.Text, out var errors))
|
|
{
|
|
errorLbl.Text = Resources.StrMsgFailedPasswordChange;
|
|
|
|
foreach (var kvp in errors)
|
|
{
|
|
if (fields.TryGetValue(kvp.Key, out var control))
|
|
{
|
|
ChangePasswordErrorProvider.SetError(control, kvp.Value);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
closeOnSuccessOrCancel?.Invoke(this);
|
|
}
|
|
}
|
|
|
|
private void btnCHangePassword_KeyDown(Object sender, KeyEventArgs e)
|
|
{
|
|
if (e.KeyCode == Keys.Enter)
|
|
OnFormSubmittedClick(this, null);
|
|
}
|
|
|
|
private void btnCancel_KeyDown(Object sender, KeyEventArgs e)
|
|
{
|
|
OnCancellationClick(this, null);
|
|
}
|
|
}
|
|
}
|