narsil/Tanshu.Accounts.PointOfSale/User Management/ChangePassword.cs
tanshu 69617949bd Important! : Need to update to new schema using SQL Scripts
Important! : This version will not work.  It is pre-alpha and saved in case of catastrophic failure
Refactor: Remove dependency on Fluent Nhibernate.
Refactor: All Primary keys are now Guids.
Refactor: Class Mappings changed from AutoMap to Explicit Mappings.
Breakage: All Cascading is now disabled and entities must be explicitly saved/updated/deleted
Breakage: Auto Commiting is now off and "SaveChanges()" needs to be called on all BIs.
Refactor: Changed the pattern where all relevant db code for an operation is basically in the same function.
Chore: Removed Advance and Payments options.
2014-10-12 15:11:45 +05:30

109 lines
3.8 KiB
C#

using System;
using System.Drawing;
using System.Windows.Forms;
using Tanshu.Accounts.Repository;
using Tanshu.Accounts.Contracts;
using Tanshu.Accounts.Helpers;
using Tanshu.Accounts.Entities.Auth;
using Tanshu.Common.KeyboardControl;
namespace Tanshu.Accounts.PointOfSale
{
public partial class ChangePassword : Form
{
IKeyboardControl keyboardControl;
public ChangePassword(IKeyboardControl keyboardControl)
{
InitializeComponent();
this.keyboardControl = keyboardControl;
var control = keyboardControl as UserControl;
if (control != null)
{
control.Location = new System.Drawing.Point(6, 140);
this.Controls.Add(control);
this.Size = this.SizeFromClientSize(new Size(6 + control.Width + 6, 140 + control.Height + 6));
}
}
private void ChangePassword_Load(object sender, EventArgs e)
{
txtUsername.Text = Session.User.Name;
}
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()
{
var userEntity = new User();
userEntity.Name = txtUsername.Text.Trim();
userEntity.Password = Tanshu.Common.Md5.Hash(txtPassword.Text.Trim(), "v2");
using (var bi = new UserBI())
if (bi.ValidateUser(userEntity.Name, userEntity.Password) != null)
return bi.ChangePassword(userEntity, Tanshu.Common.Md5.Hash(txtnewPassword.Text.Trim(), "v2"));
else
return false;
}
private void btnMsr_Click(object sender, EventArgs e)
{
var user = new User();
user.Name = txtUsername.Text.Trim();
user.Password = Common.Md5.Hash(txtPassword.Text.Trim(), "v2");
using (var bi = new UserBI())
if (bi.ValidateUser(user.Name, user.Password) == null)
return;
using (var frm = new MsrLoginForm(true))
{
frm.ShowDialog();
string userName;
frm.UserName(out userName);
if (MessageBox.Show("Update Msr Card", "Update", MessageBoxButtons.YesNo, MessageBoxIcon.Question) !=
DialogResult.Yes)
return;
using (var bi = new UserBI())
{
user = bi.Get(x => x.Name == user.Name);
user.MsrString = userName;
bi.Update(user);
bi.SaveChanges();
}
MessageBox.Show("Msr Card Updated");
this.Close();
}
}
}
}