| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405 |
- using System.Linq;
- using GalaSoft.MvvmLight;
- using GalaSoft.MvvmLight.Command;
- using GalaSoft.MvvmLight.Ioc;
- using Muchinfo.MTPClient.Account.Views;
- using Muchinfo.MTPClient.Data;
- using Muchinfo.MTPClient.Data.Enums;
- using Muchinfo.MTPClient.Data.Model.Account;
- using Muchinfo.MTPClient.Infrastructure.Helpers;
- using Muchinfo.MTPClient.Infrastructure.MessageBox;
- using Muchinfo.MTPClient.Infrastructure.Utilities;
- using Muchinfo.MTPClient.IService;
- using Muchinfo.WPF.Controls.Windows;
- using System;
- using System.Collections.Generic;
- using System.Windows;
- namespace Muchinfo.MTPClient.Account.ViewModels
- {
- /// <summary>
- /// 交易密码修改业务逻辑
- /// </summary>
- public class TradePWDModifyViewModel : ViewModelBase
- {
- #region Constructors
- public TradePWDModifyViewModel(bool isUnforceUpdate)
- {
- OldLoginPassword = string.Empty;
- NewLoginPassword = string.Empty;
- ConfLoginPassword = string.Empty;
- OldFundsPassword = string.Empty;
- NewFundsPassword = string.Empty;
- ConfFundsPassword = string.Empty;
- IsTradePanel = true;
- LoginID = UserManager.CurrentTradeAccount != null ? UserManager.CurrentTradeAccount.LoginID : uint.MaxValue;
- FundsLst = UserManager.CurrentTradeAccount != null ? UserManager.CurrentTradeAccount.FundsAccountIds : new List<ulong>();
- _loginService = SimpleIoc.Default.GetService(typeof(ILoginService)) as ILoginService;
- IsUnforceUpdate = isUnforceUpdate;
- }
- #endregion Constructors
- #region Properties
- public ILoginService _loginService { get; set; }
- private int ServerCount = 0;
- private bool _isTradePanel;
- /// <summary>
- /// 是否选中修改交易密码面板
- /// </summary>
- public bool IsTradePanel
- {
- get { return _isTradePanel; }
- set
- {
- Set(() => IsTradePanel, ref _isTradePanel, value);
- ErrorMsg = string.Empty;
- }
- }
- private bool _isPhonePanel;
- /// <summary>
- /// 是否选中修改电话密码面板
- /// </summary>
- public bool IsPhonePanel
- {
- get { return _isPhonePanel; }
- set
- {
- Set(() => IsPhonePanel, ref _isPhonePanel, value);
- ErrorMsg = string.Empty;
- }
- }
- private bool _isCommunicationPanel;
- /// <summary>
- /// 是否选中修改通讯密码面板
- /// </summary>
- public bool IsCommunicationPanel
- {
- get { return _isCommunicationPanel; }
- set
- {
- Set(() => IsCommunicationPanel, ref _isCommunicationPanel, value);
- ErrorMsg = string.Empty;
- }
- }
- private bool _isFundsPanel;
- /// <summary>
- /// 是否选中修改通讯密码面板
- /// </summary>
- public bool IsFundsPanel
- {
- get { return _isFundsPanel; }
- set
- {
- Set(() => IsFundsPanel, ref _isFundsPanel, value);
- ErrorMsg = string.Empty;
- }
- }
- //错误提示
- private string _errorMsg;
- /// <summary>
- /// 修改不成功出现的错误提示
- /// </summary>
- public string ErrorMsg
- {
- get
- {
- return _errorMsg;
- }
- set
- {
- Set(() => ErrorMsg, ref _errorMsg, value);
- }
- }
- /// <summary>
- /// 是否显示忙
- /// </summary>
- private bool _isBusy;
- /// <summary>
- /// 是否忙,显示等待控件
- /// </summary>
- public bool IsBusy
- {
- get { return _isBusy; }
- set { Set(() => IsBusy, ref _isBusy, value); }
- }
- /// <summary>
- /// 登录账号
- /// </summary>
- public ulong LoginID { get; set; }
- /// <summary>
- /// 旧登录密码
- /// </summary>
- public string OldLoginPassword { get; set; }
- /// <summary>
- /// 新登录密码
- /// </summary>
- public string NewLoginPassword { get; set; }
- /// <summary>
- /// 确认登录密码
- /// </summary>
- public string ConfLoginPassword { get; set; }
- /// <summary>
- /// 资金账户ID列表
- /// </summary>
- public List<ulong> FundsLst { get; set; }
- /// <summary>
- /// 旧资金帐号密码
- /// </summary>
- public string OldFundsPassword { get; set; }
- /// <summary>
- /// 新资金账号密码
- /// </summary>
- public string NewFundsPassword { get; set; }
- /// <summary>
- /// 确认资金帐号密码
- /// </summary>
- public string ConfFundsPassword { get; set; }
- private ulong _currentFundID = uint.MaxValue;
- public ulong CurrentFundID
- {
- get { return _currentFundID; }
- set
- {
- Set(() => CurrentFundID, ref _currentFundID, value);
- }
- }
- private bool _isUnforceUpdate = true;
- /// <summary>
- /// 是否非强制修改
- /// </summary>
- /// <value><c>true</c> if this instance is unforce update; otherwise, <c>false</c>.</value>
- public bool IsUnforceUpdate
- {
- get { return _isUnforceUpdate; }
- set
- {
- Set(() => IsUnforceUpdate, ref _isUnforceUpdate, value);
- }
- }
- #endregion Properties
- #region Command
- public RelayCommand<TradePWDModifyView> CancelCommand
- {
- get
- {
- return new RelayCommand<TradePWDModifyView>((w) =>
- {
- w.DialogResult = false;
- });
- }
- }
- /// <summary>
- /// 修改密码
- /// </summary>
- public RelayCommand<TradePWDModifyView> OKCommand
- {
- get
- {
- return new RelayCommand<TradePWDModifyView>((w) =>
- {
- if (!ValidData()) return;
- var pwds = new AccountPwds() { ModifyPwdType = 1 };
- if (IsTradePanel)
- {
- pwds.ModifyPwdType = 1;
- pwds.ModifyPwdID = LoginID;
- pwds.OldPwd = string.IsNullOrEmpty(OldLoginPassword) ? string.Empty : EncryptHelper.SHA256(LoginID.ToString().Trim() + OldLoginPassword.Trim()).ToLower();
- pwds.NewPwd = string.IsNullOrEmpty(NewLoginPassword) ? string.Empty : EncryptHelper.SHA256(LoginID.ToString().Trim() + NewLoginPassword.Trim()).ToLower(); ;
- }
- else if (IsFundsPanel)
- {
- pwds.ModifyPwdType = 2;
- pwds.ModifyPwdID = CurrentFundID;
- pwds.OldPwd = string.IsNullOrEmpty(CurrentFundID.ToString()) ? string.Empty : EncryptHelper.SHA256(CurrentFundID.ToString().Trim() + OldFundsPassword.Trim()).ToLower();
- pwds.NewPwd = string.IsNullOrEmpty(CurrentFundID.ToString()) ? string.Empty : EncryptHelper.SHA256(CurrentFundID.ToString().Trim() + NewFundsPassword.Trim()).ToLower();
- }
- ServerCount = 1;
- _loginService.ModifyPasswords(pwds, ModifyPWDSuccess, ModifyPWdError);
-
- IsBusy = true;
-
- });
- }
- }
- private void ModifyPWDSuccess(bool isOK)
- {
- ServerCount--;
- if (ServerCount > 0)
- {
- return;
- }
- //修改成功清空密码
- IsBusy = false;
- ResetPWD();
- Application.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- //LogManager.WritePassWordModifyLog(UserManager.CurrentTradeAccount, 4);
- MessageBoxHelper.ShowInfo("修改成功 "+Muchinfo.MTPClient.Resources.Client_Resource.Models_MakesureSafe_Relogin,
- Muchinfo.MTPClient.Resources.Client_Resource.Models_Tips);
- MessengerHelper.DefaultSend<string>(null, MessengerTokens.RerunApplication);
- }));
- }
- private void ModifyMemberAmountPWdError(ErrorEntity errorEntity)
- {
- IsBusy = false;
- ResetPWD();
- Application.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- ErrorManager.ShowReturnError(errorEntity, Muchinfo.MTPClient.Resources.Client_Resource.ModelsMember_ErrorTips);
- }));
- }
- private void ModifyPWdError(ErrorEntity errorEntity)
- {
- IsBusy = false;
- ResetPWD();
- Application.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- ErrorManager.ShowReturnError(errorEntity, Muchinfo.MTPClient.Resources.Client_Resource.Models_ErrorTips);
- }));
- }
- private void ResetPWD()
- {
- OldFundsPassword = "";
- NewFundsPassword = "";
- ConfFundsPassword = "";
- RaisePropertyChanged(OldFundsPassword);
- RaisePropertyChanged(NewFundsPassword);
- RaisePropertyChanged(ConfFundsPassword);
- // LogManager.WritePassWordModifyLog(UserManager.CurrentTradeAccount, 3);
- OldLoginPassword = "";
- NewLoginPassword = "";
- ConfLoginPassword = "";
- RaisePropertyChanged(OldLoginPassword);
- RaisePropertyChanged(NewLoginPassword);
- RaisePropertyChanged(ConfLoginPassword);
- }
- #endregion
- #region Methods
- /// <summary>
- /// 客户端验证登录数据
- /// </summary>
- /// <returns></returns>
- private bool ValidData()
- {
- ErrorMsg = string.Empty;
- if (LoginID == uint.MaxValue)
- {
- ErrorMsg = Muchinfo.MTPClient.Resources.Client_Resource.Models_GetAccount_Failure;
- return false;
- }
- if (string.IsNullOrWhiteSpace(OldLoginPassword))
- {
- ErrorMsg = Muchinfo.MTPClient.Resources.Client_Resource.Models_NotInputModifyPassword;
- return false;
- }
- #region 验证登录密码
- OldLoginPassword = OldLoginPassword.Trim();
- if (!string.IsNullOrWhiteSpace(OldLoginPassword))
- {
- NewLoginPassword = NewLoginPassword.Trim();
- ConfLoginPassword = ConfLoginPassword.Trim();
- //验证交易密码
- if (OldLoginPassword.Length < 6)
- {
- ErrorMsg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.Models_PasswordNotless6, Muchinfo.MTPClient.Resources.Client_Resource.Models_TradePassword);
- }
- else if (NewLoginPassword.Length < 6)
- {
- ErrorMsg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.Models_ClearPassword, Muchinfo.MTPClient.Resources.Client_Resource.Models_TradePassword);
- }
- else if (ConfLoginPassword.Length < 6)
- {
- ErrorMsg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.Models_MakesurePasswordNotless6);
- }
- else if (!NewLoginPassword.Equals(ConfLoginPassword))
- {
- ErrorMsg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.Models_MakesurePasswordUnmatchNewPassword);
- }
- else if (NewLoginPassword.Equals(OldLoginPassword))
- {
- ErrorMsg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.Models_NewPasswordUnmatchOriginalPassword);
- }
- if (!string.IsNullOrWhiteSpace(ErrorMsg))
- {
- var temp = ErrorMsg;
- IsTradePanel = true;
- ErrorMsg = temp;
- return false;
- }
- }
- #endregion
- #region 验证资金密码
- OldFundsPassword = OldFundsPassword.Trim();
- if (!string.IsNullOrWhiteSpace(OldFundsPassword))
- {
- NewFundsPassword = NewFundsPassword.Trim();
- ConfFundsPassword = ConfFundsPassword.Trim();
- //验证交易密码
- if (OldFundsPassword.Length < 6)
- {
- ErrorMsg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.Models_PasswordNotless6, Muchinfo.MTPClient.Resources.Client_Resource.Models_FundsPassword);
- }
- else if (NewFundsPassword.Length < 6)
- {
- ErrorMsg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.Models_ClearPassword, Muchinfo.MTPClient.Resources.Client_Resource.Models_FundsPassword);
- }
- else if (ConfFundsPassword.Length < 6)
- {
- ErrorMsg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.Models_MakesurePasswordNotless6);
- }
- else if (!NewFundsPassword.Equals(ConfFundsPassword))
- {
- ErrorMsg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.Models_MakesurePasswordUnmatchNewPassword);
- }
- else if (NewFundsPassword.Equals(OldFundsPassword))
- {
- ErrorMsg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.Models_NewPasswordUnmatchOriginalPassword);
- }
- if (!string.IsNullOrWhiteSpace(ErrorMsg))
- {
- var temp = ErrorMsg;
- IsFundsPanel = true;
- ErrorMsg = temp;
- return false;
- }
- }
- #endregion
- return true;
- }
- #endregion Methods
- }
- }
|