LoginPasswordRegionViewModel.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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 LoginPasswordRegionViewModel : 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. }
  49. }
  50. private string _LoginPasswordlook;
  51. public string LoginPasswordlook
  52. {
  53. get { return _LoginPasswordlook; }
  54. set { SetProperty(ref _LoginPasswordlook, value); }
  55. }
  56. private string _LoginPassword = "";
  57. public string LoginPassword
  58. {
  59. get { return _LoginPassword; }
  60. set
  61. {
  62. SetProperty(ref _LoginPassword, value);
  63. LoginPasswordlookVis = Visibility.Collapsed;
  64. if (string.IsNullOrEmpty(LoginPassword))
  65. {
  66. ChkVis = Visibility.Collapsed;
  67. }
  68. else
  69. {
  70. ChkVis = Visibility.Visible;
  71. }
  72. CheckEnableNextStepEncrypt();
  73. }
  74. }
  75. private string _LoginPasswordMsg = "Enter your password";
  76. public string LoginPasswordMsg
  77. {
  78. get { return _LoginPasswordMsg; }
  79. set
  80. {
  81. SetProperty(ref _LoginPasswordMsg, value);
  82. }
  83. }
  84. private string _LoginPasswordmsglook = "";
  85. public string LoginPasswordmsglook
  86. {
  87. get { return _LoginPasswordmsglook; }
  88. set
  89. {
  90. SetProperty(ref _LoginPasswordmsglook, value);
  91. }
  92. }
  93. private Visibility _LoginPasswordVisibility = Visibility.Visible;
  94. public Visibility LoginPasswordVisibility
  95. {
  96. get { return _LoginPasswordVisibility; }
  97. set
  98. {
  99. if (value == Visibility.Visible)
  100. {
  101. LoginTextVisibility = Visibility.Collapsed;
  102. }
  103. else
  104. {
  105. LoginTextVisibility = Visibility.Visible;
  106. }
  107. SetProperty(ref _LoginPasswordVisibility, value);
  108. }
  109. }
  110. private Visibility _ChkVis = Visibility.Collapsed;
  111. public Visibility ChkVis
  112. {
  113. get { return _ChkVis; }
  114. set { SetProperty(ref _ChkVis, value); }
  115. }
  116. private Visibility _LoginTextVisibility = Visibility.Collapsed;
  117. public Visibility LoginTextVisibility
  118. {
  119. get { return _LoginTextVisibility; }
  120. set { SetProperty(ref _LoginTextVisibility, value); }
  121. }
  122. private Visibility _LoginPasswordlookVis = Visibility.Collapsed;
  123. public Visibility LoginPasswordlookVis
  124. {
  125. get { return _LoginPasswordlookVis; }
  126. set { SetProperty(ref _LoginPasswordlookVis, value); }
  127. }
  128. public DelegateCommand<object> DisplayPasswordCommand { get; set; }
  129. public DelegateCommand ChangeEmailCommand { get; set; }
  130. public DelegateCommand GoCodeUpdataCommand { get; set; }
  131. public DelegateCommand LoginCommand { get; set; }
  132. public DelegateCommand LinkLicenseCommand { get; set; }
  133. public DelegateCommand LoginPasswordChangedCommand { get; set; }
  134. LoginPasswordRegionViewModel(IRegionManager regionManager, IDialogService dialogService)
  135. {
  136. dialogs = dialogService;
  137. DisplayPasswordCommand = new DelegateCommand<object>(DisplayPassword);
  138. LoginCommand = new DelegateCommand(Login);
  139. ChangeEmailCommand = new DelegateCommand(ChangeEmail);
  140. GoCodeUpdataCommand = new DelegateCommand(GoCodeUpdata);
  141. LoginPasswordChangedCommand = new DelegateCommand(LoginPasswordChanged);
  142. }
  143. private void LoginPasswordChanged()
  144. {
  145. if (LoginPassword.Length < 6)
  146. {
  147. LoginPasswordlook = "At least 6 characters";
  148. }
  149. else if (LoginPassword.Length > 24)
  150. {
  151. LoginPasswordlook = "Up to 24 characters";
  152. }
  153. else
  154. {
  155. LoginPasswordlook = "";
  156. }
  157. }
  158. private void GoCodeUpdata()
  159. {
  160. ServiceHelper.Get_code("user_reset_password", LoginEmail);
  161. LoginDialogViewModel.IsReset = true;
  162. LoginDialogViewModel.RegionMan("CodeRegion");
  163. }
  164. private void Login()
  165. {
  166. if (ServiceHelper.Login(LoginEmail, LoginPassword, uuid) == "success")
  167. {
  168. LoginDialogViewModel.Close();
  169. App.mainWindowViewModel.UserVis = Visibility.Visible;
  170. App.mainWindowViewModel.RegisterVis = Visibility.Collapsed;
  171. App.mainWindowViewModel.LoginVis = Visibility.Collapsed;
  172. }
  173. else
  174. {
  175. LoginPasswordmsglook = ServiceHelper.Login(LoginEmail, LoginPassword, uuid);
  176. LoginPasswordlookVis = Visibility.Visible;
  177. }
  178. }
  179. private void ChangeEmail()
  180. {
  181. LoginDialogViewModel.RegionMan("LoginRegion");
  182. }
  183. private void CheckEnableNextStepEncrypt()
  184. {
  185. EnableNextStep = true;
  186. if (LoginPassword.Length < 6 || LoginPassword.Length > 24 )
  187. {
  188. EnableNextStep = false;
  189. }
  190. }
  191. public void DisplayPassword(object e)
  192. {
  193. var chk = e as CheckBox;
  194. if (chk != null)
  195. {
  196. if (chk.IsChecked == true)
  197. {
  198. LoginPasswordVisibility = Visibility.Collapsed;
  199. }
  200. else
  201. {
  202. LoginPasswordVisibility = Visibility.Visible;
  203. }
  204. }
  205. }
  206. }
  207. }