Exemple #1
0
        public void SignOut()
        {
            FirestoreDb db = CreateInstanceDB();

            AbbigliamentoECommerceEntity.User wUser = new AbbigliamentoECommerceEntity.User();
            var    appSettings  = ConfigurationManager.AppSettings;
            string wApiKey      = appSettings["FirebaseApiKey"] ?? "Not Found";
            var    authProvider = new FirebaseAuthProvider(new FirebaseConfig(wApiKey));

            try
            {
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemple #2
0
        public async Task <WriteResult> InsertUser(AbbigliamentoECommerceEntity.User pUser)
        {
            FirebaseApp wApp        = CreateFirebaseApp();
            FirestoreDb db          = CreateInstanceDB();
            var         appSettings = ConfigurationManager.AppSettings;
            string      apiKey      = appSettings["FirebaseApiKey"] ?? "Not Found";
            //per creare l'username e la password di accesso all'applicazione
            //è necessario utilizzare UserRecordArgs valorizzando le properties con i valori inseriti
            //dall'utente di fase di registrazione
            //si è deciso di usare un autenticazione di tipo email e password
            UserRecordArgs args = new UserRecordArgs()
            {
                Email         = pUser.email,
                EmailVerified = false,
                PhoneNumber   = pUser.TelefoneNumber,
                Password      = pUser.Password,
                DisplayName   = pUser.nome,
                Disabled      = false,
            };
            //viene creato un record nell'Authentication di Firebase tramite un account amministrativ
            UserRecord userRecord = await FirebaseAdmin.Auth.FirebaseAuth.GetAuth(wApp).CreateUserAsync(args);

            // se la registrazione dell'email e password avviene correttamente si procederà
            //accedendo al catalogo User e compilando le informazioni mancanti
            //GetData
            DocumentReference wDocRef = db.Collection("user").Document(userRecord.Uid);

            Dictionary <string, object> wDictionaryUser = new Dictionary <string, object>
            {
                { "Address", pUser.Address },
                { "City", pUser.City },
                //{ "DateOfBirth",pUser.DateOfBirth },
                { "District", pUser.District },
                { "email", pUser.email },
                { "cognome", pUser.cognome },
                { "nome", pUser.nome },
                { "TelefoneNumber", pUser.TelefoneNumber },
                { "Ruolo", "Cliente" },
            };

            return(await wDocRef.SetAsync(wDictionaryUser));
        }
Exemple #3
0
        //Metodo che effettua la login e verifica utenza di Firebase
        public async Task <AbbigliamentoECommerceEntity.User> SignIn(string pEmail, string pPassword)
        {
            FirestoreDb db = CreateInstanceDB();

            AbbigliamentoECommerceEntity.User wUser = new AbbigliamentoECommerceEntity.User();
            var    appSettings  = ConfigurationManager.AppSettings;
            string wApiKey      = appSettings["FirebaseApiKey"] ?? "Not Found";
            var    authProvider = new FirebaseAuthProvider(new FirebaseConfig(wApiKey));

            try
            {
                //Effettuo la login tramite email e password
                FirebaseAuthLink auth = await authProvider.SignInWithEmailAndPasswordAsync(pEmail, pPassword);

                //recupero del uid utente per recuperare tutte le info del'utente loggato
                var decoded = await FirebaseAdmin.Auth.FirebaseAuth.DefaultInstance.VerifyIdTokenAsync(auth.FirebaseToken);

                var uid = decoded.Uid;
                DocumentReference wDocRef = db.Collection("user").Document(uid);

                DocumentSnapshot snapshot = await wDocRef.GetSnapshotAsync();

                if (snapshot.Exists)
                {
                    wUser.Address        = snapshot.ContainsField("Address") ? snapshot.GetValue <string>("Address") : "";
                    wUser.City           = snapshot.ContainsField("City") ? snapshot.GetValue <string>("City") : "";
                    wUser.cognome        = snapshot.ContainsField("cognome") ? snapshot.GetValue <string>("cognome") : "";
                    wUser.DateOfBirth    = snapshot.ContainsField("DateOfBirth") ? snapshot.GetValue <DateTime>("DateOfBirth") : DateTime.MinValue;
                    wUser.District       = snapshot.ContainsField("District") ? snapshot.GetValue <string>("District") : "";
                    wUser.email          = snapshot.ContainsField("email") ? snapshot.GetValue <string>("email") : "";
                    wUser.Id             = uid;
                    wUser.nome           = snapshot.ContainsField("nome") ? snapshot.GetValue <string>("nome") : "";
                    wUser.Ruolo          = snapshot.ContainsField("Ruolo") ? snapshot.GetValue <string>("Ruolo") : "cliente";
                    wUser.TelefoneNumber = snapshot.ContainsField("TelefoneNumber") ? snapshot.GetValue <string>("TelefoneNumber") : "";
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(wUser);
        }
Exemple #4
0
        public async Task <AbbigliamentoECommerceEntity.User> GetUser(string pId)
        {
            FirestoreDb db = CreateInstanceDB();

            AbbigliamentoECommerceEntity.User wUser = new AbbigliamentoECommerceEntity.User();
            var    appSettings = ConfigurationManager.AppSettings;
            string wApiKey     = appSettings["FirebaseApiKey"] ?? "Not Found";

            // var authProvider = new FirebaseAuthProvider(new FirebaseConfig(wApiKey));
            try
            {
                //recupero del uid utente per recuperare tutte le info del'utente loggato
                DocumentReference wDocRef = db.Collection("user").Document(pId);

                DocumentSnapshot snapshot = await wDocRef.GetSnapshotAsync();

                if (snapshot.Exists)
                {
                    wUser.Address        = snapshot.ContainsField("Address") ? snapshot.GetValue <string>("Address") : "";
                    wUser.City           = snapshot.ContainsField("City") ? snapshot.GetValue <string>("City") : "";
                    wUser.cognome        = snapshot.ContainsField("cognome") ? snapshot.GetValue <string>("cognome") : "";
                    wUser.DateOfBirth    = snapshot.ContainsField("DateOfBirth") ? snapshot.GetValue <DateTime>("DateOfBirth") : DateTime.MinValue;
                    wUser.District       = snapshot.ContainsField("District") ? snapshot.GetValue <string>("District") : "";
                    wUser.email          = snapshot.ContainsField("email") ? snapshot.GetValue <string>("email") : "";
                    wUser.Id             = pId;
                    wUser.nome           = snapshot.ContainsField("nome") ? snapshot.GetValue <string>("nome") : "";
                    wUser.Ruolo          = snapshot.ContainsField("Ruolo") ? snapshot.GetValue <string>("Ruolo") : "cliente";
                    wUser.TelefoneNumber = snapshot.ContainsField("TelefoneNumber") ? snapshot.GetValue <string>("TelefoneNumber") : "";
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            return(wUser);
        }