private async void BtnRegister_Click(object sender, RoutedEventArgs e)
{
if(!CheckBoxPrivacyPolicy.IsChecked == true)
return;
var email = TextBoxRegisterEmail.Text;
if(string.IsNullOrEmpty(email) || !Regex.IsMatch(email, @".*@.*\..*"))
{
DisplayLoginError("Please enter an valid email address");
return;
}
if(string.IsNullOrEmpty(TextBoxRegisterPassword.Password))
{
DisplayLoginError("Please enter a password");
return;
}
if(TextBoxRegisterPassword.Password.Length < 6)
{
DisplayLoginError("Your password needs to be at least 6 characters");
return;
}
if(string.IsNullOrEmpty(TextBoxRegisterPasswordConfirm.Password))
{
DisplayLoginError("Please confirm your password");
return;
}
if(!TextBoxRegisterPassword.Password.Equals(TextBoxRegisterPasswordConfirm.Password))
{
DisplayLoginError("Entered passwords do not match");
return;
}
IsEnabled = false;
_controller = await this.ShowProgressAsync("Registering account...", "");
var result = await HearthStatsAPI.RegisterAsync(email, TextBoxRegisterPassword.Password);
if(result.Success)
{
_controller.SetTitle("Logging in...");
result = await HearthStatsAPI.LoginAsync(email, TextBoxRegisterPassword.Password);
}
else if(result.Message.Contains("422"))
DisplayLoginError("Email already registered");
else
DisplayLoginError(result.Message);
TextBoxRegisterPassword.Clear();
TextBoxRegisterPasswordConfirm.Clear();
if(result.Success)
{
var mw = new MainWindow();
mw.Show();
Close();
}
}