LoginPasswordRegionViewModel.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. using PDF_Master.CustomControl;
  2. using PDF_Master.Helper;
  3. using PDF_Master.Model;
  4. using PDF_Master.Properties;
  5. using PDF_Master.Views.Dialog.ServiceDialog;
  6. using Prism.Commands;
  7. using Prism.Mvvm;
  8. using Prism.Regions;
  9. using Prism.Services.Dialogs;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Diagnostics;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. using System.Windows;
  17. using System.Windows.Controls;
  18. using System.Windows.Documents;
  19. using System.Windows.Navigation;
  20. namespace PDF_Master.ViewModels.Dialog.ServiceDialog
  21. {
  22. public class LoginPasswordRegionViewModel : BindableBase, INavigationAware
  23. {
  24. private string uuid = ServiceHelper.GetDeviceSerialNumber();
  25. private LoginDialogViewModel LoginDialogViewModel;
  26. private ErrorCodeHelper ErrorCodeHelper = new ErrorCodeHelper();
  27. public IDialogService dialogs;
  28. public bool IsNavigationTarget(NavigationContext navigationContext)
  29. {
  30. return true;
  31. }
  32. public void OnNavigatedFrom(NavigationContext navigationContext)
  33. {
  34. }
  35. public void OnNavigatedTo(NavigationContext navigationContext)
  36. {
  37. navigationContext.Parameters.TryGetValue<LoginDialogViewModel>("LoginDialogViewModel", out LoginDialogViewModel);
  38. LoginEmail = LoginDialogViewModel.LoginEmail;
  39. }
  40. #region 文案
  41. private string _Text_login = "";
  42. public string Text_login
  43. {
  44. get { return _Text_login; }
  45. set
  46. {
  47. SetProperty(ref _Text_login, value);
  48. }
  49. }
  50. private string _Text_chmail = "";
  51. public string Text_chmail
  52. {
  53. get { return _Text_chmail; }
  54. set
  55. {
  56. SetProperty(ref _Text_chmail, value);
  57. }
  58. }
  59. private string _Text_enterpass = "";
  60. public string Text_enterpass
  61. {
  62. get { return _Text_enterpass; }
  63. set
  64. {
  65. SetProperty(ref _Text_enterpass, value);
  66. }
  67. }
  68. private string _LoginPasswordMsg0 = "";
  69. public string LoginPasswordMsg0
  70. {
  71. get { return _LoginPasswordMsg0; }
  72. set
  73. {
  74. SetProperty(ref _LoginPasswordMsg0, value);
  75. }
  76. }
  77. private string _Text_forgetpass = "";
  78. public string Text_forgetpass
  79. {
  80. get { return _Text_forgetpass; }
  81. set
  82. {
  83. SetProperty(ref _Text_forgetpass, value);
  84. }
  85. }
  86. private void InitString()
  87. {
  88. Text_login = App.ServiceLoader.GetString("Text_login");
  89. Text_chmail = App.ServiceLoader.GetString("Text_chmail");
  90. Text_enterpass = App.ServiceLoader.GetString("RegisterPasswordMsg");
  91. Text_forgetpass = App.ServiceLoader.GetString("Text_forgetpass");
  92. LoginPasswordMsg0 = App.ServiceLoader.GetString("LoginPasswordMsg0");
  93. }
  94. #endregion
  95. private bool enableNextStep = false;
  96. public bool EnableNextStep
  97. {
  98. get { return enableNextStep; }
  99. set { SetProperty(ref enableNextStep, value); }
  100. }
  101. private string _LoginEmail = "";
  102. public string LoginEmail
  103. {
  104. get { return _LoginEmail; }
  105. set
  106. {
  107. SetProperty(ref _LoginEmail, value);
  108. }
  109. }
  110. private string _LoginPasswordlook;
  111. public string LoginPasswordlook
  112. {
  113. get { return _LoginPasswordlook; }
  114. set { SetProperty(ref _LoginPasswordlook, value); }
  115. }
  116. private string _LoginPassword = "";
  117. public string LoginPassword
  118. {
  119. get { return _LoginPassword; }
  120. set
  121. {
  122. SetProperty(ref _LoginPassword, value);
  123. LoginPasswordmsglook = "";
  124. LoginPasswordlookVis = Visibility.Collapsed;
  125. if (string.IsNullOrEmpty(LoginPassword))
  126. {
  127. ChkVis = Visibility.Collapsed;
  128. }
  129. else
  130. {
  131. ChkVis = Visibility.Visible;
  132. }
  133. CheckEnableNextStepEncrypt();
  134. }
  135. }
  136. private string _LoginPasswordmsglook = "";
  137. public string LoginPasswordmsglook
  138. {
  139. get { return _LoginPasswordmsglook; }
  140. set
  141. {
  142. SetProperty(ref _LoginPasswordmsglook, value);
  143. }
  144. }
  145. private Visibility _LoginPasswordVisibility = Visibility.Visible;
  146. public Visibility LoginPasswordVisibility
  147. {
  148. get { return _LoginPasswordVisibility; }
  149. set
  150. {
  151. if (value == Visibility.Visible)
  152. {
  153. LoginTextVisibility = Visibility.Collapsed;
  154. }
  155. else
  156. {
  157. LoginTextVisibility = Visibility.Visible;
  158. }
  159. SetProperty(ref _LoginPasswordVisibility, value);
  160. }
  161. }
  162. private Visibility _ChkVis = Visibility.Collapsed;
  163. public Visibility ChkVis
  164. {
  165. get { return _ChkVis; }
  166. set { SetProperty(ref _ChkVis, value); }
  167. }
  168. private Visibility _LoginTextVisibility = Visibility.Collapsed;
  169. public Visibility LoginTextVisibility
  170. {
  171. get { return _LoginTextVisibility; }
  172. set { SetProperty(ref _LoginTextVisibility, value); }
  173. }
  174. private Visibility _LoginPasswordlookVis = Visibility.Collapsed;
  175. public Visibility LoginPasswordlookVis
  176. {
  177. get { return _LoginPasswordlookVis; }
  178. set { SetProperty(ref _LoginPasswordlookVis, value); }
  179. }
  180. public DelegateCommand<object> DisplayPasswordCommand { get; set; }
  181. public DelegateCommand ChangeEmailCommand { get; set; }
  182. public DelegateCommand GoCodeUpdataCommand { get; set; }
  183. public DelegateCommand LoginCommand { get; set; }
  184. public DelegateCommand LinkLicenseCommand { get; set; }
  185. public DelegateCommand LoginPasswordChangedCommand { get; set; }
  186. LoginPasswordRegionViewModel(IRegionManager regionManager, IDialogService dialogService)
  187. {
  188. dialogs = dialogService;
  189. InitString();
  190. DisplayPasswordCommand = new DelegateCommand<object>(DisplayPassword);
  191. LoginCommand = new DelegateCommand(Login);
  192. ChangeEmailCommand = new DelegateCommand(ChangeEmail);
  193. GoCodeUpdataCommand = new DelegateCommand(GoCodeUpdata);
  194. LoginPasswordChangedCommand = new DelegateCommand(LoginPasswordChanged);
  195. }
  196. //密码改变
  197. private void LoginPasswordChanged()
  198. {
  199. if (LoginPassword.Length < 6)
  200. {
  201. LoginPasswordlook = "At least 6 characters";
  202. }
  203. else if (LoginPassword.Length > 24)
  204. {
  205. LoginPasswordlook = "Up to 24 characters";
  206. }
  207. else
  208. {
  209. LoginPasswordlook = "";
  210. }
  211. }
  212. //获取忘记密码验证码
  213. private void GoCodeUpdata()
  214. {
  215. ServiceHelper.Get_code("user_reset_password", LoginEmail);
  216. LoginDialogViewModel.IsReset = true;
  217. LoginDialogViewModel.RegionMan("CodeRegion");
  218. }
  219. //登录
  220. private void Login()
  221. {
  222. if (ServiceHelper.Login(LoginEmail, LoginPassword, uuid) == "success")
  223. {
  224. LoginDialogViewModel.Close();
  225. App.mainWindowViewModel.UserVis = Visibility.Visible;
  226. App.mainWindowViewModel.RegisterVis = Visibility.Collapsed;
  227. App.mainWindowViewModel.LoginVis = Visibility.Collapsed;
  228. App.mainWindowViewModel.OphVis = Visibility.Collapsed;
  229. Settings.Default.UserDate.Email = LoginEmail;
  230. }
  231. else if(ServiceHelper.Login(LoginEmail, LoginPassword, uuid) == "300")
  232. {
  233. LoginDialogViewModel.RegionMan("NOInternetRegion");
  234. }
  235. else
  236. {
  237. LoginPasswordmsglook = ErrorCodeHelper.Ercode(ServiceHelper.Login(LoginEmail, LoginPassword, uuid));
  238. LoginPasswordlookVis = Visibility.Visible;
  239. }
  240. }
  241. private void ChangeEmail()
  242. {
  243. LoginDialogViewModel.RegionMan("LoginRegion");
  244. }
  245. private void CheckEnableNextStepEncrypt()
  246. {
  247. EnableNextStep = true;
  248. if (LoginPassword.Length < 6 || LoginPassword.Length > 24 )
  249. {
  250. EnableNextStep = false;
  251. }
  252. }
  253. public void DisplayPassword(object e)
  254. {
  255. var chk = e as CheckBox;
  256. if (chk != null)
  257. {
  258. if (chk.IsChecked == true)
  259. {
  260. LoginPasswordVisibility = Visibility.Collapsed;
  261. }
  262. else
  263. {
  264. LoginPasswordVisibility = Visibility.Visible;
  265. }
  266. }
  267. }
  268. }
  269. }