Esempio n. 1
0
        public async Task <bool> LogOut()
        {
            Context        mContext = Android.App.Application.Context;
            AppPreferences ap       = new AppPreferences(mContext);

            ap.SaveAccessKey(false);
            ap.SaveAccessPass("");
            ap.SaveAccessEmail("");
            FirebaseAuth.Instance.SignOut();
            return(true);
        }
Esempio n. 2
0
        public async Task <bool> AuthenticateUser(string email, string password)
        {
            try
            {
                await FirebaseAuth.Instance.SignInWithEmailAndPasswordAsync(email, password);

                //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 (Exception)
            {
                return(false);
            }
        }
Esempio n. 3
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.");
            }
        }