using PDF_Master.CustomControl; using PDF_Master.Helper; using PDF_Master.Model; using PDF_Master.Properties; using PDF_Master.Views.Dialog.ServiceDialog; using Prism.Commands; using Prism.Mvvm; using Prism.Regions; using Prism.Services.Dialogs; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Navigation; namespace PDF_Master.ViewModels.Dialog.ServiceDialog { public class LoginRegionViewModel : BindableBase, INavigationAware { private LoginDialogViewModel LoginDialogViewModel; private ErrorCodeHelper ErrorCodeHelper = new ErrorCodeHelper(); public IDialogService dialogs; public bool IsNavigationTarget(NavigationContext navigationContext) { return true; } public void OnNavigatedFrom(NavigationContext navigationContext) { } public void OnNavigatedTo(NavigationContext navigationContext) { navigationContext.Parameters.TryGetValue("LoginDialogViewModel", out LoginDialogViewModel); } #region 文案 private string _Text_Login = ""; public string Text_Login { get { return _Text_Login; } set { SetProperty(ref _Text_Login, value); } } private string _Text_emailac = ""; public string Text_emailac { get { return _Text_emailac; } set { SetProperty(ref _Text_emailac, value); } } private string _Text_next = ""; public string Text_next { get { return _Text_next; } set { SetProperty(ref _Text_next, value); } } private string _Text_noacc = ""; public string Text_noacc { get { return _Text_noacc; } set { SetProperty(ref _Text_noacc, value); } } private string _Text_toregister = ""; public string Text_toregister { get { return _Text_toregister; } set { SetProperty(ref _Text_toregister, value); } } private string _LoginEmailMsg = ""; public string LoginEmailMsg { get { return _LoginEmailMsg; } set { SetProperty(ref _LoginEmailMsg, value); } } private string _Mailerr = ""; public string Mailerr { get { return _Mailerr; } set { SetProperty(ref _Mailerr, value); } } private string _Text_remsg = ""; public string Text_remsg { get { return _Text_remsg; } set { SetProperty(ref _Text_remsg, value); } } private string _Text_privary = ""; public string Text_privary { get { return _Text_privary; } set { SetProperty(ref _Text_privary, value); } } private string _Text_and = ""; public string Text_and { get { return _Text_and; } set { SetProperty(ref _Text_and, value); } } private string _Text_licens = ""; public string Text_licens { get { return _Text_licens; } set { SetProperty(ref _Text_licens, value); } } private void InitString() { Text_Login = App.ServiceLoader.GetString("Text_Login"); Text_emailac = App.ServiceLoader.GetString("Text_emailac"); Text_next = App.ServiceLoader.GetString("RegisterNextStep"); Text_noacc = App.ServiceLoader.GetString("Text_noacc"); Text_toregister = App.ServiceLoader.GetString("Text_Signup"); Mailerr = App.ServiceLoader.GetString("Mailerr"); LoginEmailMsg = App.ServiceLoader.GetString("RegisterEmailMsg"); Text_remsg = App.ServiceLoader.GetString("Text_remsg"); Text_privary = App.ServiceLoader.GetString("Text_privary"); Text_and = App.ServiceLoader.GetString("Text_and"); Text_licens = App.ServiceLoader.GetString("Text_licens"); } #endregion private bool enableNextStep = false; public bool EnableNextStep { get { return enableNextStep; } set { SetProperty(ref enableNextStep, value); } } private string _LoginEmaillook=""; public string LoginEmaillook { get { return _LoginEmaillook; } set { SetProperty(ref _LoginEmaillook, value);} } private string _LoginEmail = Settings.Default.UserDate.Email; public string LoginEmail { get { return _LoginEmail; } set { SetProperty(ref _LoginEmail, value); LoginEmaillook = ""; //if (LoginEmail == "") //{ // LoginEmaillook = ""; //} //else //{ // CheckMail(LoginEmail); //} CheckEnableNextStepEncrypt(); } } private string _uriPolivy = "https://www.pdfreaderpro.com/privacy-policy"; public string UriPolivy { get { return _uriPolivy; } set { SetProperty(ref _uriPolivy, value); } } private string _uriLicense = "https://www.pdfreaderpro.com/terms_of_service"; public string UriLicense { get { return _uriLicense; } set { SetProperty(ref _uriLicense, value); } } public DelegateCommand LoginNextCommand { get; set; } public DelegateCommand GoLoginCommand { get; set; } public DelegateCommand LinkPolicyCommand { get; set; } public DelegateCommand LinkLicenseCommand { get; set; } LoginRegionViewModel(IRegionManager regionManager, IDialogService dialogService) { dialogs = dialogService; LinkPolicyCommand = new DelegateCommand(LinkPolicy); LinkLicenseCommand = new DelegateCommand(LinkLicense); LoginNextCommand = new DelegateCommand(LoginNext); GoLoginCommand = new DelegateCommand(GoLogin); InitString(); CheckEnableNextStepEncrypt(); } private void LoginNext() { if(CheckMail(LoginEmail)==true) { string code = ServiceHelper.Ok_email(LoginEmail, "1"); if (code == "200") { LoginDialogViewModel.LoginEmail = LoginEmail; LoginDialogViewModel.RegionMan("LoginPasswordRegion"); } else if (code == "318") { dialogs.ShowDialog(DialogNames.UserOutingLogin, new DialogParameters(""), r => { }); } else { LoginEmaillook = ErrorCodeHelper.Ercode(code); } } } private void LinkPolicy() { Process.Start(new ProcessStartInfo(UriPolivy)); } private void LinkLicense() { Process.Start(new ProcessStartInfo(UriLicense)); } private bool CheckMail(string mail) { string str = "^([a-z0-9_\\.-]+)@([\\da-z\\.-]+)\\.([a-z\\.]{2,6})$"; Regex mReg = new Regex(str); if (mReg.IsMatch(mail)) { LoginEmaillook = ""; return true; } else { LoginEmaillook = Mailerr; return false; } } private void GoLogin() { LoginDialogViewModel.Close(); Settings.Default.UserDate.TodayRegister = true; DateTime currentTime = DateTime.Now; Settings.Default.UserDate.TodayRegisterTime = currentTime.ToString(); //此处异步处理,减少等待时间 DefaultSave(); App.mainWindowViewModel.OpenRegister(); } private async void DefaultSave() { await Task.Run(() => { Settings.Default.Save(); }); } private void CheckEnableNextStepEncrypt() { EnableNextStep = true; if (string.IsNullOrEmpty(LoginEmail) || LoginEmaillook != "") { EnableNextStep = false; } } } }