//procedura di sign up async void Sign_up_btn_Clicked(object sender, EventArgs e) { MyUser user = new MyUser(); string username = Entry_Username.Text; string emailLowerCase = Entry_Email.Text; if (Entry_Email.Text != null) { emailLowerCase = Entry_Email.Text.ToLower(); } string pwd = Entry_Password.Text; bool isEmailOk = MailValidation(emailLowerCase); bool isPassConfOk = PasswordConfirmationValidation(user); bool isUsernameOk = UsernameValidation(username); bool isPassOk = PasswordValidation(pwd); bool isAgeOk = AgeValidation(); //bool test = true; //se tutti i campi sono rispettati la procedura ha successos if (isEmailOk && isPassConfOk && isUsernameOk && isPassOk && isAgeOk) { try { var authProvider = new FirebaseAuthProvider(new FirebaseConfig(AuthFirebase.Instance.GetKey())); //signup con email e password var auth = await authProvider.CreateUserWithEmailAndPasswordAsync(Entry_Email.Text, Entry_Password.Text); //invia email di verifica await authProvider.SendEmailVerificationAsync(auth); await authProvider.UpdateProfileAsync(auth.FirebaseToken, username, ""); Preferences.Set("UserEmailFirebase", emailLowerCase.Replace(".", "-").Replace("@", "-at-")); //alert await App.Current.MainPage.DisplayAlert("Success!", "Don't forget to verify your Email.", "Ok"); //aggiunto utente nel database var viewModel = (MyUserViewModel)BindingContext; if (viewModel.AddUserCommand.CanExecute(null)) { viewModel.AddUserCommand.Execute(null); } //navigazione alla pagina di login await Navigation.PushAsync(new LoginPage()); } catch (Exception ex) { Console.WriteLine(ex.Message); await App.Current.MainPage.DisplayAlert("Ops... Something went wrong.", "Try to Sign Up again.", "Ok"); } } }
public async Task <bool> SendVerificationEmailAsync(string token) { try { await FirebaseAuthProvider.SendEmailVerificationAsync ( token ); } catch (Firebase.Auth.FirebaseAuthException ex) { if (ex.InnerException?.InnerException?.GetType() == typeof(SocketException)) { throw new HttpRequestException("Cannot join the server. Please check your internet connexion."); } throw new UnauthorizedAccessException("Email or password is invalid !", ex); } catch (Exception ex) { throw ex; } return(false); }
//procedura per il login async void Sign_in_btn_Clicked(System.Object sender, System.EventArgs e) { if (Entry_Email.Text != null && Entry_Password.Text != null) { string emailLowerCase = Entry_Email.Text.ToLower(); FirebaseAuthProvider authProvider = new FirebaseAuthProvider(new FirebaseConfig(AuthFirebase.Instance.GetKey())); try { FirebaseAuthLink auth = await authProvider.SignInWithEmailAndPasswordAsync(Entry_Email.Text, Entry_Password.Text); FirebaseAuthLink content = await auth.LinkToAsync(Entry_Email.Text, Entry_Password.Text); string serializedcontnet = JsonConvert.SerializeObject(content); Preferences.Set("MyLoginToken", serializedcontnet); Preferences.Set("UserEmailFirebase", emailLowerCase.Replace(".", "-").Replace("@", "-at-")); await Navigation.PushAsync(new MasterDetail()); if (content.User.IsEmailVerified == false) { bool action = await App.Current.MainPage.DisplayAlert("Attention.", "Your account is not verified yet.\n Send verification email again?", "Yes", "No"); if (action) { await authProvider.SendEmailVerificationAsync(content.FirebaseToken); } } } catch (Exception ex) { Console.WriteLine(ex.Message); await App.Current.MainPage.DisplayAlert("Alert.", "Invalid email or password.", "Ok"); } } }
public void ResendVerificationEmail() { _authProvider.SendEmailVerificationAsync(AuthLink); }
public void ResendEmailVerification(string firebasetoken) { var y = authProvider.SendEmailVerificationAsync(firebasetoken); }