PasswordUpdataRegionVIewModel.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. using PDF_Office.Helper;
  2. using PDF_Office.Model;
  3. using Prism.Commands;
  4. using Prism.Mvvm;
  5. using Prism.Regions;
  6. using Prism.Services.Dialogs;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Diagnostics;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows;
  14. using System.Windows.Controls;
  15. namespace PDF_Office.ViewModels.Dialog.ServiceDialog
  16. {
  17. public class PasswordUpdataRegionViewModel : BindableBase, INavigationAware
  18. {
  19. private static Guid myuuid = Guid.NewGuid();
  20. private string uuid = myuuid.ToString();
  21. private LoginDialogViewModel LoginDialogViewModel;
  22. public IDialogService dialogs;
  23. public bool IsNavigationTarget(NavigationContext navigationContext)
  24. {
  25. return true;
  26. }
  27. public void OnNavigatedFrom(NavigationContext navigationContext)
  28. {
  29. }
  30. public void OnNavigatedTo(NavigationContext navigationContext)
  31. {
  32. navigationContext.Parameters.TryGetValue<LoginDialogViewModel>("LoginDialogViewModel", out LoginDialogViewModel);
  33. LoginEmail = LoginDialogViewModel.LoginEmail;
  34. }
  35. private bool enableNextStep = false;
  36. public bool EnableNextStep
  37. {
  38. get { return enableNextStep; }
  39. set { SetProperty(ref enableNextStep, value); }
  40. }
  41. private string _LoginEmail = "";
  42. public string LoginEmail
  43. {
  44. get { return _LoginEmail; }
  45. set
  46. {
  47. SetProperty(ref _LoginEmail, value);
  48. CheckEnableNextStepEncrypt();
  49. }
  50. }
  51. private string _LoginPasswordlook;
  52. public string LoginPasswordlook
  53. {
  54. get { return _LoginPasswordlook; }
  55. set { SetProperty(ref _LoginPasswordlook, value); }
  56. }
  57. private string _LoginPasswordlook2;
  58. public string LoginPasswordlook2
  59. {
  60. get { return _LoginPasswordlook2; }
  61. set { SetProperty(ref _LoginPasswordlook2, value); }
  62. }
  63. private string _LoginPassword = "";
  64. public string LoginPassword
  65. {
  66. get { return _LoginPassword; }
  67. set
  68. {
  69. SetProperty(ref _LoginPassword, value);
  70. if (string.IsNullOrEmpty(LoginPassword))
  71. {
  72. ChkVis = Visibility.Collapsed;
  73. }
  74. else
  75. {
  76. ChkVis = Visibility.Visible;
  77. }
  78. CheckEnableNextStepEncrypt();
  79. }
  80. }
  81. private string _LoginPasswordMsg = "Enter the new password again";
  82. public string LoginPasswordMsg
  83. {
  84. get { return _LoginPasswordMsg; }
  85. set
  86. {
  87. SetProperty(ref _LoginPasswordMsg, value);
  88. }
  89. }
  90. private Visibility _ChkVis = Visibility.Collapsed;
  91. public Visibility ChkVis
  92. {
  93. get { return _ChkVis; }
  94. set { SetProperty(ref _ChkVis, value); }
  95. }
  96. private Visibility _ChkVis2 = Visibility.Collapsed;
  97. public Visibility ChkVis2
  98. {
  99. get { return _ChkVis2; }
  100. set { SetProperty(ref _ChkVis2, value); }
  101. }
  102. private Visibility _LoginPasswordVisibility = Visibility.Visible;
  103. public Visibility LoginPasswordVisibility
  104. {
  105. get { return _LoginPasswordVisibility; }
  106. set
  107. {
  108. if (value == Visibility.Visible)
  109. {
  110. LoginTextVisibility = Visibility.Collapsed;
  111. }
  112. else
  113. {
  114. LoginTextVisibility = Visibility.Visible;
  115. }
  116. SetProperty(ref _LoginPasswordVisibility, value);
  117. }
  118. }
  119. private Visibility _LoginTextVisibility = Visibility.Collapsed;
  120. public Visibility LoginTextVisibility
  121. {
  122. get { return _LoginTextVisibility; }
  123. set { SetProperty(ref _LoginTextVisibility, value); }
  124. }
  125. private string _LoginPassword2 = "";
  126. public string LoginPassword2
  127. {
  128. get { return _LoginPassword2; }
  129. set
  130. {
  131. SetProperty(ref _LoginPassword2, value);
  132. if (string.IsNullOrEmpty(LoginPassword2))
  133. {
  134. ChkVis2 = Visibility.Collapsed;
  135. }
  136. else
  137. {
  138. ChkVis2 = Visibility.Visible;
  139. }
  140. CheckEnableNextStepEncrypt();
  141. }
  142. }
  143. private string _LoginPasswordMsg2 = "Enter your password";
  144. public string LoginPasswordMsg2
  145. {
  146. get { return _LoginPasswordMsg2; }
  147. set
  148. {
  149. SetProperty(ref _LoginPasswordMsg2, value);
  150. }
  151. }
  152. private Visibility _LoginPasswordVisibility2 = Visibility.Visible;
  153. public Visibility LoginPasswordVisibility2
  154. {
  155. get { return _LoginPasswordVisibility2; }
  156. set
  157. {
  158. if (value == Visibility.Visible)
  159. {
  160. LoginTextVisibility2 = Visibility.Collapsed;
  161. }
  162. else
  163. {
  164. LoginTextVisibility2 = Visibility.Visible;
  165. }
  166. SetProperty(ref _LoginPasswordVisibility2, value);
  167. }
  168. }
  169. private Visibility _LoginTextVisibility2 = Visibility.Collapsed;
  170. public Visibility LoginTextVisibility2
  171. {
  172. get { return _LoginTextVisibility2; }
  173. set { SetProperty(ref _LoginTextVisibility2, value); }
  174. }
  175. private string _PasswordUpdatamsglook = "";
  176. public string PasswordUpdatamsglook
  177. {
  178. get { return _PasswordUpdatamsglook; }
  179. set
  180. {
  181. SetProperty(ref _PasswordUpdatamsglook, value);
  182. }
  183. }
  184. private Visibility _PasswordUpdatalookVis = Visibility.Collapsed;
  185. public Visibility PasswordUpdatalookVis
  186. {
  187. get { return _PasswordUpdatalookVis; }
  188. set { SetProperty(ref _PasswordUpdatalookVis, value); }
  189. }
  190. public DelegateCommand<object> DisplayPasswordCommand { get; set; }
  191. public DelegateCommand<object> DisplayPasswordCommand2 { get; set; }
  192. public DelegateCommand ChangeEmailCommand { get; set; }
  193. public DelegateCommand GoCodeUpdataCommand { get; set; }
  194. public DelegateCommand PasswordUpdataCommand { get; set; }
  195. public DelegateCommand LinkLicenseCommand { get; set; }
  196. public DelegateCommand LoginPasswordChangedCommand { get; set; }
  197. public DelegateCommand LoginPasswordChanged2Command { get; set; }
  198. PasswordUpdataRegionViewModel(IRegionManager regionManager, IDialogService dialogService)
  199. {
  200. dialogs = dialogService;
  201. DisplayPasswordCommand = new DelegateCommand<object>(DisplayPassword);
  202. DisplayPasswordCommand2 = new DelegateCommand<object>(DisplayPassword2);
  203. PasswordUpdataCommand = new DelegateCommand(PasswordUpdata);
  204. LoginPasswordChangedCommand = new DelegateCommand(LoginPasswordChanged);
  205. LoginPasswordChanged2Command = new DelegateCommand(LoginPasswordChanged2);
  206. }
  207. private void LoginPasswordChanged()
  208. {
  209. if (LoginPassword.Length < 6)
  210. {
  211. LoginPasswordlook = "At least 6 characters";
  212. }
  213. else if (LoginPassword.Length > 24)
  214. {
  215. LoginPasswordlook = "Up to 24 characters";
  216. }
  217. else
  218. {
  219. LoginPasswordlook = "";
  220. }
  221. }
  222. private void LoginPasswordChanged2()
  223. {
  224. if (LoginPassword2.Length < 6)
  225. {
  226. LoginPasswordlook2 = "At least 6 characters";
  227. }
  228. else if (LoginPassword2.Length > 24)
  229. {
  230. LoginPasswordlook2 = "Up to 24 characters";
  231. }
  232. else
  233. {
  234. LoginPasswordlook2 = "";
  235. }
  236. }
  237. private void PasswordUpdata()
  238. {
  239. if (ServiceHelper.Rebirth(LoginEmail, LoginPassword2, LoginPassword, LoginDialogViewModel.PasswordCode) == "success")
  240. {
  241. LoginDialogViewModel.RegionMan("LoginRegion");
  242. }
  243. else
  244. {
  245. PasswordUpdatamsglook = ServiceHelper.Rebirth(LoginEmail, LoginPassword2, LoginPassword, LoginDialogViewModel.PasswordCode);
  246. PasswordUpdatalookVis = Visibility.Visible;
  247. }
  248. }
  249. private void CheckEnableNextStepEncrypt()
  250. {
  251. EnableNextStep = true;
  252. if (LoginPassword.Length < 6 || LoginPassword.Length > 24 || LoginPassword2.Length < 6 || LoginPassword2.Length > 24)
  253. {
  254. EnableNextStep = false;
  255. }
  256. }
  257. public void DisplayPassword(object e)
  258. {
  259. var chk = e as CheckBox;
  260. if (chk != null)
  261. {
  262. if (chk.IsChecked == true)
  263. {
  264. LoginPasswordVisibility = Visibility.Collapsed;
  265. }
  266. else
  267. {
  268. LoginPasswordVisibility = Visibility.Visible;
  269. }
  270. }
  271. }
  272. public void DisplayPassword2(object e)
  273. {
  274. var chk = e as CheckBox;
  275. if (chk != null)
  276. {
  277. if (chk.IsChecked == true)
  278. {
  279. LoginPasswordVisibility2 = Visibility.Collapsed;
  280. }
  281. else
  282. {
  283. LoginPasswordVisibility2 = Visibility.Visible;
  284. }
  285. }
  286. }
  287. }
  288. }