TradePWDModifyViewModel.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. using System.Linq;
  2. using GalaSoft.MvvmLight;
  3. using GalaSoft.MvvmLight.Command;
  4. using GalaSoft.MvvmLight.Ioc;
  5. using Muchinfo.MTPClient.Account.Views;
  6. using Muchinfo.MTPClient.Data;
  7. using Muchinfo.MTPClient.Data.Enums;
  8. using Muchinfo.MTPClient.Data.Model.Account;
  9. using Muchinfo.MTPClient.Infrastructure.Helpers;
  10. using Muchinfo.MTPClient.Infrastructure.MessageBox;
  11. using Muchinfo.MTPClient.Infrastructure.Utilities;
  12. using Muchinfo.MTPClient.IService;
  13. using Muchinfo.WPF.Controls.Windows;
  14. using System;
  15. using System.Collections.Generic;
  16. using System.Windows;
  17. namespace Muchinfo.MTPClient.Account.ViewModels
  18. {
  19. /// <summary>
  20. /// 交易密码修改业务逻辑
  21. /// </summary>
  22. public class TradePWDModifyViewModel : ViewModelBase
  23. {
  24. #region Constructors
  25. public TradePWDModifyViewModel(bool isUnforceUpdate)
  26. {
  27. OldLoginPassword = string.Empty;
  28. NewLoginPassword = string.Empty;
  29. ConfLoginPassword = string.Empty;
  30. OldFundsPassword = string.Empty;
  31. NewFundsPassword = string.Empty;
  32. ConfFundsPassword = string.Empty;
  33. IsTradePanel = true;
  34. LoginID = UserManager.CurrentTradeAccount != null ? UserManager.CurrentTradeAccount.LoginID : uint.MaxValue;
  35. FundsLst = UserManager.CurrentTradeAccount != null ? UserManager.CurrentTradeAccount.FundsAccountIds : new List<ulong>();
  36. _loginService = SimpleIoc.Default.GetService(typeof(ILoginService)) as ILoginService;
  37. IsUnforceUpdate = isUnforceUpdate;
  38. }
  39. #endregion Constructors
  40. #region Properties
  41. public ILoginService _loginService { get; set; }
  42. private int ServerCount = 0;
  43. private bool _isTradePanel;
  44. /// <summary>
  45. /// 是否选中修改交易密码面板
  46. /// </summary>
  47. public bool IsTradePanel
  48. {
  49. get { return _isTradePanel; }
  50. set
  51. {
  52. Set(() => IsTradePanel, ref _isTradePanel, value);
  53. ErrorMsg = string.Empty;
  54. }
  55. }
  56. private bool _isPhonePanel;
  57. /// <summary>
  58. /// 是否选中修改电话密码面板
  59. /// </summary>
  60. public bool IsPhonePanel
  61. {
  62. get { return _isPhonePanel; }
  63. set
  64. {
  65. Set(() => IsPhonePanel, ref _isPhonePanel, value);
  66. ErrorMsg = string.Empty;
  67. }
  68. }
  69. private bool _isCommunicationPanel;
  70. /// <summary>
  71. /// 是否选中修改通讯密码面板
  72. /// </summary>
  73. public bool IsCommunicationPanel
  74. {
  75. get { return _isCommunicationPanel; }
  76. set
  77. {
  78. Set(() => IsCommunicationPanel, ref _isCommunicationPanel, value);
  79. ErrorMsg = string.Empty;
  80. }
  81. }
  82. private bool _isFundsPanel;
  83. /// <summary>
  84. /// 是否选中修改通讯密码面板
  85. /// </summary>
  86. public bool IsFundsPanel
  87. {
  88. get { return _isFundsPanel; }
  89. set
  90. {
  91. Set(() => IsFundsPanel, ref _isFundsPanel, value);
  92. ErrorMsg = string.Empty;
  93. }
  94. }
  95. //错误提示
  96. private string _errorMsg;
  97. /// <summary>
  98. /// 修改不成功出现的错误提示
  99. /// </summary>
  100. public string ErrorMsg
  101. {
  102. get
  103. {
  104. return _errorMsg;
  105. }
  106. set
  107. {
  108. Set(() => ErrorMsg, ref _errorMsg, value);
  109. }
  110. }
  111. /// <summary>
  112. /// 是否显示忙
  113. /// </summary>
  114. private bool _isBusy;
  115. /// <summary>
  116. /// 是否忙,显示等待控件
  117. /// </summary>
  118. public bool IsBusy
  119. {
  120. get { return _isBusy; }
  121. set { Set(() => IsBusy, ref _isBusy, value); }
  122. }
  123. /// <summary>
  124. /// 登录账号
  125. /// </summary>
  126. public ulong LoginID { get; set; }
  127. /// <summary>
  128. /// 旧登录密码
  129. /// </summary>
  130. public string OldLoginPassword { get; set; }
  131. /// <summary>
  132. /// 新登录密码
  133. /// </summary>
  134. public string NewLoginPassword { get; set; }
  135. /// <summary>
  136. /// 确认登录密码
  137. /// </summary>
  138. public string ConfLoginPassword { get; set; }
  139. /// <summary>
  140. /// 资金账户ID列表
  141. /// </summary>
  142. public List<ulong> FundsLst { get; set; }
  143. /// <summary>
  144. /// 旧资金帐号密码
  145. /// </summary>
  146. public string OldFundsPassword { get; set; }
  147. /// <summary>
  148. /// 新资金账号密码
  149. /// </summary>
  150. public string NewFundsPassword { get; set; }
  151. /// <summary>
  152. /// 确认资金帐号密码
  153. /// </summary>
  154. public string ConfFundsPassword { get; set; }
  155. private ulong _currentFundID = uint.MaxValue;
  156. public ulong CurrentFundID
  157. {
  158. get { return _currentFundID; }
  159. set
  160. {
  161. Set(() => CurrentFundID, ref _currentFundID, value);
  162. }
  163. }
  164. private bool _isUnforceUpdate = true;
  165. /// <summary>
  166. /// 是否非强制修改
  167. /// </summary>
  168. /// <value><c>true</c> if this instance is unforce update; otherwise, <c>false</c>.</value>
  169. public bool IsUnforceUpdate
  170. {
  171. get { return _isUnforceUpdate; }
  172. set
  173. {
  174. Set(() => IsUnforceUpdate, ref _isUnforceUpdate, value);
  175. }
  176. }
  177. #endregion Properties
  178. #region Command
  179. public RelayCommand<TradePWDModifyView> CancelCommand
  180. {
  181. get
  182. {
  183. return new RelayCommand<TradePWDModifyView>((w) =>
  184. {
  185. w.DialogResult = false;
  186. });
  187. }
  188. }
  189. /// <summary>
  190. /// 修改密码
  191. /// </summary>
  192. public RelayCommand<TradePWDModifyView> OKCommand
  193. {
  194. get
  195. {
  196. return new RelayCommand<TradePWDModifyView>((w) =>
  197. {
  198. if (!ValidData()) return;
  199. var pwds = new AccountPwds() { ModifyPwdType = 1 };
  200. if (IsTradePanel)
  201. {
  202. pwds.ModifyPwdType = 1;
  203. pwds.ModifyPwdID = LoginID;
  204. pwds.OldPwd = string.IsNullOrEmpty(OldLoginPassword) ? string.Empty : EncryptHelper.SHA256(LoginID.ToString().Trim() + OldLoginPassword.Trim()).ToLower();
  205. pwds.NewPwd = string.IsNullOrEmpty(NewLoginPassword) ? string.Empty : EncryptHelper.SHA256(LoginID.ToString().Trim() + NewLoginPassword.Trim()).ToLower(); ;
  206. }
  207. else if (IsFundsPanel)
  208. {
  209. pwds.ModifyPwdType = 2;
  210. pwds.ModifyPwdID = CurrentFundID;
  211. pwds.OldPwd = string.IsNullOrEmpty(CurrentFundID.ToString()) ? string.Empty : EncryptHelper.SHA256(CurrentFundID.ToString().Trim() + OldFundsPassword.Trim()).ToLower();
  212. pwds.NewPwd = string.IsNullOrEmpty(CurrentFundID.ToString()) ? string.Empty : EncryptHelper.SHA256(CurrentFundID.ToString().Trim() + NewFundsPassword.Trim()).ToLower();
  213. }
  214. ServerCount = 1;
  215. _loginService.ModifyPasswords(pwds, ModifyPWDSuccess, ModifyPWdError);
  216. IsBusy = true;
  217. });
  218. }
  219. }
  220. private void ModifyPWDSuccess(bool isOK)
  221. {
  222. ServerCount--;
  223. if (ServerCount > 0)
  224. {
  225. return;
  226. }
  227. //修改成功清空密码
  228. IsBusy = false;
  229. ResetPWD();
  230. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  231. {
  232. //LogManager.WritePassWordModifyLog(UserManager.CurrentTradeAccount, 4);
  233. MessageBoxHelper.ShowInfo("修改成功 "+Muchinfo.MTPClient.Resources.Client_Resource.Models_MakesureSafe_Relogin,
  234. Muchinfo.MTPClient.Resources.Client_Resource.Models_Tips);
  235. MessengerHelper.DefaultSend<string>(null, MessengerTokens.RerunApplication);
  236. }));
  237. }
  238. private void ModifyMemberAmountPWdError(ErrorEntity errorEntity)
  239. {
  240. IsBusy = false;
  241. ResetPWD();
  242. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  243. {
  244. ErrorManager.ShowReturnError(errorEntity, Muchinfo.MTPClient.Resources.Client_Resource.ModelsMember_ErrorTips);
  245. }));
  246. }
  247. private void ModifyPWdError(ErrorEntity errorEntity)
  248. {
  249. IsBusy = false;
  250. ResetPWD();
  251. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  252. {
  253. ErrorManager.ShowReturnError(errorEntity, Muchinfo.MTPClient.Resources.Client_Resource.Models_ErrorTips);
  254. }));
  255. }
  256. private void ResetPWD()
  257. {
  258. OldFundsPassword = "";
  259. NewFundsPassword = "";
  260. ConfFundsPassword = "";
  261. RaisePropertyChanged(OldFundsPassword);
  262. RaisePropertyChanged(NewFundsPassword);
  263. RaisePropertyChanged(ConfFundsPassword);
  264. // LogManager.WritePassWordModifyLog(UserManager.CurrentTradeAccount, 3);
  265. OldLoginPassword = "";
  266. NewLoginPassword = "";
  267. ConfLoginPassword = "";
  268. RaisePropertyChanged(OldLoginPassword);
  269. RaisePropertyChanged(NewLoginPassword);
  270. RaisePropertyChanged(ConfLoginPassword);
  271. }
  272. #endregion
  273. #region Methods
  274. /// <summary>
  275. /// 客户端验证登录数据
  276. /// </summary>
  277. /// <returns></returns>
  278. private bool ValidData()
  279. {
  280. ErrorMsg = string.Empty;
  281. if (LoginID == uint.MaxValue)
  282. {
  283. ErrorMsg = Muchinfo.MTPClient.Resources.Client_Resource.Models_GetAccount_Failure;
  284. return false;
  285. }
  286. if (string.IsNullOrWhiteSpace(OldLoginPassword))
  287. {
  288. ErrorMsg = Muchinfo.MTPClient.Resources.Client_Resource.Models_NotInputModifyPassword;
  289. return false;
  290. }
  291. #region 验证登录密码
  292. OldLoginPassword = OldLoginPassword.Trim();
  293. if (!string.IsNullOrWhiteSpace(OldLoginPassword))
  294. {
  295. NewLoginPassword = NewLoginPassword.Trim();
  296. ConfLoginPassword = ConfLoginPassword.Trim();
  297. //验证交易密码
  298. if (OldLoginPassword.Length < 6)
  299. {
  300. ErrorMsg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.Models_PasswordNotless6, Muchinfo.MTPClient.Resources.Client_Resource.Models_TradePassword);
  301. }
  302. else if (NewLoginPassword.Length < 6)
  303. {
  304. ErrorMsg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.Models_ClearPassword, Muchinfo.MTPClient.Resources.Client_Resource.Models_TradePassword);
  305. }
  306. else if (ConfLoginPassword.Length < 6)
  307. {
  308. ErrorMsg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.Models_MakesurePasswordNotless6);
  309. }
  310. else if (!NewLoginPassword.Equals(ConfLoginPassword))
  311. {
  312. ErrorMsg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.Models_MakesurePasswordUnmatchNewPassword);
  313. }
  314. else if (NewLoginPassword.Equals(OldLoginPassword))
  315. {
  316. ErrorMsg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.Models_NewPasswordUnmatchOriginalPassword);
  317. }
  318. if (!string.IsNullOrWhiteSpace(ErrorMsg))
  319. {
  320. var temp = ErrorMsg;
  321. IsTradePanel = true;
  322. ErrorMsg = temp;
  323. return false;
  324. }
  325. }
  326. #endregion
  327. #region 验证资金密码
  328. OldFundsPassword = OldFundsPassword.Trim();
  329. if (!string.IsNullOrWhiteSpace(OldFundsPassword))
  330. {
  331. NewFundsPassword = NewFundsPassword.Trim();
  332. ConfFundsPassword = ConfFundsPassword.Trim();
  333. //验证交易密码
  334. if (OldFundsPassword.Length < 6)
  335. {
  336. ErrorMsg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.Models_PasswordNotless6, Muchinfo.MTPClient.Resources.Client_Resource.Models_FundsPassword);
  337. }
  338. else if (NewFundsPassword.Length < 6)
  339. {
  340. ErrorMsg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.Models_ClearPassword, Muchinfo.MTPClient.Resources.Client_Resource.Models_FundsPassword);
  341. }
  342. else if (ConfFundsPassword.Length < 6)
  343. {
  344. ErrorMsg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.Models_MakesurePasswordNotless6);
  345. }
  346. else if (!NewFundsPassword.Equals(ConfFundsPassword))
  347. {
  348. ErrorMsg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.Models_MakesurePasswordUnmatchNewPassword);
  349. }
  350. else if (NewFundsPassword.Equals(OldFundsPassword))
  351. {
  352. ErrorMsg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.Models_NewPasswordUnmatchOriginalPassword);
  353. }
  354. if (!string.IsNullOrWhiteSpace(ErrorMsg))
  355. {
  356. var temp = ErrorMsg;
  357. IsFundsPanel = true;
  358. ErrorMsg = temp;
  359. return false;
  360. }
  361. }
  362. #endregion
  363. return true;
  364. }
  365. #endregion Methods
  366. }
  367. }