LoginRegionViewModel.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. using PDF_Master.CustomControl;
  2. using PDF_Master.Helper;
  3. using PDF_Master.Model;
  4. using PDF_Master.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.Text.RegularExpressions;
  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 LoginRegionViewModel : BindableBase, INavigationAware
  23. {
  24. private LoginDialogViewModel LoginDialogViewModel;
  25. private ErrorCodeHelper ErrorCodeHelper = new ErrorCodeHelper();
  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. }
  38. #region 文案
  39. private string _Text_Login = "";
  40. public string Text_Login
  41. {
  42. get { return _Text_Login; }
  43. set
  44. {
  45. SetProperty(ref _Text_Login, value);
  46. }
  47. }
  48. private string _Text_emailac = "";
  49. public string Text_emailac
  50. {
  51. get { return _Text_emailac; }
  52. set
  53. {
  54. SetProperty(ref _Text_emailac, value);
  55. }
  56. }
  57. private string _Text_next = "";
  58. public string Text_next
  59. {
  60. get { return _Text_next; }
  61. set
  62. {
  63. SetProperty(ref _Text_next, value);
  64. }
  65. }
  66. private string _Text_noacc = "";
  67. public string Text_noacc
  68. {
  69. get { return _Text_noacc; }
  70. set
  71. {
  72. SetProperty(ref _Text_noacc, value);
  73. }
  74. }
  75. private string _Text_toregister = "";
  76. public string Text_toregister
  77. {
  78. get { return _Text_toregister; }
  79. set
  80. {
  81. SetProperty(ref _Text_toregister, value);
  82. }
  83. }
  84. private string _LoginEmailMsg = "";
  85. public string LoginEmailMsg
  86. {
  87. get { return _LoginEmailMsg; }
  88. set
  89. {
  90. SetProperty(ref _LoginEmailMsg, value);
  91. }
  92. }
  93. private string _Mailerr = "";
  94. public string Mailerr
  95. {
  96. get { return _Mailerr; }
  97. set
  98. {
  99. SetProperty(ref _Mailerr, value);
  100. }
  101. }
  102. private string _Text_remsg = "";
  103. public string Text_remsg
  104. {
  105. get { return _Text_remsg; }
  106. set
  107. {
  108. SetProperty(ref _Text_remsg, value);
  109. }
  110. }
  111. private string _Text_privary = "";
  112. public string Text_privary
  113. {
  114. get { return _Text_privary; }
  115. set
  116. {
  117. SetProperty(ref _Text_privary, value);
  118. }
  119. }
  120. private string _Text_and = "";
  121. public string Text_and
  122. {
  123. get { return _Text_and; }
  124. set
  125. {
  126. SetProperty(ref _Text_and, value);
  127. }
  128. }
  129. private string _Text_licens = "";
  130. public string Text_licens
  131. {
  132. get { return _Text_licens; }
  133. set
  134. {
  135. SetProperty(ref _Text_licens, value);
  136. }
  137. }
  138. private void InitString()
  139. {
  140. Text_Login = App.ServiceLoader.GetString("Text_Login");
  141. Text_emailac = App.ServiceLoader.GetString("Text_emailac");
  142. Text_next = App.ServiceLoader.GetString("RegisterNextStep");
  143. Text_noacc = App.ServiceLoader.GetString("Text_noacc");
  144. Text_toregister = App.ServiceLoader.GetString("Text_Signup");
  145. Mailerr = App.ServiceLoader.GetString("Mailerr");
  146. LoginEmailMsg = App.ServiceLoader.GetString("RegisterEmailMsg");
  147. Text_remsg = App.ServiceLoader.GetString("Text_remsg");
  148. Text_privary = App.ServiceLoader.GetString("Text_privary");
  149. Text_and = App.ServiceLoader.GetString("Text_and");
  150. Text_licens = App.ServiceLoader.GetString("Text_licens");
  151. }
  152. #endregion
  153. private bool enableNextStep = false;
  154. public bool EnableNextStep
  155. {
  156. get { return enableNextStep; }
  157. set { SetProperty(ref enableNextStep, value); }
  158. }
  159. private string _LoginEmaillook;
  160. public string LoginEmaillook
  161. {
  162. get { return _LoginEmaillook; }
  163. set { SetProperty(ref _LoginEmaillook, value);}
  164. }
  165. private string _LoginEmail = "";
  166. public string LoginEmail
  167. {
  168. get { return _LoginEmail; }
  169. set
  170. {
  171. SetProperty(ref _LoginEmail, value);
  172. LoginEmaillook = "";
  173. //if (LoginEmail == "")
  174. //{
  175. // LoginEmaillook = "";
  176. //}
  177. //else
  178. //{
  179. // CheckMail(LoginEmail);
  180. //}
  181. CheckEnableNextStepEncrypt();
  182. }
  183. }
  184. public DelegateCommand LoginNextCommand { get; set; }
  185. public DelegateCommand GoLoginCommand { get; set; }
  186. LoginRegionViewModel(IRegionManager regionManager, IDialogService dialogService)
  187. {
  188. dialogs = dialogService;
  189. LoginNextCommand = new DelegateCommand(LoginNext);
  190. GoLoginCommand = new DelegateCommand(GoLogin);
  191. InitString();
  192. }
  193. private void LoginNext()
  194. {
  195. if(CheckMail(LoginEmail)==true)
  196. {
  197. string code = ServiceHelper.Ok_email(LoginEmail, "1");
  198. if (code == "200")
  199. {
  200. LoginDialogViewModel.LoginEmail = LoginEmail;
  201. LoginDialogViewModel.RegionMan("LoginPasswordRegion");
  202. }
  203. else if (code == "318")
  204. {
  205. dialogs.ShowDialog(DialogNames.UserOutingLogin, new DialogParameters(""), r =>
  206. {
  207. });
  208. }
  209. else
  210. {
  211. LoginEmaillook = ErrorCodeHelper.Ercode(code);
  212. }
  213. }
  214. }
  215. private bool CheckMail(string mail)
  216. {
  217. string str = "^([a-z0-9_\\.-]+)@([\\da-z\\.-]+)\\.([a-z\\.]{2,6})$";
  218. Regex mReg = new Regex(str);
  219. if (mReg.IsMatch(mail))
  220. {
  221. LoginEmaillook = "";
  222. return true;
  223. }
  224. else
  225. {
  226. LoginEmaillook = Mailerr;
  227. return false;
  228. }
  229. }
  230. private void GoLogin()
  231. {
  232. LoginDialogViewModel.Close();
  233. App.mainWindowViewModel.OpenRegister();
  234. }
  235. private void CheckEnableNextStepEncrypt()
  236. {
  237. EnableNextStep = true;
  238. if (string.IsNullOrEmpty(LoginEmail) || LoginEmaillook != "")
  239. {
  240. EnableNextStep = false;
  241. }
  242. }
  243. }
  244. }