PasswordUpdataRegionVIewModel.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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. PasswordUpdatalookVis = Visibility.Collapsed;
  71. if (string.IsNullOrEmpty(LoginPassword))
  72. {
  73. ChkVis = Visibility.Collapsed;
  74. }
  75. else
  76. {
  77. ChkVis = Visibility.Visible;
  78. }
  79. CheckEnableNextStepEncrypt();
  80. }
  81. }
  82. private string _LoginPasswordMsg = "Enter the new password again";
  83. public string LoginPasswordMsg
  84. {
  85. get { return _LoginPasswordMsg; }
  86. set
  87. {
  88. SetProperty(ref _LoginPasswordMsg, value);
  89. }
  90. }
  91. private Visibility _ChkVis = Visibility.Collapsed;
  92. public Visibility ChkVis
  93. {
  94. get { return _ChkVis; }
  95. set { SetProperty(ref _ChkVis, value); }
  96. }
  97. private Visibility _ChkVis2 = Visibility.Collapsed;
  98. public Visibility ChkVis2
  99. {
  100. get { return _ChkVis2; }
  101. set { SetProperty(ref _ChkVis2, value); }
  102. }
  103. private Visibility _LoginPasswordVisibility = Visibility.Visible;
  104. public Visibility LoginPasswordVisibility
  105. {
  106. get { return _LoginPasswordVisibility; }
  107. set
  108. {
  109. if (value == Visibility.Visible)
  110. {
  111. LoginTextVisibility = Visibility.Collapsed;
  112. }
  113. else
  114. {
  115. LoginTextVisibility = Visibility.Visible;
  116. }
  117. SetProperty(ref _LoginPasswordVisibility, value);
  118. }
  119. }
  120. private Visibility _LoginTextVisibility = Visibility.Collapsed;
  121. public Visibility LoginTextVisibility
  122. {
  123. get { return _LoginTextVisibility; }
  124. set { SetProperty(ref _LoginTextVisibility, value); }
  125. }
  126. private string _LoginPassword2 = "";
  127. public string LoginPassword2
  128. {
  129. get { return _LoginPassword2; }
  130. set
  131. {
  132. SetProperty(ref _LoginPassword2, value);
  133. PasswordUpdatalookVis = Visibility.Collapsed;
  134. if (string.IsNullOrEmpty(LoginPassword2))
  135. {
  136. ChkVis2 = Visibility.Collapsed;
  137. }
  138. else
  139. {
  140. ChkVis2 = Visibility.Visible;
  141. }
  142. CheckEnableNextStepEncrypt();
  143. }
  144. }
  145. private string _LoginPasswordMsg2 = "Enter your password";
  146. public string LoginPasswordMsg2
  147. {
  148. get { return _LoginPasswordMsg2; }
  149. set
  150. {
  151. SetProperty(ref _LoginPasswordMsg2, value);
  152. }
  153. }
  154. private Visibility _LoginPasswordVisibility2 = Visibility.Visible;
  155. public Visibility LoginPasswordVisibility2
  156. {
  157. get { return _LoginPasswordVisibility2; }
  158. set
  159. {
  160. if (value == Visibility.Visible)
  161. {
  162. LoginTextVisibility2 = Visibility.Collapsed;
  163. }
  164. else
  165. {
  166. LoginTextVisibility2 = Visibility.Visible;
  167. }
  168. SetProperty(ref _LoginPasswordVisibility2, value);
  169. }
  170. }
  171. private Visibility _LoginTextVisibility2 = Visibility.Collapsed;
  172. public Visibility LoginTextVisibility2
  173. {
  174. get { return _LoginTextVisibility2; }
  175. set { SetProperty(ref _LoginTextVisibility2, value); }
  176. }
  177. private string _PasswordUpdatamsglook = "";
  178. public string PasswordUpdatamsglook
  179. {
  180. get { return _PasswordUpdatamsglook; }
  181. set
  182. {
  183. SetProperty(ref _PasswordUpdatamsglook, value);
  184. }
  185. }
  186. private Visibility _PasswordUpdatalookVis = Visibility.Collapsed;
  187. public Visibility PasswordUpdatalookVis
  188. {
  189. get { return _PasswordUpdatalookVis; }
  190. set { SetProperty(ref _PasswordUpdatalookVis, value); }
  191. }
  192. public DelegateCommand<object> DisplayPasswordCommand { get; set; }
  193. public DelegateCommand<object> DisplayPasswordCommand2 { get; set; }
  194. public DelegateCommand ChangeEmailCommand { get; set; }
  195. public DelegateCommand GoCodeUpdataCommand { get; set; }
  196. public DelegateCommand PasswordUpdataCommand { get; set; }
  197. public DelegateCommand LinkLicenseCommand { get; set; }
  198. public DelegateCommand LoginPasswordChangedCommand { get; set; }
  199. public DelegateCommand LoginPasswordChanged2Command { get; set; }
  200. public DelegateCommand CloseDialogCommand { get; set; }
  201. PasswordUpdataRegionViewModel(IRegionManager regionManager, IDialogService dialogService)
  202. {
  203. dialogs = dialogService;
  204. DisplayPasswordCommand = new DelegateCommand<object>(DisplayPassword);
  205. DisplayPasswordCommand2 = new DelegateCommand<object>(DisplayPassword2);
  206. PasswordUpdataCommand = new DelegateCommand(PasswordUpdata);
  207. LoginPasswordChangedCommand = new DelegateCommand(LoginPasswordChanged);
  208. LoginPasswordChanged2Command = new DelegateCommand(LoginPasswordChanged2);
  209. CloseDialogCommand = new DelegateCommand(CloseDialog);
  210. }
  211. private void CloseDialog()
  212. {
  213. LoginDialogViewModel.Close();
  214. }
  215. private void LoginPasswordChanged()
  216. {
  217. if (LoginPassword.Length < 6)
  218. {
  219. LoginPasswordlook = "At least 6 characters";
  220. }
  221. else if (LoginPassword.Length > 24)
  222. {
  223. LoginPasswordlook = "Up to 24 characters";
  224. }
  225. else
  226. {
  227. LoginPasswordlook = "";
  228. }
  229. }
  230. private void LoginPasswordChanged2()
  231. {
  232. if (LoginPassword2.Length < 6)
  233. {
  234. LoginPasswordlook2 = "At least 6 characters";
  235. }
  236. else if (LoginPassword2.Length > 24)
  237. {
  238. LoginPasswordlook2 = "Up to 24 characters";
  239. }
  240. else
  241. {
  242. LoginPasswordlook2 = "";
  243. }
  244. }
  245. private void PasswordUpdata()
  246. {
  247. if (ServiceHelper.Rebirth(LoginEmail, LoginPassword2, LoginPassword, LoginDialogViewModel.PasswordCode) == "success")
  248. {
  249. LoginDialogViewModel.RegionMan("LoginRegion");
  250. }
  251. else
  252. {
  253. PasswordUpdatamsglook = ServiceHelper.Rebirth(LoginEmail, LoginPassword2, LoginPassword, LoginDialogViewModel.PasswordCode);
  254. PasswordUpdatalookVis = Visibility.Visible;
  255. }
  256. }
  257. private void CheckEnableNextStepEncrypt()
  258. {
  259. EnableNextStep = true;
  260. if (LoginPassword.Length < 6 || LoginPassword.Length > 24 || LoginPassword2.Length < 6 || LoginPassword2.Length > 24)
  261. {
  262. EnableNextStep = false;
  263. }
  264. }
  265. public void DisplayPassword(object e)
  266. {
  267. var chk = e as CheckBox;
  268. if (chk != null)
  269. {
  270. if (chk.IsChecked == true)
  271. {
  272. LoginPasswordVisibility = Visibility.Collapsed;
  273. }
  274. else
  275. {
  276. LoginPasswordVisibility = Visibility.Visible;
  277. }
  278. }
  279. }
  280. public void DisplayPassword2(object e)
  281. {
  282. var chk = e as CheckBox;
  283. if (chk != null)
  284. {
  285. if (chk.IsChecked == true)
  286. {
  287. LoginPasswordVisibility2 = Visibility.Collapsed;
  288. }
  289. else
  290. {
  291. LoginPasswordVisibility2 = Visibility.Visible;
  292. }
  293. }
  294. }
  295. }
  296. }