Пример #1
0
 private void ExecuteSavePasswordCommand()
 {
     if (String.IsNullOrEmpty(Password))
     {
         ErrorMessage = "Password is required.";
     }
     else if (Password.Trim() != ConfirmPassword.Trim())
     {
         ErrorMessage = "Passwords do not match.";
     }
     else
     {
         using (var dp = SimpleIoc.Default.GetInstance <IUnitOfWorkFactory>().CreateUnitOfWork())
         {
             var repo    = dp.SettingsRepository;
             var setting = repo.FindSingle(k => k.Key == CottonDBMS.DataModels.TruckClientSettingKeys.ADMIN_PASSWORD);
             setting.Value = _password.Trim();
             repo.Update(setting);
             dp.SaveChanges();
         }
         PasswordModalVisible = false;
         SettingsLocked       = true;
         DialogOpen           = false;
     }
 }
Пример #2
0
        private void ExecuteSavePasswordCommand()
        {
            if (string.IsNullOrWhiteSpace(Password))
            {
                PasswordErrorMessage = "Password is required.";
            }
            else if (string.IsNullOrWhiteSpace(ConfirmPassword))
            {
                PasswordErrorMessage = "Confirm password is required";
            }
            else if (Password.Trim() != ConfirmPassword.Trim())
            {
                PasswordErrorMessage = "Passwords do not match.";
            }
            else
            {
                //error checking passed so we can save the lock code
                using (var dp = SimpleIoc.Default.GetInstance <IUnitOfWorkFactory>().CreateUnitOfWork())
                {
                    dp.SettingsRepository.UpsertSetting(TruckClientSettingKeys.ADMIN_PASSWORD, Password.Trim());
                    dp.SaveChanges();

                    _windowService.CloseModalWindow(WindowType.TruckSetupWindow);
                    GalaSoft.MvvmLight.Messaging.Messenger.Default.Send <FirstSetupWizardComplete>(new FirstSetupWizardComplete());
                }
            }
        }
Пример #3
0
        public void Validate()
        {
            if (!string.IsNullOrEmpty(NewPassword))
            {
                NewPassword = NewPassword.Trim();
            }

            if (string.IsNullOrEmpty(NewPassword))
            {
                LocalFunctions.AddError("Please enter new password", MethodBase.GetCurrentMethod(), false, false);
            }
            else
            {
                if (NewPassword.Length < 6)
                {
                    LocalFunctions.AddError("Password min lenght should be 6", MethodBase.GetCurrentMethod(), false, false);
                }

                if (NewPassword.Length > 30)
                {
                    LocalFunctions.AddError("Password max lenght is 30", MethodBase.GetCurrentMethod(), false, false);
                }
            }


            if (!string.IsNullOrEmpty(ConfirmPassword))
            {
                ConfirmPassword = ConfirmPassword.Trim();
            }

            if (string.IsNullOrEmpty(ConfirmPassword))
            {
                LocalFunctions.AddError("Please enter confirm password", MethodBase.GetCurrentMethod(), false, false);
            }
            else if (ConfirmPassword != NewPassword)
            {
                LocalFunctions.AddError("Confirm password is not same", MethodBase.GetCurrentMethod(), false, false);
            }


            if (!string.IsNullOrEmpty(EmailedCode))
            {
                EmailedCode = EmailedCode.Trim();
            }

            if (string.IsNullOrEmpty(EmailedCode))
            {
                LocalFunctions.AddError("Please enter emailed code", MethodBase.GetCurrentMethod(), false, false);
            }
            else
            {
                if (EmailedCode.Length != 10)
                {
                    LocalFunctions.AddError("Emailed code lenght should be 10", MethodBase.GetCurrentMethod(), false, false);
                }
            }
        }
 /// <summary>
 /// 用户注册
 /// </summary>
 private async void UserSignup()
 {
     if (UserName != null && UserPassword != null && ConfirmPassword != null && NickName != null && Age != null)
     {
         string userName        = UserName.Trim();
         string userPassword    = UserPassword.Trim();
         string confirmPassword = ConfirmPassword.Trim();
         string nickName        = NickName.Trim();
         int    age             = int.Parse(Age.Trim());
         string gender          = Gender == true ? "男" : "女";
         if (!userName.Equals(string.Empty) && !userPassword.Equals(string.Empty) && !confirmPassword.Equals(string.Empty) && !nickName.Equals(string.Empty))
         {
             if (userPassword.Length >= 6 && userPassword.Equals(confirmPassword))
             {
                 signupCanExecute = false;
                 miniClient       = new MiniClient(userName, Config.ClientAddressFamily, Config.ClientAgreement, Config.GetServerIPEndPoint());
                 miniClient.ClientRequestResult += MiniClient_ClientRequestResult;
                 miniClient.OpenClient();
                 if (await miniClient.ConnectionServerAsync())
                 {
                     User user = new User()
                     {
                         UserName = userName,
                         Password = ClientHelper.Encryption(userPassword),
                         NickName = nickName,
                         Gender   = gender,
                         Age      = age,
                         HeadIcon = ClientHelper.GetBytes(gender == "男" ? new Uri("/Resources/Images/boy.png", UriKind.Relative) : new Uri("/Resources/Images/girl.png", UriKind.Relative))
                     };
                     if (miniClient.SendDatabaseRequest(user, "Signup", null))
                     {
                         if (!await ClientHelper.WaitAsync(() => signupCanExecute, 20))
                         {
                             signupCanExecute = true;
                             miniClient?.CloseClient();
                             miniClient = null;
                             MessageBox.Show("服务器连接超时!", Config.Name, MessageBoxButton.OK, MessageBoxImage.Error);
                         }
                         return;
                     }
                 }
                 signupCanExecute = true;
                 miniClient?.CloseClient();
                 miniClient = null;
                 MessageBox.Show("无法连接到服务器!", Config.Name, MessageBoxButton.OK, MessageBoxImage.Error);
                 return;
             }
             MessageBox.Show("密码不符合要求!", Config.Name, MessageBoxButton.OK, MessageBoxImage.Warning);
             return;
         }
     }
     MessageBox.Show("用户信息不能为空!", Config.Name, MessageBoxButton.OK, MessageBoxImage.Warning);
 }
        public void Validate()
        {
            if (!string.IsNullOrEmpty(ConfirmPassword))
            {
                ConfirmPassword = ConfirmPassword.Trim();
            }

            if (string.IsNullOrEmpty(ConfirmPassword))
            {
                LocalFunctions.AddError("Please enter confirm password", MethodBase.GetCurrentMethod(), false, false);
            }
            else if (ConfirmPassword != tsUser.Password)
            {
                LocalFunctions.AddError("Confirm password is not same", MethodBase.GetCurrentMethod(), false, false);
            }
        }
Пример #6
0
        /// <summary>
        /// Invoked when the Sign Up button is clicked.
        /// </summary>
        /// <param name="obj">The Object</param>
        private async void SignUpClicked(object obj)
        {
            // Do something

            // Register user..1

            Email           = Email.Trim();
            Password        = Password.Trim();
            ConfirmPassword = ConfirmPassword.Trim();

            var resmgr = new ResourceManager("DigiFyy.Resources.AppResources", typeof(TranslateExtension).GetTypeInfo().Assembly);
            var ci     = CrossMultilingual.Current.CurrentCultureInfo;



            string uuid = Preferences.Get("UUID", "");

            if (string.IsNullOrEmpty(Email))
            {
                IsInvalidEmail = true;
                return;
            }

            if (Password.Length < 8)
            {
                PasswordError = resmgr.GetString("PasswordTooShort", ci); // "Password too short (8 chars min)";
                WrongPassword = true;
                return;
            }

            if (ConfirmPassword != Password)
            {
                PasswordError = resmgr.GetString("PasswordMismatch", ci);
                WrongPassword = true;
                return;
            }


            IsBusy = true;
            Owner owner = new Owner()
            {
                Email = Email, Name = "anonymous", OwnerID = 0
            };
            UniqueID uniqueID = new UniqueID()
            {
                Username = Email, Name = Email, Password = Password, UID = uuid, Owner = owner
            };

            // Step 1 - register new user

            var result1 = await DataStore.RegisterUUID(uniqueID);

            int registerStatus = result1.Item2;

            if (registerStatus == (int)OwnerRegisterErrorType.UIDDoesNotExist)
            {
                await DialogService.Show("Error registering", "The UUID does not exist", "Ok");
            }
            else if (registerStatus == (int)OwnerRegisterErrorType.UIDRegisterToOtherUser)
            {
                await DialogService.Show("Error registering", "The UUID is registered to another user", "Ok");
            }
            else if (registerStatus == (int)OwnerRegisterErrorType.UIDReportedStolen)
            {
                await DialogService.Show("Error registering", "The bike is reported stolen and cannot be registered", "Ok");
            }
            else
            {
                // Step 2: Login user to obtain token

                var result2 = await DataStore.LoginUser(Email, Password);

                if (result2.Token != "")
                {
                    Preferences.Set("Token", result2.Token);
                    Preferences.Set("Email", Email);
                    Preferences.Set("Password", Password);
                    Preferences.Set("IsLoggedIn", "1");
                    IsBusy = false;

                    if (result1.Item1.UID != "")
                    {
                        // Step 3 - Link user to owner to UUID

                        if (Preferences.Get("RegisteredToBike", "0") != "1")
                        {
                            int imageType = (int)ImageTypes.Invoice;
                            await NavigationService.NavigateToAsync <AddPictureViewModel>(imageType);
                        }
                        else
                        {
                            await NavigationService.NavigateToAsync <MainViewModel>(2);
                        }
                    }
                }
            }



            IsBusy = false;


            //  int imageType = (int)ImageTypes.Invoice;
            // await NavigationService.NavigateToAsync<AddPictureViewModel>(imageType);
        }