public async Task <Response> Login(Model.User user)
        {
            try
            {
                var authLink = await authProvider.SignInWithEmailAndPasswordAsync(user.EmailID, user.Password);

                firebaseUser = await authProvider.GetUserAsync(authLink.FirebaseToken);

                client = new FirebaseClient(Config.FirebaseWebApp,
                                            new FirebaseOptions
                {
                    AuthTokenAsyncFactory = () => Task.FromResult <string>(authLink.FirebaseToken)
                }
                                            );

                storageClient = new FirebaseStorage(Config.FirebaseStorageApp,
                                                    new FirebaseStorageOptions
                {
                    AuthTokenAsyncFactory = () => Task.FromResult <string>(authLink.FirebaseToken)
                }
                                                    );

                return(new Response {
                    Success = true, Code = (firebaseUser.IsEmailVerified) ? Code.Default : Code.EmailNotVerified
                });
            }
            catch (Exception ex)
            {
                return(new Response {
                    Success = false
                });
            }
        }
Esempio n. 2
0
        private void ClienteAlerta_FormClosing(object sender, FormClosingEventArgs e)
        {
            var authProvider = new FirebaseAuthProvider(new FirebaseConfig("AIzaSyCjNHR6PHEqCbUj_Of7Mx2NxePvoXwkvAM"));

            try
            {
                Auth = null;
            }
            catch (Exception ex)
            {
                User = null;
            }
        }
Esempio n. 3
0
        private void SignUserOut()
        {
            firebaseUser = null;
            accountData  = null;
            adminMsgsListBox.Items.Clear();
            userMsgsListBox.Items.Clear();
            userMsgList     = null;
            exitApplication = false;
            this.Close();
            LoginPanel Login = new LoginPanel();

            Login.Show();
        }
Esempio n. 4
0
        public async void setInfoAsync(Guid id)
        {
            cliente = db.Clientes.Where(x => x.IdCliente == id).FirstOrDefault();

            if (cliente.IdUsuario != null)
            {   // Entra cuando tiene un usuario y tiene un numero de cuenta
                var authProvider = new FirebaseAuthProvider(new FirebaseConfig("AIzaSyCjNHR6PHEqCbUj_Of7Mx2NxePvoXwkvAM"));
                try
                {
                    //Autentificacion si el usuario existe en firebase
                    Auth = await Task.Run(() => authProvider.SignInWithEmailAndPasswordAsync(cliente.NumeroDeCuenta + "@avenzo.mx", cliente.NumeroDeCuenta));

                    User = Auth.User;
                }
                catch (Firebase.Auth.FirebaseAuthException ex)
                {
                    JObject      jObject = JObject.Parse(ex.ResponseData);
                    DialogResult dr      = MetroMessageBox.Show(this, "error:" + jObject["error"]["errors"].First.Last.First.ToString(), "Error en la base de datos de google", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    User = null;
                }
                if (User == null)
                {
                    //Entra si el usuario tiene usuario en sql pero no esta autenticado
                    //Si no esta autenticado bloquar o no permitir la entrada a esta ventana
                    formEdit.Text = "Cliente no cuenta con acceso a aplicacion web ni movil";
                    metroToggle_Android.Checked = false;
                    metroToggle_Web.Checked     = true;
                }
                else
                {
                    //Select para traer los datos de firebase
                    try
                    {
                        var       res = client.Get(@"Accesos/" + cliente.NumeroDeCuenta.ToString());
                        AccesosFb acc = res.ResultAs <AccesosFb>();
                        metroTextBox_Email.Text     = acc.Mail;
                        metroToggle_Android.Checked = acc.Movil;
                        metroToggle_Web.Checked     = acc.Web;
                    }
                    catch (FirebaseAuthException ex)
                    {
                        Console.WriteLine(ex);
                    }
                }
            }
            else
            {
                metroToggle_Android.Checked = false;
                metroToggle_Web.Checked     = false;
            }
        }
Esempio n. 5
0
        public async Task <bool> SignInUser(string email, string password)
        {
            try
            {
                _authLink = await authProvider.SignInWithEmailAndPasswordAsync(email, password);

                String token = _authLink.FirebaseToken;
                SaveFirebaseAuth(_authLink);
                // token = Settings.FirebaseAuthJson;
                Firebase.Auth.User user = await authProvider.GetUserAsync(token);

                if (user.IsEmailVerified == false)
                {
                    ResendEmailVerification(_authLink.FirebaseToken);
                    String massage = String.Format("الحساب غير مفعل سوف نعيد ارسال رابط التفعيل الا الايميل ",
                                                   email);
                    await App.Current.MainPage.DisplayAlert("تأكيد", massage, "موافق");
                }

                return(user.IsEmailVerified);
            }
            catch (FirebaseAuthException ee)
            {
                switch (ee.Reason)
                {
                case AuthErrorReason.WrongPassword:
                    await App.Current.MainPage.DisplayAlert("خطأ", " كلمة السر غير صحيحة", "موافق");

                    break;

                case AuthErrorReason.UnknownEmailAddress:
                    await App.Current.MainPage.DisplayAlert("خطأ", " الايميل غير مستخدم", "موافق");

                    break;
                }
                return(false);
            }
            catch (System.Exception e)
            {
                return(false);

                throw e;
            }
        }
Esempio n. 6
0
        public async Task <Response> SignUp(string email, string password)
        {
            var response = new Response();

            try
            {
                var user = await firebaseAuthProvider.CreateUserWithEmailAndPasswordAsync(email, password);

                if (user.User.LocalId != null)
                {
                    Firebase.Auth.User x = user.User;
                    //string y = x.LocalId;
                    response.Id = user.User.LocalId;
                    return(response);
                }
                else
                {
                    return(null);
                }
            }
            //catch exception if account is not created
            catch (FirebaseAuthException e)
            {
                switch (e.Reason.ToString())
                {
                case "EmailExists":
                    response.ErrorMessage = "Email already exists";
                    break;

                case "InvalidEmailAddress":
                    response.ErrorMessage = "Invalid Email";
                    break;

                default:
                    response.ErrorMessage = "Error Occured";
                    break;
                }
                return(response);
            }
        }
Esempio n. 7
0
        public async void VerifyAsync(string email, string password)
        {
            var authProvider = new FirebaseAuthProvider(new Firebase.Auth.FirebaseConfig("AIzaSyCjNHR6PHEqCbUj_Of7Mx2NxePvoXwkvAM"));

            //
            try
            {
                Auth = await Task.Run(() => authProvider.SignInWithEmailAndPasswordAsync(email, password));

                User = Auth.User;
            }
            catch (Exception ex)
            {
                User = null;
            }

            if (User == null)
            {
                Button_Android.Enabled             = false;
                label_Android_Disponible.Text      = "No Disponible";
                label_Android_Disponible.BackColor = Color.Red;
            }
            else
            {
                var       select = client.Get(@"Accesos/" + cliente.NumeroDeCuenta.ToString());
                AccesosFb acc    = select.ResultAs <AccesosFb>();
                if (acc.Movil == true)
                {
                    Button_Android.Enabled             = true;
                    label_Android_Disponible.Text      = "Disponible";
                    label_Android_Disponible.BackColor = Color.LimeGreen;
                }
                else
                {
                    Button_Android.Enabled             = false;
                    label_Android_Disponible.Text      = "Disponible";
                    label_Android_Disponible.BackColor = Color.Red;
                }
            }
        }
Esempio n. 8
0
        private async void loginButton_Click(object sender, EventArgs e)
        {
            if (pageState == "signIn")
            {
                try
                {
                    // Sign user in and set firebaseUser as the newly signed in account.
                    string           email          = emailBox.Text;
                    string           password       = passwordBox.Text;
                    FirebaseAuthLink userCredential = await authProvider.SignInWithEmailAndPasswordAsync(email, password);

                    firebaseUser = userCredential.User;
                    UserSignedInAsync();
                }
                catch (Exception error)
                {
                    if (error.Message.Contains("INVALID_EMAIL"))
                    {
                        MessageBox.Show("email must be in [email protected] form");
                    }
                    else if (error.Message.Contains("MISSING_PASSWORD"))
                    {
                        MessageBox.Show("Must enter a password.");
                    }
                    else if (error.Message.Contains("WEAK_PASSWORD"))
                    {
                        MessageBox.Show("Password must contain at least 6 characters.");
                    }
                    else if (error.Message.Contains("WrongPassword"))
                    {
                        MessageBox.Show("Incorrect password. Please try again.");
                    }
                    else
                    {
                        MessageBox.Show(error.Message);
                    }
                }
            }
            else if (pageState == "createAccount")
            {
                if (verifyPasswordBox.Text == passwordBox.Text && signUpCodeBox.Text != "")
                {
                    try
                    {
                        // Create account and set firebaseUser as the newly created account. Add account info to database.
                        string email       = emailBox.Text;
                        string password    = passwordBox.Text;
                        string accountType = null;
                        if (signUpCodeBox.Text == "00USER00")
                        {
                            accountType = "User";
                        }
                        else if (signUpCodeBox.Text == "00ADMIN00")
                        {
                            accountType = "Admin";
                        }

                        if (accountType != null)
                        {
                            FirebaseAuthLink userCredential = await authProvider.CreateUserWithEmailAndPasswordAsync(email, password);

                            firebaseUser = userCredential.User;
                            string userId = firebaseUser.LocalId;
                            // Create an accountInfo object with email and account type. Upload to firebase.
                            // #WRITE
                            AccountInfo createdAcctInfo = new AccountInfo(firebaseUser.Email, accountType);
                            await databaseHandler.Child("accounts").Child(userId).Child("accountInfo").PutAsync(createdAcctInfo);

                            UserSignedInAsync();
                        }
                        else
                        {
                            MessageBox.Show("Invalid account type. All users must be part of the company.");
                        }
                    }
                    catch (Exception error)
                    {
                        if (error.Message.Contains("INVALID_EMAIL"))
                        {
                            MessageBox.Show("email must be in [email protected] form");
                        }
                        else if (error.Message.Contains("MISSING_PASSWORD"))
                        {
                            MessageBox.Show("Must enter a password.");
                        }
                        else if (error.Message.Contains("EMAIL_EXISTS"))
                        {
                            MessageBox.Show("That email already belongs to an account.");
                        }
                        else if (error.Message.Contains("WEAK_PASSWORD"))
                        {
                            MessageBox.Show("Password must contain at least 6 characters.");
                        }
                        else
                        {
                            MessageBox.Show(error.Message);
                        }
                    }
                }
                else
                {
                    if (verifyPasswordBox.Text != passwordBox.Text)
                    {
                        MessageBox.Show("Passwords must match.");
                    }
                    else if (signUpCodeBox.Text == "")
                    {
                        MessageBox.Show("You must have an account code.");
                    }
                }
            }
        }