LoginRegionViewModel.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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.Text.RegularExpressions;
  16. using System.Threading.Tasks;
  17. using System.Windows;
  18. using System.Windows.Controls;
  19. using System.Windows.Documents;
  20. using System.Windows.Navigation;
  21. namespace PDF_Master.ViewModels.Dialog.ServiceDialog
  22. {
  23. public class LoginRegionViewModel : BindableBase, INavigationAware
  24. {
  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. }
  39. #region 文案
  40. private string _Text_Login = "";
  41. public string Text_Login
  42. {
  43. get { return _Text_Login; }
  44. set
  45. {
  46. SetProperty(ref _Text_Login, value);
  47. }
  48. }
  49. private string _Text_emailac = "";
  50. public string Text_emailac
  51. {
  52. get { return _Text_emailac; }
  53. set
  54. {
  55. SetProperty(ref _Text_emailac, value);
  56. }
  57. }
  58. private string _Text_next = "";
  59. public string Text_next
  60. {
  61. get { return _Text_next; }
  62. set
  63. {
  64. SetProperty(ref _Text_next, value);
  65. }
  66. }
  67. private string _Text_noacc = "";
  68. public string Text_noacc
  69. {
  70. get { return _Text_noacc; }
  71. set
  72. {
  73. SetProperty(ref _Text_noacc, value);
  74. }
  75. }
  76. private string _Text_toregister = "";
  77. public string Text_toregister
  78. {
  79. get { return _Text_toregister; }
  80. set
  81. {
  82. SetProperty(ref _Text_toregister, value);
  83. }
  84. }
  85. private string _LoginEmailMsg = "";
  86. public string LoginEmailMsg
  87. {
  88. get { return _LoginEmailMsg; }
  89. set
  90. {
  91. SetProperty(ref _LoginEmailMsg, value);
  92. }
  93. }
  94. private string _Mailerr = "";
  95. public string Mailerr
  96. {
  97. get { return _Mailerr; }
  98. set
  99. {
  100. SetProperty(ref _Mailerr, value);
  101. }
  102. }
  103. private string _Text_remsg = "";
  104. public string Text_remsg
  105. {
  106. get { return _Text_remsg; }
  107. set
  108. {
  109. SetProperty(ref _Text_remsg, value);
  110. }
  111. }
  112. private string _Text_privary = "";
  113. public string Text_privary
  114. {
  115. get { return _Text_privary; }
  116. set
  117. {
  118. SetProperty(ref _Text_privary, value);
  119. }
  120. }
  121. private string _Text_and = "";
  122. public string Text_and
  123. {
  124. get { return _Text_and; }
  125. set
  126. {
  127. SetProperty(ref _Text_and, value);
  128. }
  129. }
  130. private string _Text_licens = "";
  131. public string Text_licens
  132. {
  133. get { return _Text_licens; }
  134. set
  135. {
  136. SetProperty(ref _Text_licens, value);
  137. }
  138. }
  139. private void InitString()
  140. {
  141. Text_Login = App.ServiceLoader.GetString("Text_Login");
  142. Text_emailac = App.ServiceLoader.GetString("Text_emailac");
  143. Text_next = App.ServiceLoader.GetString("RegisterNextStep");
  144. Text_noacc = App.ServiceLoader.GetString("Text_noacc");
  145. Text_toregister = App.ServiceLoader.GetString("Text_Signup");
  146. Mailerr = App.ServiceLoader.GetString("Mailerr");
  147. LoginEmailMsg = App.ServiceLoader.GetString("RegisterEmailMsg");
  148. Text_remsg = App.ServiceLoader.GetString("Text_remsg");
  149. Text_privary = App.ServiceLoader.GetString("Text_privary");
  150. Text_and = App.ServiceLoader.GetString("Text_and");
  151. Text_licens = App.ServiceLoader.GetString("Text_licens");
  152. }
  153. #endregion
  154. private bool enableNextStep = false;
  155. public bool EnableNextStep
  156. {
  157. get { return enableNextStep; }
  158. set { SetProperty(ref enableNextStep, value); }
  159. }
  160. private string _LoginEmaillook="";
  161. public string LoginEmaillook
  162. {
  163. get { return _LoginEmaillook; }
  164. set { SetProperty(ref _LoginEmaillook, value);}
  165. }
  166. private string _LoginEmail = Settings.Default.UserDate.Email;
  167. public string LoginEmail
  168. {
  169. get { return _LoginEmail; }
  170. set
  171. {
  172. SetProperty(ref _LoginEmail, value);
  173. LoginEmaillook = "";
  174. //if (LoginEmail == "")
  175. //{
  176. // LoginEmaillook = "";
  177. //}
  178. //else
  179. //{
  180. // CheckMail(LoginEmail);
  181. //}
  182. CheckEnableNextStepEncrypt();
  183. }
  184. }
  185. private string _uriPolivy = "https://www.pdfreaderpro.com/privacy-policy";
  186. public string UriPolivy
  187. {
  188. get { return _uriPolivy; }
  189. set
  190. {
  191. SetProperty(ref _uriPolivy, value);
  192. }
  193. }
  194. private string _uriLicense = "https://www.pdfreaderpro.com/terms_of_service";
  195. public string UriLicense
  196. {
  197. get { return _uriLicense; }
  198. set
  199. {
  200. SetProperty(ref _uriLicense, value);
  201. }
  202. }
  203. public DelegateCommand LoginNextCommand { get; set; }
  204. public DelegateCommand GoLoginCommand { get; set; }
  205. public DelegateCommand LinkPolicyCommand { get; set; }
  206. public DelegateCommand LinkLicenseCommand { get; set; }
  207. LoginRegionViewModel(IRegionManager regionManager, IDialogService dialogService)
  208. {
  209. dialogs = dialogService;
  210. LinkPolicyCommand = new DelegateCommand(LinkPolicy);
  211. LinkLicenseCommand = new DelegateCommand(LinkLicense);
  212. LoginNextCommand = new DelegateCommand(LoginNext);
  213. GoLoginCommand = new DelegateCommand(GoLogin);
  214. InitString();
  215. CheckEnableNextStepEncrypt();
  216. }
  217. private void LoginNext()
  218. {
  219. //去掉前后空格
  220. LoginEmail = LoginEmail.Trim();
  221. if (CheckMail(LoginEmail)==true)
  222. {
  223. string code = ServiceHelper.Ok_email(LoginEmail, "1");
  224. if (code == "200")
  225. {
  226. LoginDialogViewModel.LoginEmail = LoginEmail;
  227. LoginDialogViewModel.RegionMan("LoginPasswordRegion");
  228. }
  229. else if (code == "318")
  230. {
  231. dialogs.ShowDialog(DialogNames.UserOutingLogin, new DialogParameters(""), r =>
  232. {
  233. });
  234. }
  235. else
  236. {
  237. LoginEmaillook = ErrorCodeHelper.Ercode(code);
  238. }
  239. }
  240. }
  241. private void LinkPolicy()
  242. {
  243. Process.Start(new ProcessStartInfo(UriPolivy));
  244. }
  245. private void LinkLicense()
  246. {
  247. Process.Start(new ProcessStartInfo(UriLicense));
  248. }
  249. private bool CheckMail(string mail)
  250. {
  251. string str = "^([a-z0-9_\\.-]+)@([\\da-z\\.-]+)\\.([a-z\\.]{2,6})$";
  252. Regex mReg = new Regex(str);
  253. if (mReg.IsMatch(mail))
  254. {
  255. LoginEmaillook = "";
  256. return true;
  257. }
  258. else
  259. {
  260. LoginEmaillook = Mailerr;
  261. return false;
  262. }
  263. }
  264. private void GoLogin()
  265. {
  266. LoginDialogViewModel.Close();
  267. Settings.Default.UserDate.TodayRegister = true;
  268. DateTime currentTime = DateTime.Now;
  269. Settings.Default.UserDate.TodayRegisterTime = currentTime.ToString();
  270. //此处异步处理,减少等待时间
  271. DefaultSave();
  272. App.mainWindowViewModel.OpenRegister();
  273. }
  274. private async void DefaultSave()
  275. {
  276. await Task.Run(() => { Settings.Default.Save(); });
  277. }
  278. private void CheckEnableNextStepEncrypt()
  279. {
  280. EnableNextStep = true;
  281. if (string.IsNullOrEmpty(LoginEmail) || LoginEmaillook != "")
  282. {
  283. EnableNextStep = false;
  284. }
  285. }
  286. }
  287. }