public RegistroPage(UserFB user)
        {
            InitializeComponent();

            tapSiguiente         = new TapGestureRecognizer();
            tapSiguiente.Tapped += TapSiguiente_Tapped;
            slSiguiente.GestureRecognizers.Add(tapSiguiente);
            var r = new ToolbarItem();

            r.Text     = "Ir al Home";
            r.Clicked += (object sender, EventArgs e) =>
            {
                App.BackToMain(false);
            };
            ToolbarItems.Add(r);


            userInfoFromFaceBook = user;

            if (userInfoFromFaceBook != null)
            {
                txtMail.Text     = userInfoFromFaceBook.email;
                txtPhone.Text    = userInfoFromFaceBook.phone;
                txtFullName.Text = userInfoFromFaceBook.full_name;
                //txtMail.IsEnabled = false; porque algunas cuentas de facebook vienen sin email ejemplo las creadas con numero de telefono
                lblSiguiente.Text = "Terminar";
                swicthTerminosYCondiciones.IsToggled = true;
            }

            imgFb.IsVisible     = false;
            btnSignIn.IsVisible = false;

            Loading(false);
        }
Beispiel #2
0
        public static async void LoginFacebook(string obj, string accesS_token, DateTime expires_in)
        {
            UserFB usr = new UserFB();

            usr.public_profile = obj;
            usr.token          = accesS_token;
            usr.expireDate     = expires_in;
            var dyn = Newtonsoft.Json.JsonConvert.DeserializeObject <JObject>(obj);


            if (dyn["email"] != null)
            {
                usr.email = dyn["email"].ToString() ?? "";
            }
            else
            {
                usr.email = "";
            }

            usr.first_name = dyn["first_name"].ToString() ?? "";
            usr.last_name  = dyn["last_name"].ToString() ?? "";
            usr.full_name  = usr.first_name + " " + usr.last_name;
            usr.gender     = dyn["gender"].ToString() ?? "";
            usr.id_fbk     = dyn["id"].ToString();
            usr.url        = "https://graph.facebook.com/" + usr.id_fbk + "/picture?type=large";
            userFB         = usr;

            var r = JsonConvert.SerializeObject(usr);

            //attemp login if not exists fb on db then create a new account in db idd
            await App.LoginFB(usr);
        }
        async void TapSiguiente_Tapped(object sender, EventArgs e)
        {
            //validar datos primero
            var pasa_validacion = true;

            var aceptoTerminos = swicthTerminosYCondiciones.IsToggled;

            if (aceptoTerminos)
            {
                if (!string.IsNullOrEmpty(txtFullName.Text) && !string.IsNullOrEmpty(txtMail.Text) && !string.IsNullOrEmpty(txtPhone.Text))
                {
                    //si viene el mail entonces validar
                    if (!string.IsNullOrEmpty((txtMail.Text)))
                    {
                        if (!GlobalHelpers.EmailBienEscrito(txtMail.Text))
                        {
                            await DisplayAlert("¡Uh oh!", "Email no valido.", "Aceptar");

                            pasa_validacion = false;
                        }
                    }
                    if (pasa_validacion)
                    {
                        //los datos ya vienen del login de facebook
                        if (userInfoFromFaceBook != null)
                        {
                            userInfoFromFaceBook.phone     = txtPhone.Text;
                            userInfoFromFaceBook.email     = txtMail.Text;
                            userInfoFromFaceBook.full_name = txtFullName.Text;


                            Loading(true);
                            await Registrar(userInfoFromFaceBook);

                            //GeneralSetting.UserSettings = JsonConvert.SerializeObject(userInfoFromFaceBook);
                            //App.NavigateToProfile();
                        }
                        else
                        {
                            UserFB user = new UserFB();
                            user.email     = txtMail.Text;
                            user.full_name = txtFullName.Text;
                            user.phone     = txtPhone.Text;

                            await Navigation.PushAsync(new ContraseñaPage(user));
                        }
                    }
                }
                else
                {
                    await DisplayAlert("¡Uh oh!", "Todos los datos son obligatorios.", "Aceptar");
                }
            }
            else
            {
                await DisplayAlert("¡Uh oh!", "no se puede registrar si no acepta los terminos y condiciones.", "Aceptar");
            }
        }
Beispiel #4
0
        public static async Task <JObject> PostUserFB(UserFB user)
        {
            try
            {
                using (var client = ServiceBase.GetClient())
                {
                    var r       = JsonConvert.SerializeObject(user);
                    var content = new StringContent(JsonConvert.SerializeObject(user), Encoding.UTF8, "application/json");


                    client.MaxResponseContentBufferSize = 5256000;

                    MultipartFormDataContent form = new MultipartFormDataContent();

                    form.Add(new StringContent(user.token), "token");
                    form.Add(new StringContent(user.url ?? String.Empty), "url");
                    form.Add(new StringContent(user.expireDate.ToShortDateString()), "expireDate");
                    form.Add(new StringContent(user.id_fbk), "id_fbk");
                    form.Add(new StringContent(user.email), "email");
                    form.Add(new StringContent(user.first_name), "first_name");
                    form.Add(new StringContent(user.last_name), "last_name");
                    form.Add(new StringContent(user.phone), "phone");
                    form.Add(new StringContent(user.first_name + " " + user.last_name), "full_name");
                    form.Add(new StringContent(user.public_profile ?? String.Empty), "public_profile");
                    form.Add(new StringContent(user.user_hometown ?? String.Empty), "user_hometown");
                    form.Add(new StringContent(user.user_location ?? String.Empty), "user_location");
                    form.Add(new StringContent(user.gender ?? string.Empty), "gender");


                    var response = await client.PostAsync("api/user/user_fb", form);

                    if (response.IsSuccessStatusCode)
                    {
                        var str = await response.Content.ReadAsStringAsync();

                        var responseContent = Newtonsoft.Json.JsonConvert.DeserializeObject <JObject>(str);

                        return(responseContent);
                        //return user;
                    }
                    else
                    {
                        var errorResponse = new JObject();
                        errorResponse.Add("codigo", "-1");
                        errorResponse.Add("mensaje", "ha ocurrido un error");
                        return(errorResponse);
                    }

                    return(null);
                }
            }
            catch (Exception e)
            {
                return(null);
            }
        }
Beispiel #5
0
        public static async Task LoginFB(UserFB usr)
        {
            Console.WriteLine("entra a registrar");

            await Task.Run(async() =>
            {
                try
                {
                    var responseApi = await FbService.PostLogin(usr.id_fbk);


                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        if (responseApi != null)
                        {
                            if (responseApi["codigo"].ToString() == "1")
                            {
                                var s          = responseApi["data"].ToString();
                                var userLogged = Newtonsoft.Json.JsonConvert.DeserializeObject <UserFB>(s);

                                if (userLogged != null)
                                {
                                    GeneralSetting.UserSettings = JsonConvert.SerializeObject(userLogged);
                                    App.NavigateToProfile();
                                }                                //usuario nuevo registrar pagina
                                else
                                {
                                    var app      = Current as App;
                                    app.MainPage = new NavigationPage(new RegistroPage(usr))
                                    {
                                        BarBackgroundColor = (Color)App.Current.Resources["AzulColor"]
                                    };
                                }
                            }
                            else
                            {
                                var app      = Current as App;
                                app.MainPage = new NavigationPage(new RegistroPage(usr))
                                {
                                    BarBackgroundColor = (Color)App.Current.Resources["AzulColor"]
                                };
                            }
                        }
                    });
                }
                catch (Exception e)
                {
                    Console.WriteLine("ha ocurrido un error");
                }
            });
        }
Beispiel #6
0
        public ContraseñaPage(UserFB _user)
        {
            InitializeComponent();

            this.user    = _user;
            _userService = new UserService();

            tapTerminar         = new TapGestureRecognizer();
            tapTerminar.Tapped += TapTerminar_Tapped;
            johnnSl.GestureRecognizers.Add(tapTerminar);


            Loading(false);
        }
        public async Task Registrar(UserFB usr)
        {
            Console.WriteLine("entra a registrar");

            await Task.Run(async() =>
            {
                try
                {
                    var responseApi = await FbService.PostUserFB(usr);

                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        if (responseApi != null)
                        {
                            if (responseApi["codigo"].ToString() == "1")
                            {
                                var s       = responseApi["data"].ToString();
                                var newUser = Newtonsoft.Json.JsonConvert.DeserializeObject <UserFB>(s);

                                if (newUser != null)
                                {
                                    //await DisplayAlert("Usuario", "Usuario creado con exito", "Aceptar");
                                    GeneralSetting.UserSettings = JsonConvert.SerializeObject(newUser);
                                    App.NavigateToProfile();
                                    Loading(false);
                                }
                            }
                            else
                            {
                                await DisplayAlert("Usuario", responseApi["mensaje"].ToString(), "Aceptar");
                            }
                        }
                        else
                        {
                            Loading(false);
                            await DisplayAlert("Usuario", "Ha ocurrido un error", "Aceptar");
                        }
                    });
                }
                catch (Exception e)
                {
                    Loading(false);
                    await DisplayAlert("Usuario", "Ha ocurrido un error " + e.Message, "Aceptar");
                }
            });
        }
Beispiel #8
0
        public async Task <JObject> PostUser(UserFB user)
        {
            try
            {
                using (var client = ServiceBase.GetClient())
                {
                    client.MaxResponseContentBufferSize = 5256000;

                    MultipartFormDataContent form = new MultipartFormDataContent();
                    //if (listByte != null)
                    //{
                    //	for (int i = 0; i < listByte.Count; i++)
                    //	{
                    //		form.Add(new ByteArrayContent(listByte[i], 0, listByte[i].Length), "userfile[]", i + ".jpg");
                    //	}
                    //}
                    form.Add(new StringContent(user.email), "email");
                    form.Add(new StringContent(user.full_name), "full_name");
                    form.Add(new StringContent(user.phone), "phone");
                    form.Add(new StringContent(user.password), "password");


                    var response = await client.PostAsync("api/user/user", form);

                    if (response.IsSuccessStatusCode)
                    {
                        var str = await response.Content.ReadAsStringAsync();

                        var responseContent = Newtonsoft.Json.JsonConvert.DeserializeObject <JObject>(str);

                        return(responseContent);

                        //if (responseContent["codigo"].ToString() == "1")
                        //{
                        //	var s = responseContent["data"].ToString();
                        //	var res = Newtonsoft.Json.JsonConvert.DeserializeObject<UserFB>(s);

                        //	var json = new JObject();
                        //	json.Add("data", s);
                        //	json.Add("codigo"



                        //	return res;
                        //}
                        //else {


                        //}
                    }
                    else
                    {
                        var errorResponse = new JObject();
                        errorResponse.Add("codigo", "-1");
                        errorResponse.Add("mensaje", "ha ocurrido un error");
                        return(errorResponse);
                    }
                }
            }
            catch (Exception e)
            {
                return(null);
            }
        }