LoginPasswordRegionViewModel.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. using PDF_Office.CustomControl;
  2. using PDF_Office.Helper;
  3. using PDF_Office.Model;
  4. using PDF_Office.Views.Dialog.ServiceDialog;
  5. using Prism.Commands;
  6. using Prism.Mvvm;
  7. using Prism.Regions;
  8. using Prism.Services.Dialogs;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Diagnostics;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using System.Windows;
  16. using System.Windows.Controls;
  17. using System.Windows.Documents;
  18. using System.Windows.Navigation;
  19. namespace PDF_Office.ViewModels.Dialog.ServiceDialog
  20. {
  21. public class LoginPasswordRegionViewModel : BindableBase, INavigationAware
  22. {
  23. private static Guid myuuid = Guid.NewGuid();
  24. private string uuid = myuuid.ToString();
  25. private LoginDialogViewModel LoginDialogViewModel;
  26. public IDialogService dialogs;
  27. public bool IsNavigationTarget(NavigationContext navigationContext)
  28. {
  29. return true;
  30. }
  31. public void OnNavigatedFrom(NavigationContext navigationContext)
  32. {
  33. }
  34. public void OnNavigatedTo(NavigationContext navigationContext)
  35. {
  36. navigationContext.Parameters.TryGetValue<LoginDialogViewModel>("LoginDialogViewModel", out LoginDialogViewModel);
  37. LoginEmail = LoginDialogViewModel.LoginEmail;
  38. }
  39. private bool enableNextStep = false;
  40. public bool EnableNextStep
  41. {
  42. get { return enableNextStep; }
  43. set { SetProperty(ref enableNextStep, value); }
  44. }
  45. private string _LoginEmail = "";
  46. public string LoginEmail
  47. {
  48. get { return _LoginEmail; }
  49. set
  50. {
  51. SetProperty(ref _LoginEmail, value);
  52. }
  53. }
  54. private string _LoginPasswordlook;
  55. public string LoginPasswordlook
  56. {
  57. get { return _LoginPasswordlook; }
  58. set { SetProperty(ref _LoginPasswordlook, value); }
  59. }
  60. private string _LoginPassword = "";
  61. public string LoginPassword
  62. {
  63. get { return _LoginPassword; }
  64. set
  65. {
  66. SetProperty(ref _LoginPassword, value);
  67. LoginPasswordmsglook = "";
  68. LoginPasswordlookVis = Visibility.Collapsed;
  69. if (string.IsNullOrEmpty(LoginPassword))
  70. {
  71. ChkVis = Visibility.Collapsed;
  72. }
  73. else
  74. {
  75. ChkVis = Visibility.Visible;
  76. }
  77. CheckEnableNextStepEncrypt();
  78. }
  79. }
  80. private string _LoginPasswordMsg = "Enter your password";
  81. public string LoginPasswordMsg
  82. {
  83. get { return _LoginPasswordMsg; }
  84. set
  85. {
  86. SetProperty(ref _LoginPasswordMsg, value);
  87. }
  88. }
  89. private string _LoginPasswordmsglook = "";
  90. public string LoginPasswordmsglook
  91. {
  92. get { return _LoginPasswordmsglook; }
  93. set
  94. {
  95. SetProperty(ref _LoginPasswordmsglook, value);
  96. }
  97. }
  98. private Visibility _LoginPasswordVisibility = Visibility.Visible;
  99. public Visibility LoginPasswordVisibility
  100. {
  101. get { return _LoginPasswordVisibility; }
  102. set
  103. {
  104. if (value == Visibility.Visible)
  105. {
  106. LoginTextVisibility = Visibility.Collapsed;
  107. }
  108. else
  109. {
  110. LoginTextVisibility = Visibility.Visible;
  111. }
  112. SetProperty(ref _LoginPasswordVisibility, value);
  113. }
  114. }
  115. private Visibility _ChkVis = Visibility.Collapsed;
  116. public Visibility ChkVis
  117. {
  118. get { return _ChkVis; }
  119. set { SetProperty(ref _ChkVis, value); }
  120. }
  121. private Visibility _LoginTextVisibility = Visibility.Collapsed;
  122. public Visibility LoginTextVisibility
  123. {
  124. get { return _LoginTextVisibility; }
  125. set { SetProperty(ref _LoginTextVisibility, value); }
  126. }
  127. private Visibility _LoginPasswordlookVis = Visibility.Collapsed;
  128. public Visibility LoginPasswordlookVis
  129. {
  130. get { return _LoginPasswordlookVis; }
  131. set { SetProperty(ref _LoginPasswordlookVis, value); }
  132. }
  133. public DelegateCommand<object> DisplayPasswordCommand { get; set; }
  134. public DelegateCommand ChangeEmailCommand { get; set; }
  135. public DelegateCommand GoCodeUpdataCommand { get; set; }
  136. public DelegateCommand LoginCommand { get; set; }
  137. public DelegateCommand LinkLicenseCommand { get; set; }
  138. public DelegateCommand LoginPasswordChangedCommand { get; set; }
  139. LoginPasswordRegionViewModel(IRegionManager regionManager, IDialogService dialogService)
  140. {
  141. dialogs = dialogService;
  142. DisplayPasswordCommand = new DelegateCommand<object>(DisplayPassword);
  143. LoginCommand = new DelegateCommand(Login);
  144. ChangeEmailCommand = new DelegateCommand(ChangeEmail);
  145. GoCodeUpdataCommand = new DelegateCommand(GoCodeUpdata);
  146. LoginPasswordChangedCommand = new DelegateCommand(LoginPasswordChanged);
  147. }
  148. //密码改变
  149. private void LoginPasswordChanged()
  150. {
  151. if (LoginPassword.Length < 6)
  152. {
  153. LoginPasswordlook = "At least 6 characters";
  154. }
  155. else if (LoginPassword.Length > 24)
  156. {
  157. LoginPasswordlook = "Up to 24 characters";
  158. }
  159. else
  160. {
  161. LoginPasswordlook = "";
  162. }
  163. }
  164. //获取忘记密码验证码
  165. private void GoCodeUpdata()
  166. {
  167. ServiceHelper.Get_code("user_reset_password", LoginEmail);
  168. LoginDialogViewModel.IsReset = true;
  169. LoginDialogViewModel.RegionMan("CodeRegion");
  170. }
  171. //登录
  172. private void Login()
  173. {
  174. if (ServiceHelper.Login(LoginEmail, LoginPassword, uuid) == "success")
  175. {
  176. LoginDialogViewModel.Close();
  177. App.mainWindowViewModel.UserVis = Visibility.Visible;
  178. App.mainWindowViewModel.RegisterVis = Visibility.Collapsed;
  179. App.mainWindowViewModel.LoginVis = Visibility.Collapsed;
  180. App.mainWindowViewModel.OphVis = Visibility.Collapsed;
  181. }
  182. else if(ServiceHelper.Login(LoginEmail, LoginPassword, uuid) == "网络不稳定请重试")
  183. {
  184. LoginDialogViewModel.RegionMan("NOInternetRegion");
  185. }
  186. else
  187. {
  188. LoginPasswordmsglook = ServiceHelper.Login(LoginEmail, LoginPassword, uuid);
  189. LoginPasswordlookVis = Visibility.Visible;
  190. }
  191. }
  192. private void ChangeEmail()
  193. {
  194. LoginDialogViewModel.RegionMan("LoginRegion");
  195. }
  196. private void CheckEnableNextStepEncrypt()
  197. {
  198. EnableNextStep = true;
  199. if (LoginPassword.Length < 6 || LoginPassword.Length > 24 )
  200. {
  201. EnableNextStep = false;
  202. }
  203. }
  204. public void DisplayPassword(object e)
  205. {
  206. var chk = e as CheckBox;
  207. if (chk != null)
  208. {
  209. if (chk.IsChecked == true)
  210. {
  211. LoginPasswordVisibility = Visibility.Collapsed;
  212. }
  213. else
  214. {
  215. LoginPasswordVisibility = Visibility.Visible;
  216. }
  217. }
  218. }
  219. }
  220. }