99 lines
3.7 KiB
C#
99 lines
3.7 KiB
C#
// Copyright (c) 2017- schick Informatik
|
|
// Description: Users may change their password
|
|
//
|
|
|
|
using bsmd.database;
|
|
using ENI2.Controls;
|
|
using System;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
|
|
namespace ENI2.EditControls
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for ChangePasswordDialog.xaml
|
|
/// </summary>
|
|
public partial class ChangePasswordDialog : EditWindowBase
|
|
{
|
|
|
|
#region Construction
|
|
|
|
public ChangePasswordDialog()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Properties
|
|
|
|
public ReportingParty CurrentUser { get; set; }
|
|
|
|
#endregion
|
|
|
|
#region event handler
|
|
|
|
private void buttonChangePassword_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
bool success = false;
|
|
string message = "";
|
|
if (!textBoxOldPassword.Password.IsNullOrEmpty() || !textBoxNew1Password.Password.IsNullOrEmpty() || !textBoxNew2Password.Password.IsNullOrEmpty())
|
|
{
|
|
if (!textBoxOldPassword.Password.IsNullOrEmpty())
|
|
{
|
|
if (CurrentUser.GetHash(textBoxOldPassword.Password).Equals(CurrentUser.PasswordHash))
|
|
{
|
|
if (textBoxNew1Password.Password.IsNullOrEmpty() ||
|
|
textBoxNew2Password.Password.IsNullOrEmpty() ||
|
|
!textBoxNew1Password.Password.Equals(textBoxNew2Password.Password))
|
|
{
|
|
message = "New passwords are empty or do not match";
|
|
}
|
|
else
|
|
{
|
|
if (textBoxOldPassword.Password.Equals(textBoxNew1Password.Password))
|
|
{
|
|
message = "Old and new password are the same";
|
|
}
|
|
else
|
|
{
|
|
CurrentUser.SetPassword(textBoxNew1Password.Password);
|
|
success = true;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
message = "Old password is not correct";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
message = "Old password empty";
|
|
}
|
|
if (!success)
|
|
MessageBox.Show(message, "Changing password failed", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
else
|
|
MessageBox.Show("Password successfully changed.", "Password changed", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
}
|
|
// user may have changed combobox default display value so we are saving anyway here
|
|
this.CurrentUser.ShipcallDisplayMode = (ReportingParty.ShipcallDisplayModeEnum)Enum.Parse(typeof(ReportingParty.ShipcallDisplayModeEnum), (string)this.comboBoxDefaultDisplay.SelectedValue);
|
|
DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Save(CurrentUser);
|
|
}
|
|
|
|
private void EditWindowBase_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
this.textBlockName.Text = CurrentUser.Logon;
|
|
this.AddVisible = false;
|
|
this.OkVisible = false;
|
|
var cancelButton = (Button)Template.FindName("buttonCancel", this);
|
|
cancelButton.Content = "Close";
|
|
this.comboBoxDefaultDisplay.ItemsSource = Util.EnumHelper.GetAllValuesAndDescription(typeof(ReportingParty.ShipcallDisplayModeEnum));
|
|
this.comboBoxDefaultDisplay.SelectedValue = this.CurrentUser.ShipcallDisplayMode;
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|