2010-03-02 17:56:21 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Windows.Forms;
|
2011-01-30 07:14:05 +00:00
|
|
|
|
using Tanshu.Accounts.Repository;
|
2010-03-02 17:56:21 +00:00
|
|
|
|
using Tanshu.Accounts.Contracts;
|
|
|
|
|
using Tanshu.Accounts.Helpers;
|
2011-01-30 07:14:05 +00:00
|
|
|
|
using Tanshu.Accounts.Entities.Auth;
|
2011-02-09 12:03:22 +00:00
|
|
|
|
using Tanshu.Common.KeyboardControl;
|
2010-03-02 17:56:21 +00:00
|
|
|
|
|
|
|
|
|
namespace Tanshu.Accounts.PointOfSale
|
|
|
|
|
{
|
|
|
|
|
public partial class ChangePassword : Form
|
|
|
|
|
{
|
2011-02-09 12:03:22 +00:00
|
|
|
|
IKeyboardControl keyboardControl;
|
|
|
|
|
public ChangePassword(IKeyboardControl keyboardControl)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2011-02-09 12:03:22 +00:00
|
|
|
|
this.keyboardControl = keyboardControl;
|
|
|
|
|
|
|
|
|
|
var control = keyboardControl as UserControl;
|
|
|
|
|
if (control != null)
|
|
|
|
|
{
|
|
|
|
|
control.Location = new System.Drawing.Point(6, 140);
|
|
|
|
|
var border = (this.Width - this.ClientSize.Width) / 2;
|
|
|
|
|
var titlebarHeight = this.Height - this.ClientSize.Height - (2 * border);
|
|
|
|
|
this.Controls.Add(control);
|
|
|
|
|
this.Width = 6 + control.Width + 6 + (border * 2);
|
|
|
|
|
this.Height = titlebarHeight + 140 + control.Height + 6 + (border * 2);
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ChangePassword_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
2011-01-06 07:17:00 +00:00
|
|
|
|
txtUsername.Text = Session.User.Name;
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void button2_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnCreateUSer_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (txtPassword.Text.Trim() == "")
|
|
|
|
|
MessageBox.Show("Old password can not be blank", "Blank not allowed");
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (txtnewPassword.Text.Trim() == "")
|
|
|
|
|
MessageBox.Show("New password can not be blank", "Blank not allowed");
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (txtnewPassword.Text.Trim() != txtConfirmPassword.Text.Trim())
|
|
|
|
|
MessageBox.Show("New password not matched to confirm password", "Password not matched");
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (ChangeUserPassword())
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Password changed", "Confirm");
|
|
|
|
|
this.Close();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
MessageBox.Show("old Password not matched for user", "Wrong Password");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool ChangeUserPassword()
|
|
|
|
|
{
|
2011-01-30 07:14:05 +00:00
|
|
|
|
User userEntity = new User();
|
2010-03-02 17:56:21 +00:00
|
|
|
|
userEntity.Name = txtUsername.Text.Trim();
|
2011-01-30 07:14:05 +00:00
|
|
|
|
userEntity.Password = Tanshu.Common.Md5.Hash(txtPassword.Text.Trim(), "v2");
|
2010-03-02 17:56:21 +00:00
|
|
|
|
|
2011-01-30 07:14:05 +00:00
|
|
|
|
if (UserBI.ValidateUser(userEntity.Name, userEntity.Password))
|
|
|
|
|
return UserBI.ChangePassword(userEntity, Tanshu.Common.Md5.Hash(txtnewPassword.Text.Trim(), "v2"));
|
2010-03-02 17:56:21 +00:00
|
|
|
|
else
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|