예제 #1
0
 public async Task Register(string mail, string password, string nome, string cognome)
 {
     try
     {
         await FirebaseAuth.Instance.CreateUserWithEmailAndPasswordAsync(mail, password).ContinueWith(task =>
         {
             if (task.IsCompletedSuccessfully)
             {
                 UserProfileChangeRequest request = new UserProfileChangeRequest.Builder().SetDisplayName(
                     nome + " " + cognome).Build();
                 task.Result.User.UpdateProfileAsync(request);
             }
             else
             {
                 throw new FormatException();
             }
         });
     }
     catch (FirebaseAuthInvalidUserException exception)
     {
         throw exception;
     }
     catch (System.Exception exception)
     {
         throw exception;
     }
 }
예제 #2
0
        public void SetAccountData(String name, String birthday, int radius, bool sendVerification)
        {
            if (authAccount == null)
            {
                authAccount = new Account();
            }
            authAccount.Name        = name;
            authAccount.Birthday    = Convert.ToDateTime(birthday);
            authAccount.SalesRadius = radius;
            var user           = FirebaseAuth.Instance.CurrentUser;
            var profileUpdates = new UserProfileChangeRequest.Builder().SetDisplayName(name).Build();

            user.UpdateProfile(profileUpdates);

            IDictionary <string, Java.Lang.Object> accountData = new Dictionary <string, Java.Lang.Object>
            {
                { "name", name },
                { "birthday", birthday },
                { "radius", radius }
            };

            if (dataRef == null)
            {
                dataRef = firData.GetReference($"users/{FirebaseAuth.Instance.CurrentUser.Uid}");
            }
            dataRef.UpdateChildren(accountData);
            if (sendVerification)
            {
                SendEmailVerification();
            }
        }
        /// <summary>
        ///     Méthode d'initialisation des boutons
        /// </summary>
        private void InitializeButtons()
        {
            register        = FindViewById <Button>(Resource.Id.button_register);
            register.Click += async delegate
            {
                try
                {
                    await FirebaseAuth.Instance.CreateUserWithEmailAndPasswordAsync(userMail.Text.ToString(), userPassword.Text.ToString());

                    var profileUpdates = new UserProfileChangeRequest.Builder()
                                         .SetDisplayName(userName.Text.ToString())
                                         .Build();

                    try
                    {
                        await FirebaseAuth.Instance.CurrentUser.UpdateProfileAsync(profileUpdates);

                        StartActivity(typeof(MainActivity));
                    }
                    catch (Exception ex)
                    {
                        // Failed to update user profile
                    }
                }
                catch
                {
                    Toast.MakeText(this, "Authentication failed.", ToastLength.Short).Show();
                }
            };
        }
예제 #4
0
        public async void UserSignUp(string email, string pass, string name, string sName, string tName)
        {
            var user = await FirebaseAuth.Instance.CreateUserWithEmailAndPasswordAsync(email, pass);

            var userProfileChangeRequest = new UserProfileChangeRequest.Builder()
                                           .SetDisplayName($"{name} {sName} {tName}")
                                           .Build();

            user.User.UpdateProfile(userProfileChangeRequest);
        }
예제 #5
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.Registration);
            mAuth = FirebaseAuth.GetInstance(AppDataHelper.GetAuth().App);
            FirebaseUser             user       = mAuth.CurrentUser;
            UserProfileChangeRequest profUpdate = new UserProfileChangeRequest.Builder().SetDisplayName(fullname).Build();

            ConnectControl();
        }
예제 #6
0
        public async Task <bool> CreateUser(string username, string email, string password)
        {
            var authResult = await FirebaseAuth.Instance.CreateUserWithEmailAndPasswordAsync(email, password);

            var userProfileChangeRequestBuilder = new UserProfileChangeRequest.Builder();

            userProfileChangeRequestBuilder.SetDisplayName(username);
            var userProfileChangeRequest = userProfileChangeRequestBuilder.Build();
            await authResult.User.UpdateProfileAsync(userProfileChangeRequest);

            return(await Task.FromResult(true));
        }
        public async Task <string> Register(string eMail, string password, string name)
        {
            IAuthResult user = await FirebaseAuth.Instance.CreateUserWithEmailAndPasswordAsync(eMail, password);

            UserProfileChangeRequest.Builder profileUpdates = new UserProfileChangeRequest.Builder();
            profileUpdates.SetDisplayName(name);
            UserProfileChangeRequest updates = profileUpdates.Build();
            await user.User.UpdateProfileAsync(updates);

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

            return(token.Token);
        }
예제 #8
0
        public void OnSuccess(Java.Lang.Object result)
        {
            Toast.MakeText(this, "Picture Uploaded Successfully", ToastLength.Short).Show();
            var snapshot = (UploadTask.TaskSnapshot)result;
            var url      = "https://firebasestorage.googleapis.com" + snapshot.DownloadUrl.EncodedPath + "?" + snapshot.DownloadUrl.EncodedQuery; // download url for user image

            PhotoURL = url;                                                                                                                       // To save in db
            //int a = 1;

            var profileUpdates = new UserProfileChangeRequest.Builder().SetPhotoUri(Android.Net.Uri.Parse(url)).Build();

            auth.CurrentUser.UpdateProfile(profileUpdates);
        }
        private async void RegisterUser()
        {
            try
            {
                //editMail.Text = "*****@*****.**";
                //editUsername.Text = "TESTuSER";
                //editPassword.Text = "Tafra123";
                using IAuthResult authResult = await FirebaseHandler.Instance.Auth
                                               .CreateUserWithEmailAndPasswordAsync(editMail.Text, editPassword.Text)
                                               .ConfigureAwait(false);

                using UserProfileChangeRequest profile = new UserProfileChangeRequest.Builder()
                                                         .SetDisplayName(editUsername.Text)
                                                         .Build();

                await authResult.User
                .UpdateProfileAsync(profile)
                .ConfigureAwait(false);

                UserProfile up = new UserProfile(editUsername.Text, editMail.Text);
                UserGroups  ug = new UserGroups()
                {
                    Creator = new User(up)
                };

                System.Collections.Generic.List <Task> tasks = Instance.InitFirestoreUser(editUsername.Text, editMail.Text);
                Task.WaitAll(tasks.ToArray());
                if (tasks.All(t => t.IsCompletedSuccessfully))
                {
                    Instance.LoadUserData(editUsername.Text);
                    StartActivity(typeof(MainActivity));
                    Finish();
                }
                else
                {
                    MainThread.BeginInvokeOnMainThread(() =>
                    {
                        Toast.MakeText(ApplicationContext, Resource.String.err_failed_to_save_firestore, ToastLength.Short)
                        .Show();
                    });
                }
            }
            catch (FirebaseException excepion)
            {
                MainThread.BeginInvokeOnMainThread(() =>
                {
                    Toast.MakeText(ApplicationContext, excepion.Message, ToastLength.Short)
                    .Show();
                });
            }
        }
        public async Task <FirebaseUser> CreateUserWithEmailPasswordAsync(string email, string password, string displayName)
        {
            _user = (await _firebaseAuth.CreateUserWithEmailAndPasswordAsync(email, password)).User;

            var request = new UserProfileChangeRequest.Builder();

            request.SetDisplayName(displayName);

            await _firebaseAuth.CurrentUser.UpdateProfileAsync(request.Build());

            SaveUser();

            return(User);
        }
        public async Task <string> RegisterAsync(string displayName, string email, string password)
        {
            try
            {
                var authResult = await _firebaseAuth
                                 .CreateUserWithEmailAndPasswordAsync(email, password);

                var tokenResult = await authResult.User
                                  .GetIdTokenAsync(false);

                UserProfileChangeRequest userProfileChangeRequest = new UserProfileChangeRequest.Builder()
                                                                    .SetDisplayName(displayName)
                                                                    .Build();

                await authResult.User.UpdateProfileAsync(userProfileChangeRequest);

                StoreAuthResult(authResult.User, tokenResult.Token);

                return(tokenResult.Token);
            }
            catch (System.Exception ex)
            {
                if (ex is FirebaseAuthUserCollisionException fbuc_ex)
                {
                    _loggerService.Info(
                        TAG, $"on{nameof(RegisterAsync)}: {ex.Message}");

                    throw new InvalidUserAuthException(
                              fbuc_ex.ErrorCode,
                              fbuc_ex);
                }
                else if (ex is FirebaseAuthWeakPasswordException fbawp_ex)
                {
                    _loggerService.Info(
                        TAG, $"on{nameof(RegisterAsync)}: {ex.Message}");

                    throw new InvalidUserAuthException(
                              fbawp_ex.ErrorCode,
                              fbawp_ex);
                }
                else
                {
                    _loggerService.LogException(ex.Message);
                }

                return(null);
            }
        }
예제 #12
0
        public void ChangeLogin(string text, IOnCompleteListener c)
        {
            FirebaseUser user = FirebaseAuth.Instance.CurrentUser;

            if (user != null)
            {
                UserProfileChangeRequest.Builder profileUpdates = new UserProfileChangeRequest.Builder();
                profileUpdates.SetDisplayName(text);
                UserProfileChangeRequest updates = profileUpdates.Build();
                user.UpdateProfile(updates).AddOnCompleteListener(c);
            }
            else
            {
                throw new Exception("Current user is null");
            }
        }
        public void OnSuccess(Java.Lang.Object result)
        {
            progressDialog.Dismiss();
            Toast.MakeText(this, "Uploaded Successful", ToastLength.Short).Show();
            var snapshot = (UploadTask.TaskSnapshot)result;
            var url      = "https://firebasestorage.googleapis.com" + snapshot.DownloadUrl.EncodedPath + "?" + snapshot.DownloadUrl.EncodedQuery; // download url for user image

            //int a = 1;

            var profileUpdates = new UserProfileChangeRequest.Builder()
                                 .SetDisplayName("Jane Q. User")
                                 .SetPhotoUri(Android.Net.Uri.Parse(url))
                                 .Build();

            auth.CurrentUser.UpdateProfile(profileUpdates);
        }
예제 #14
0
        public static async Task Register(ListsActivity thisActivity, string name, string email, string password)
        {
            await AppData.auth.CreateUserWithEmailAndPasswordAsync(email, password);

            var profileUpdate = new UserProfileChangeRequest.Builder()
                                .SetDisplayName(name)
                                .Build();

            AppData.auth.CurrentUser.UpdateProfile(profileUpdate);

            UserClass localUser = new UserClass()
            {
                Name  = name,
                Email = email,
                Uid   = AppData.auth.CurrentUser.Uid
            };

            SetLocalUser.Set(localUser);

            await AppData.usersNode
            .Child(AppData.auth.CurrentUser.Uid)
            .PutAsync(localUser);


            foreach (GroceryListClass any in AppData.currentLists)
            {
                if (any.Owner.Uid == AppData.currentUser.Uid)
                {
                    SaveListOnCloud.Save(any);
                }
            }

            AlertShow.Show(thisActivity,
                           "Welcome " + AppData.currentUser.Name,
                           "You are now registered online and can share your lists with your friends");


            await thisActivity.ReloadListView();
        }
예제 #15
0
        public async Task <ResultAuth> RegisteredWithEP(string Name, string Email, string Psw)
        {
            try
            {
                var user = await FirebaseAuth.Instance.CreateUserWithEmailAndPasswordAsync(Email, Psw);

                UserProfileChangeRequest profile = new UserProfileChangeRequest.Builder().SetDisplayName(Name).Build();
                await user.User.UpdateProfileAsync(profile);

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

                return(new ResultAuth()
                {
                    Token = token.Token, isError = false, Name = Name, UID = user.User.Uid
                });
            }
            catch (Exception err)
            {
                return(new ResultAuth()
                {
                    isError = true, ErrorMsg = err.Message
                });
            }
        }