Beispiel #1
0
        private async void ToCustomer(object parameter)
        {
            var passwordBox = parameter as PasswordBox;
            var password = passwordBox.Password;
            Password = password;
            ValidateRegistry();
            if (validationErrors.Count == 0)
            {
                //using (MobilekEntities entities = new MobilekEntities())
                {
                    var hash = SecurePasswordHasher.Hash(password);
                    CustomerDTO customer = new CustomerDTO()
                    {
                        firstName = FirstName,
                        lastName = Surname,
                        creditCardNumber = CreditCardNr,
                        pesel = Pesel,
                        phoneNumber = PhoneNr,
                        userName = UserName,
                        password = hash,
                        email = Email
                    };
                    //entities.Customers.Add(customer);
                    //entities.SaveChanges();
                    var service = new Mobilek.Services.CustomerDTOService("", "");
                    await service.Post(customer);
                }
                RegistrationSuccessful = "User name: " + UserName + " was successfully added";
                FirstName = ""; Surname = ""; Email = ""; PhoneNr = ""; Pesel = ""; CreditCardNr = "";
                Password = ""; RepeatPassword = ""; UserName = ""; Login_Password = ""; Login_UserName = "";
                var msg = new ChangePageHelper() { PageName = new UserLoginViewModel() };
                Messenger.Default.Send<ChangePageHelper>(msg);
            }

        }
Beispiel #2
0
        public void ValidateRegistry()
        {
            service = new CustomerDTOService(Login_UserName, Login_Password);
            validationErrors.Clear();
            if (String.IsNullOrWhiteSpace(FirstName))
            {
                validationErrors.Add("FirstName", "First name is required!");
            }
            if (String.IsNullOrWhiteSpace(Surname))
            {
                validationErrors.Add("Surname", "Surname is required!");
            }
            if (String.IsNullOrEmpty(Pesel))
            {
                validationErrors.Add("Pesel", "Pesel is required!");
            }
            else if (Regex.IsMatch(Pesel, @"^\d+$") == false)
                validationErrors.Add("Pesel", "Only digits are allowed in Pesel field.");
            else if (Pesel.Length != 11)
                validationErrors.Add("Pesel", "Wrong Pesel Number!");
            if (String.IsNullOrEmpty(UserName))
            {
                validationErrors.Add("UserName", "User name is required!");
            }
            else
            {
                //var service = new Mobilek.Services.CustomerDTOService();
                //var users = Task.Run(() =>  service.Get()).Result;
                //var user = users.FirstOrDefault(x => x.userName == UserName);
                try
                {
                    var user = Task.Run(() => service.Get(Login_UserName)).Result;
                    if (user != null)
                    {
                        validationErrors.Add("UserName", "User name is not available. Please choose different one");
                    }
                }
                catch
                {

                }

            }
            if (String.IsNullOrEmpty(PhoneNr))
            {
                validationErrors.Add("PhoneNr", "Phone is required!");
            }
            else if (Regex.IsMatch(PhoneNr, @"^\d+$") == false)
                validationErrors.Add("PhoneNr", "Only digits are allowed in Phone Number field.");
            if (String.IsNullOrEmpty(Email))
            {
                validationErrors.Add("Email", "Email is required!");
            }
            else if (Regex.IsMatch(Email, @"^[A-Za-z0-9_\-\.]+@(([A-Za-z0-9\-])+\.)+([A-Za-z\-])+$") == false)
            {
                validationErrors.Add("Email", "Please enter valid e-mail adress.");
            }
            else
            {
                //var service = new Mobilek.Services.CustomerDTOService();
                //     var users = Task.Run(() => service.Get()).Result;
                //   var user = users.FirstOrDefault(x => x.email == Email);
                try
                {
                    var user = Task.Run(() => service.Get(Login_UserName)).Result;
                    if (user != null)
                    {
                        validationErrors.Add("Email", "This email address has already an account");
                    }
                }
                catch
                {

                }
            }
            if (String.IsNullOrEmpty(Password))
            {
                if (!validationErrors.ContainsKey("UserName"))
                {
                    validationErrors.Add("UserName", "Password is required!");
                }

            }
            else if (Password.Length < 8)
            {
                if (!validationErrors.ContainsKey("UserName"))
                {
                    validationErrors.Add("UserName", "Password must have at least 8 characters");
                }
            }
            OnPropertyChanged(null);
        }
Beispiel #3
0
        private async void ToAccount(object parameter)
        {
            var passwordBox = parameter as PasswordBox;
            var password = passwordBox.Password;
            Login_Password = password;
            ValidateLogin();
            if (validationErrors.Count == 0)
            {
                CustomerDTO customer = new CustomerDTO();
                var service = new Mobilek.Services.CustomerDTOService(Login_UserName, Login_Password);
                var users = await service.Get();
                customer = users.FirstOrDefault(x => x.userName == Login_UserName);

                var msg = new ChangePageHelper() { PageName = new UserPanelViewModel(customer) };
                Messenger.Default.Send<ChangePageHelper>(msg);

            }
            //var msg2 = new ChangePanelHelper() { panelType = PanelType.User };
            //Messenger.Default.Send<ChangePanelHelper>(msg2); 
        }
Beispiel #4
0
 public void ValidateLogin()
 {
     service = new CustomerDTOService(Login_UserName, Login_Password);
     validationErrors.Clear();
     try
     {
         if (String.IsNullOrWhiteSpace(Login_UserName))
         {
             validationErrors.Add("Login_UserName", "Please enter your user name");
         }
         {
             //    var service = new Mobilek.Services.CustomerDTOService();
             //    var users = Task.Run(() => service.Get()).Result;
             //    var user = users.FirstOrDefault(x => x.userName == Login_UserName);
             var user = Task.Run(() => service.Get(Login_UserName)).Result;
             if (user == null)
             {
                 if (!validationErrors.ContainsKey("Login_UserName"))
                 {
                     validationErrors.Add("Login_UserName", "User not found");
                 }
             }
         }
         {
             //var service = new Mobilek.Services.CustomerDTOService();
             //var users = Task.Run(()=> service.Get()).Result;
             //var user = users.FirstOrDefault(x => x.userName == Login_UserName);
             var user = Task.Run(() => service.Get(Login_UserName)).Result;
             if (user == null)
             {
                 if (!validationErrors.ContainsKey("Login_UserName"))
                 {
                     validationErrors.Add("Login_UserName", "User not found");
                 }
             }
             else
             {
                 var result = SecurePasswordHasher.Verify(Login_Password, user.password);
                 if (!result)
                 {
                     if (!validationErrors.ContainsKey("Login_UserName"))
                     {
                         validationErrors.Add("Login_UserName", "Incorrect password");
                     }
                 }
             }
         }
     }
     catch
     {
         validationErrors.Add("Login_UserName", "User not found");
     }
     OnPropertyChanged(null);
 }