Exemple #1
0
        public async Task <bool> RegisterUser(string name, string email, string password)
        {
            try
            {
                await Firebase.Auth.FirebaseAuth.Instance.CreateUserWithEmailAndPasswordAsync(email, password);

                var profileUpdates = new Firebase.Auth.UserProfileChangeRequest.Builder();
                profileUpdates.SetDisplayName(name);
                var build = profileUpdates.Build();

                var user = Firebase.Auth.FirebaseAuth.Instance.CurrentUser;
                await user.UpdateProfileAsync(build);

                return(true);
            }
            catch (FirebaseAuthWeakPasswordException ex)
            {
                throw new Exception(ex.Message);
            }
            catch (FirebaseAuthInvalidCredentialsException ex)
            {
                throw new Exception(ex.Message);
            }
            catch (FirebaseAuthUserCollisionException ex)
            {
                throw new Exception(ex.Message);
            }
            catch (Exception ex)
            {
                throw new Exception("An unknown error occured, please try again later");
            }
        }
Exemple #2
0
        public async Task <bool> RegisterUser(string name, string email, string pass)
        {
            try
            {
                await Firebase.Auth.FirebaseAuth.Instance.CreateUserWithEmailAndPasswordAsync(email, pass);

                var profileObjects = new Firebase.Auth.UserProfileChangeRequest.Builder();
                var build          = profileObjects.Build();

                var user = Firebase.Auth.FirebaseAuth.Instance.CurrentUser;
                await user.UpdateProfileAsync(build);

                return(true);
            }
            catch (FirebaseAuthWeakPasswordException x)
            {
                throw new Exception(x.Message);
            }
            catch (FirebaseAuthInvalidCredentialsException x)
            {
                throw new Exception(x.Message);
            }
            catch (FirebaseAuthUserCollisionException x)
            {
                throw new Exception(x.Message);
            }
            catch (Exception x)
            {
                throw new Exception(x.Message);
            }
        }
        /*
         * Method used to register the user with email and password with Firebase
         *
         * @Name
         *  User's name
         * @Email
         *  User's email
         * @Password
         * User's password
         */
        public async Task <bool> RegisterUser(string Name, string Email, string Password)
        {
            try
            {
                await Firebase.Auth.FirebaseAuth.Instance.CreateUserWithEmailAndPasswordAsync(Email, Password);

                // Creating a profile change request in order to update the user's name
                var profileChangeRequest = new Firebase.Auth.UserProfileChangeRequest.Builder();
                profileChangeRequest.SetDisplayName(Name);
                var build = profileChangeRequest.Build();

                var User = Firebase.Auth.FirebaseAuth.Instance.CurrentUser;
                await User.UpdateProfileAsync(build);

                // Create user's budget after creation of the user
                var collection = Firebase.Firestore.FirebaseFirestore.Instance.Collection("budgets");
                collection.Add(new Dictionary <string, Java.Lang.Object>
                {
                    { "userid", User.Uid },
                    { "budget", 100000 }
                });

                // Save user details as properties, to use them at each start of the app w/o sending a new request
                App.Current.Properties["Name"]  = Name;
                App.Current.Properties["Email"] = Email;
                await App.Current.SavePropertiesAsync();

                return(true);
            }

            // Catching Firebase exception to convert them into Xamarin exceptions, in order to know about their existence
            catch (FirebaseAuthWeakPasswordException e)
            {
                throw new Exception(e.Message);
            }
            catch (FirebaseAuthInvalidCredentialsException e)
            {
                throw new Exception(e.Message);
            }
            catch (FirebaseAuthUserCollisionException e)
            {
                throw new Exception(e.Message);
            }
            catch (Exception)
            {
                throw new Exception("An error occured, please try again!");
            }
        }
        public async Task <bool> RegisterUser(string name, string email, string password)
        {
            try
            {
                await Firebase.Auth.FirebaseAuth.Instance.CreateUserWithEmailAndPasswordAsync(email, password);

                var profileupdates = new Firebase.Auth.UserProfileChangeRequest.Builder();
                profileupdates.SetDisplayName(name);
                var build = profileupdates.Build();
                var user  = Firebase.Auth.FirebaseAuth.Instance.CurrentUser;
                await user.UpdateProfileAsync(build);

                return(true);
            }
            catch (Exception Ex)
            {
                throw new Exception(Ex.Message);
            }
        }
Exemple #5
0
        /**
         * Register with Firebase method
         *
         */
        public async Task <string> RegisterToFirebase(string username, string email, string password)
        {
            try
            {
                var create = await FirebaseAuth.Instance.CreateUserWithEmailAndPasswordAsync(email, password);

                var profileUpdates = new Firebase.Auth.UserProfileChangeRequest.Builder();
                profileUpdates.SetDisplayName(username);

                var user = Firebase.Auth.FirebaseAuth.Instance.CurrentUser;
                await user.UpdateProfileAsync(profileUpdates.Build());

                var token = await create.User.GetIdTokenAsync(false);

                return(token.Token);
            }
            catch (Exception e)
            {
                return("");
            }
        }
Exemple #6
0
        public async Task <string> Register(string N, string E, string P)
        {
            try
            {
                var result = await RegisterUser(N);

                if (result == 1)
                {
                    var create = await FirebaseAuth.Instance.CreateUserWithEmailAndPasswordAsync(E, P);

                    var profileUpdates = new Firebase.Auth.UserProfileChangeRequest.Builder().SetDisplayName(N);
                    profileUpdates.SetDisplayName(N);
                    var build = profileUpdates.Build();

                    var user = Firebase.Auth.FirebaseAuth.Instance.CurrentUser;
                    await user.UpdateProfileAsync(build);

                    var token = await create.User.GetIdTokenAsync(false);

                    Application.Current.Properties["username"] = N;
                    await Application.Current.SavePropertiesAsync();

                    return(token.Token);
                }
                else if (result == 0)
                {
                    return("userdoppio");
                }
                else
                {
                    return("");
                }
            }
            catch (Exception err)
            {
                Console.WriteLine(err.StackTrace);
                return("");
            }
        }
Exemple #7
0
        public async Task <string> DoRegisterWithEP(string N, string E, string P)   //registrazione con email e password
        {
            try
            {
                var create = await FirebaseAuth.Instance.CreateUserWithEmailAndPasswordAsync(E, P);

                var profileUpdates = new Firebase.Auth.UserProfileChangeRequest.Builder();
                profileUpdates.SetDisplayName(N);
                var build = profileUpdates.Build();

                var user = Firebase.Auth.FirebaseAuth.Instance.CurrentUser;
                await user.UpdateProfileAsync(build);

                var token = await create.User.GetIdTokenAsync(false);

                return(token.Token);
            }
            catch (Exception err)
            {
                return("");
            }
        }
Exemple #8
0
        public async Task <bool> RegisterUser(string email, string password)
        {
            try
            {
                await Firebase.Auth.FirebaseAuth.Instance.CreateUserWithEmailAndPasswordAsync(email, password);

                var profileUpdates = new Firebase.Auth.UserProfileChangeRequest.Builder();
                profileUpdates.SetDisplayName(email);
                var build = profileUpdates.Build();
                var user  = FirebaseAuth.Instance.CurrentUser;
                await user.UpdateProfileAsync(build);

                //shared preferences
                Context        mContext = Android.App.Application.Context;
                AppPreferences ap       = new AppPreferences(mContext);
                ap.SaveAccessKey(true);
                ap.SaveAccessEmail(email);
                ap.SaveAccessPass(password);

                return(true);
            }
            catch (FirebaseAuthWeakPasswordException ex)
            {
                throw new Exception(ex.Message);
            }
            catch (FirebaseAuthInvalidCredentialsException ex)
            {
                throw new Exception(ex.Message);
            }
            catch (FirebaseAuthUserCollisionException ex)
            {
                throw new Exception(ex.Message);
            }
            catch (Exception)
            {
                throw new Exception("An unknown error occurred, please try again.");
            }
        }
Exemple #9
0
        public async Task <bool> RegisterUser(string name, string email, string password)
        {
            try
            {
                //creating an user with email and password
                await Firebase.Auth.FirebaseAuth.Instance.CreateUserWithEmailAndPasswordAsync(email, password);

                //create a profile builder to add the name to the profile
                var profileBuilder = new Firebase.Auth.UserProfileChangeRequest.Builder();
                profileBuilder.SetDisplayName(name);
                var build = profileBuilder.Build();

                //getting the current user
                var user = Firebase.Auth.FirebaseAuth.Instance.CurrentUser;

                //updating the profile of the user with the above build
                await user.UpdateProfileAsync(build);

                return(true);
            }
            catch (FirebaseAuthWeakPasswordException ex)
            {
                throw new Exception(ex.Message);
            }
            catch (FirebaseAuthUserCollisionException ex)
            {
                throw new Exception(ex.Message);
            }
            catch (FirebaseAuthInvalidCredentialsException ex)
            {
                throw new Exception(ex.Message);
            }
            catch (Exception ex)
            {
                throw new Exception("An unknown error occured. Please try again later");
            }
        }
Exemple #10
0
        public async Task UpdateProfileAsync(UserProfileChangeRequest request)
        {
            try
            {
                var builder = new Firebase.Auth.UserProfileChangeRequest.Builder();

                if (request.IsDisplayNameChanged)
                {
                    builder.SetDisplayName(request.DisplayName);
                }
                if (request.IsPhotoUrlChanged)
                {
                    var uri = request.PhotoUrl != null?Android.Net.Uri.Parse(request.PhotoUrl.ToString()) : null;

                    builder.SetPhotoUri(uri);
                }

                await _user.UpdateProfileAsync(builder.Build()).ConfigureAwait(false);
            }
            catch (FirebaseException e)
            {
                throw ExceptionMapper.Map(e);
            }
        }