I'm new to using Xamarin.Forms, I'm currently working on creating a sign up page. I'm trying to create some way to check if an email is already been used when creating an account. I am using firebase realtime database. I manage to get the application to check if the email has been used and display an error, but when the email is valid(not used), when I go to create the account the application doesn't do anything. What am I missing?
I have provided the code
public Command SignUpCommand
{
get
{
return new Command(() =>
{
var hasSymbols = new Regex(@"[!@#$%^&*()_+=\[{\]};:<>|./?,-]");
//null or empty field validation, check weather email and password is null or empty
if (string.IsNullOrEmpty(Email) || string.IsNullOrEmpty(Password))
{
App.Current.MainPage.DisplayAlert("Empty Values", "Please enter Email and Password", "OK");
}
else if (!Email.Contains("@"))
{
App.Current.MainPage.DisplayAlert("", "Email Address is Invalid", "OK");
}
else if (Password.Length < 8)
{
App.Current.MainPage.DisplayAlert("", "Password is less than 8 characters", "OK");
}
else if (!Password.Any(char.IsUpper))
{
App.Current.MainPage.DisplayAlert("", "Password Must Contain at Least 1 Uppcase Letter", "OK");
}
else if (!hasSymbols.IsMatch(Password))
{
App.Current.MainPage.DisplayAlert("", "Password should contain At least one special case characters", "OK");
}
else if (Password != ConfirmPassword)
{
App.Current.MainPage.DisplayAlert("", "Password must be same as above!", "OK");
}
else if (string.IsNullOrEmpty(StudentID))
{
App.Current.MainPage.DisplayAlert("Empty Values", "Please enter Student ID", "OK");
}
else if (StudentID.Length < 9)
{
App.Current.MainPage.DisplayAlert("", "Student ID is Incorrect!", "OK");
}
else
{
EmailCheck();
}
});
}
}
private async void EmailCheck()
{
//call GetUser function which we define in Firebase helper class
var user = await FirebaseHelper.GetUser(Email);
//firebase return null valuse if user data not found in database
if (user != null)
if (Email == user.Email)
{
await App.Current.MainPage.DisplayAlert("Email Already Used", "", "Ok");
}
else
SignUp();
}
private async void SignUp()
{
//call AddUser function which we define in Firebase helper class
var user = await FirebaseHelper.AddUser(Email, Password, StudentID, FirstName, LastName, CarMake, CarModel,
CarYear, CarColor, LicenseNumber);
//AddUser return true if data insert successfuly
if (user)
{
await App.Current.MainPage.DisplayAlert("SignUp Success", "", "Ok");
//Navigate to Wellcom page after successfuly SignUp
//pass user email to welcom page
await App.Current.MainPage.Navigation.PushAsync(new LoginPage());
}
else
await App.Current.MainPage.DisplayAlert("Error", "SignUp Fail", "OK");
}
}
}
