Ejemplo n.º 1
0
 private void butRegister_Click(object sender, RoutedEventArgs e)
 {
     //register
     if (txtRegEmail.Text.Length > 5 && txtRegEmail.Text.Contains('@') && txtRegEmail.Text.Contains(".") && !(txtRegEmail.Text.Contains(" ")) && !(txtRegEmail.Text.Contains("&")) && !(txtRegEmail.Text.Contains("="))) //must be longer than 5 characters due to the minimum characters in an email is 5, block out standard characters which may break upload
     {
         if (txtRegName.Text.Length > 3 && !(txtRegName.Text.Contains(" ")) && !(txtRegName.Text.Contains("&")) && !(txtRegName.Text.Contains("=")))                                                                     //have a suitable name > 3 characters
         {
             if (txtRegPass.Password == txtRegPassConfirm.Password && !(txtRegPass.Password.Contains(" ")) && !(txtRegPass.Password.Contains("&")) && !(txtRegPass.Password.Contains("=")))
             {
                 User u = new User();
                 u.email    = txtRegEmail.Text;
                 u.name     = txtRegName.Text;
                 u.password = txtRegPass.Password;
                 UploadData.CreateUser(u);
                 MessageBox.Show("User details sent!");
                 panRegister.Visibility = Visibility.Hidden;
                 panLogin.Visibility    = Visibility.Visible;
             }
             else
             {
                 MessageBox.Show("You have used invalid characters as your password" + Environment.NewLine + @"Account passwords are not allowed the characters ' ', '&', '='");
             }
         }
         else
         {
             MessageBox.Show("You have used invalid characters as your account name, or the name you entered is less than 4 characters in length" + Environment.NewLine + @"Account names are not allowed the characters ' ', '&', '='");
         }
     }
     else
     {
         MessageBox.Show("You have used invalid characters as your email, or have an invalid email address" + Environment.NewLine + @"Account email is not allowed the characters ' ', '&', '='");
     }
 }
Ejemplo n.º 2
0
        public void Thing(UserUpdateState us, User oldUser = null)
        {
            User u = new User();

            if (txtModuserEmail.Text.Length > 5)
            {
                if (txtModuserName.Text.Length > 3)
                {
                    u.email = txtModuserEmail.Text;
                    u.name  = txtModuserName.Text;

                    if (us == UserUpdateState.IgnorePassword)
                    {
                        if (oldUser != null)
                        {
                            UploadData.UpdateUser(oldUser.email, u, false);
                            MessageBox.Show("Process complete!");
                        }
                        else
                        {
                            MessageBox.Show("An error occured when retrieving your selected user");
                        }
                    }
                    else if (txtModuserPassword.Password.Length > 5 && txtModuserPassword.Password == txtModuserPasswordConfirm.Password)
                    {
                        u.password = txtModuserPassword.Password;

                        if (us == UserUpdateState.CreateNew)
                        {
                            UploadData.CreateUser(u);
                            MessageBox.Show("Process complete!");
                        }
                        else if (us == UserUpdateState.UpdateAll)
                        {
                            u.id = int.Parse(txtModuserID.Text);
                            if (oldUser != null)
                            {
                                UploadData.UpdateUser(oldUser.email, u, true);
                                MessageBox.Show("Process complete!");
                            }
                            else
                            {
                                MessageBox.Show("An error occured when retrieving your selected user");
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show(string.Format("Your passwords either do not match or are not longer than 5 characters"));
                    }

                    try
                    {
                        UploadData.UpdatePermissions(txtModuserEmail.Text, cboModuserRoles.SelectedIndex);//update the user's role
                    }
                    catch
                    {
                        MessageBox.Show("There was an error updating this user's permissions");
                    }
                    try
                    {
                        UploadData.AssignFarm(cboModuserfarmlist.SelectedIndex, oldUser.email);//update the farm assigned to this user
                    }
                    catch
                    {
                        MessageBox.Show("There was an error asigning a farm to this user");
                    }
                }
                else
                {
                    MessageBox.Show(string.Format("Your nickname is not longer than 3 characters"));
                }
            }
            else
            {
                MessageBox.Show(string.Format("Your email is not longer than 5 characters"));
            }
        }