PasswordUpdataRegionVIewModel.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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 string uuid = ServiceHelper.GetDeviceSerialNumber();
  20. private LoginDialogViewModel LoginDialogViewModel;
  21. public IDialogService dialogs;
  22. public bool IsNavigationTarget(NavigationContext navigationContext)
  23. {
  24. return true;
  25. }
  26. public void OnNavigatedFrom(NavigationContext navigationContext)
  27. {
  28. }
  29. public void OnNavigatedTo(NavigationContext navigationContext)
  30. {
  31. navigationContext.Parameters.TryGetValue<LoginDialogViewModel>("LoginDialogViewModel", out LoginDialogViewModel);
  32. LoginEmail = LoginDialogViewModel.LoginEmail;
  33. }
  34. private bool enableNextStep = false;
  35. public bool EnableNextStep
  36. {
  37. get { return enableNextStep; }
  38. set { SetProperty(ref enableNextStep, value); }
  39. }
  40. private string _LoginEmail = "";
  41. public string LoginEmail
  42. {
  43. get { return _LoginEmail; }
  44. set
  45. {
  46. SetProperty(ref _LoginEmail, value);
  47. CheckEnableNextStepEncrypt();
  48. }
  49. }
  50. private string _LoginPasswordlook;
  51. public string LoginPasswordlook
  52. {
  53. get { return _LoginPasswordlook; }
  54. set { SetProperty(ref _LoginPasswordlook, value); }
  55. }
  56. private string _LoginPasswordlook2;
  57. public string LoginPasswordlook2
  58. {
  59. get { return _LoginPasswordlook2; }
  60. set { SetProperty(ref _LoginPasswordlook2, value); }
  61. }
  62. private string _LoginPassword = "";
  63. public string LoginPassword
  64. {
  65. get { return _LoginPassword; }
  66. set
  67. {
  68. SetProperty(ref _LoginPassword, value);
  69. PasswordUpdatalookVis = Visibility.Collapsed;
  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. PasswordUpdatalookVis = Visibility.Collapsed;
  133. if (string.IsNullOrEmpty(LoginPassword2))
  134. {
  135. ChkVis2 = Visibility.Collapsed;
  136. }
  137. else
  138. {
  139. ChkVis2 = Visibility.Visible;
  140. }
  141. CheckEnableNextStepEncrypt();
  142. }
  143. }
  144. private string _LoginPasswordMsg2 = "Enter your password";
  145. public string LoginPasswordMsg2
  146. {
  147. get { return _LoginPasswordMsg2; }
  148. set
  149. {
  150. SetProperty(ref _LoginPasswordMsg2, value);
  151. }
  152. }
  153. private Visibility _LoginPasswordVisibility2 = Visibility.Visible;
  154. public Visibility LoginPasswordVisibility2
  155. {
  156. get { return _LoginPasswordVisibility2; }
  157. set
  158. {
  159. if (value == Visibility.Visible)
  160. {
  161. LoginTextVisibility2 = Visibility.Collapsed;
  162. }
  163. else
  164. {
  165. LoginTextVisibility2 = Visibility.Visible;
  166. }
  167. SetProperty(ref _LoginPasswordVisibility2, value);
  168. }
  169. }
  170. private Visibility _LoginTextVisibility2 = Visibility.Collapsed;
  171. public Visibility LoginTextVisibility2
  172. {
  173. get { return _LoginTextVisibility2; }
  174. set { SetProperty(ref _LoginTextVisibility2, value); }
  175. }
  176. private string _PasswordUpdatamsglook = "";
  177. public string PasswordUpdatamsglook
  178. {
  179. get { return _PasswordUpdatamsglook; }
  180. set
  181. {
  182. SetProperty(ref _PasswordUpdatamsglook, value);
  183. }
  184. }
  185. private Visibility _PasswordUpdatalookVis = Visibility.Collapsed;
  186. public Visibility PasswordUpdatalookVis
  187. {
  188. get { return _PasswordUpdatalookVis; }
  189. set { SetProperty(ref _PasswordUpdatalookVis, value); }
  190. }
  191. public DelegateCommand<object> DisplayPasswordCommand { get; set; }
  192. public DelegateCommand<object> DisplayPasswordCommand2 { get; set; }
  193. public DelegateCommand ChangeEmailCommand { get; set; }
  194. public DelegateCommand GoCodeUpdataCommand { get; set; }
  195. public DelegateCommand PasswordUpdataCommand { get; set; }
  196. public DelegateCommand LinkLicenseCommand { get; set; }
  197. public DelegateCommand LoginPasswordChangedCommand { get; set; }
  198. public DelegateCommand LoginPasswordChanged2Command { get; set; }
  199. PasswordUpdataRegionViewModel(IRegionManager regionManager, IDialogService dialogService)
  200. {
  201. dialogs = dialogService;
  202. DisplayPasswordCommand = new DelegateCommand<object>(DisplayPassword);
  203. DisplayPasswordCommand2 = new DelegateCommand<object>(DisplayPassword2);
  204. PasswordUpdataCommand = new DelegateCommand(PasswordUpdata);
  205. LoginPasswordChangedCommand = new DelegateCommand(LoginPasswordChanged);
  206. LoginPasswordChanged2Command = new DelegateCommand(LoginPasswordChanged2);
  207. }
  208. private void LoginPasswordChanged()
  209. {
  210. if (LoginPassword.Length < 6)
  211. {
  212. LoginPasswordlook = "At least 6 characters";
  213. }
  214. else if (LoginPassword.Length > 24)
  215. {
  216. LoginPasswordlook = "Up to 24 characters";
  217. }
  218. else
  219. {
  220. LoginPasswordlook = "";
  221. }
  222. }
  223. private void LoginPasswordChanged2()
  224. {
  225. if (LoginPassword2.Length < 6)
  226. {
  227. LoginPasswordlook2 = "At least 6 characters";
  228. }
  229. else if (LoginPassword2.Length > 24)
  230. {
  231. LoginPasswordlook2 = "Up to 24 characters";
  232. }
  233. else
  234. {
  235. LoginPasswordlook2 = "";
  236. }
  237. }
  238. private void PasswordUpdata()
  239. {
  240. if (ServiceHelper.Rebirth(LoginEmail, LoginPassword2, LoginPassword, LoginDialogViewModel.PasswordCode) == "success")
  241. {
  242. LoginDialogViewModel.RegionMan("LoginRegion");
  243. }
  244. else
  245. {
  246. PasswordUpdatamsglook = ServiceHelper.Rebirth(LoginEmail, LoginPassword2, LoginPassword, LoginDialogViewModel.PasswordCode);
  247. PasswordUpdatalookVis = Visibility.Visible;
  248. }
  249. }
  250. private void CheckEnableNextStepEncrypt()
  251. {
  252. EnableNextStep = true;
  253. if (LoginPassword.Length < 6 || LoginPassword.Length > 24 || LoginPassword2.Length < 6 || LoginPassword2.Length > 24)
  254. {
  255. EnableNextStep = false;
  256. }
  257. }
  258. public void DisplayPassword(object e)
  259. {
  260. var chk = e as CheckBox;
  261. if (chk != null)
  262. {
  263. if (chk.IsChecked == true)
  264. {
  265. LoginPasswordVisibility = Visibility.Collapsed;
  266. }
  267. else
  268. {
  269. LoginPasswordVisibility = Visibility.Visible;
  270. }
  271. }
  272. }
  273. public void DisplayPassword2(object e)
  274. {
  275. var chk = e as CheckBox;
  276. if (chk != null)
  277. {
  278. if (chk.IsChecked == true)
  279. {
  280. LoginPasswordVisibility2 = Visibility.Collapsed;
  281. }
  282. else
  283. {
  284. LoginPasswordVisibility2 = Visibility.Visible;
  285. }
  286. }
  287. }
  288. }
  289. }