示例#1
0
        private async void UserToSubmit_OnClick(object sender, RoutedEventArgs e)
        {
            UserHasInputControl(false);

            var uapi = new UserApi("5940771a096a5bf6e36f530769a6ba2f");

            //todo REGEX
            if (string.IsNullOrWhiteSpace(UserEmail.Text) ||
                string.IsNullOrWhiteSpace(UserUsername.Text) ||
                string.IsNullOrWhiteSpace(UserPwd.Password) ||
                !(UserPwd.Password.Length > 3) ||
                !(UserUsername.Text.Length > 3) ||
                !(UserEmail.Text.Length > 6) ||
                !UserEmail.Text.Contains("@") ||
                !UserEmail.Text.Contains("."))
            {
                MessageBox.Show(
                    "One or more of he fields contains an invalid entry.\nPasswords must be between 3 and 20 alphanumeric characters",
                    ":(", MessageBoxButton.OK);
            }
            else
            {
                try
                {
                    var y = await uapi.ApiReg(UserPwd.Password, UserUsername.Text, UserEmail.Text, FilingCabinet.TownsList.Find(i => i.name == (UserTown.SelectedItem.ToString())).id);

                    if (y.success.Contains("Account created") || y.success.Contains("Account Created") || y.success.Contains("account created"))
                    {
                        MessageBox.Show("Registration successful. Account Created", ":)", MessageBoxButton.OK);

                        NavigationService.Navigate(new Uri("/Pages/UserLogin.xaml", UriKind.Relative));
                    }
                    else
                    {
                        MessageBox.Show("Registration unsuccessful.\nComputer says: " + y.success, ":(", MessageBoxButton.OK);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("We could not sign you up at this time, please check details and try again.", ":(",
                                    MessageBoxButton.OK);
                }
            }
            UserHasInputControl(true);
        }