예제 #1
0
 public SubastaController(IBLSubasta subbl, IBLComentario combl, IBLProducto probl, IBLOferta ofebl, IBLUsuario usubl, IBLAtributo atrIBL, IBLAtributo_Subasta atrSubIBL, IBLFavorito favIBL)
 {
     this.subIBL    = subbl;
     this.comIBL    = combl;
     this.proIBL    = probl;
     this.ofeIBL    = ofebl;
     this.usuIBL    = usubl;
     this.atrIBL    = atrIBL;
     this.favIBL    = favIBL;
     this.atrSubIBL = atrSubIBL;
 }
예제 #2
0
        public ActionResult FacebookCallback(string code)
        {
            log.Warn("entro Facebook FacebookCallback");

            string code_temp = code.Replace("code=", "");

            log.Warn("URI ABSOLUTE =" + RedirectUri.AbsoluteUri.ToString());



            log.Warn("Codigo  " + code);
            try
            {
                var     fb     = new FacebookClient();
                dynamic result = fb.Post("oauth/access_token", new
                {
                    client_id     = "508985985924118",
                    client_secret = "778ec6400e56f9382f23a3b9ca44b6bc",
                    redirect_uri  = RedirectUri.AbsoluteUri,
                    code          = code_temp
                });

                var accessToken = result.access_token;

                // Store the access token in the session for farther use
                Session["AccessToken"] = accessToken;

                log.Warn("Paso token ");
                // update the facebook client with the access token so
                // we can make requests on behalf of the user
                fb.AccessToken = accessToken;
                log.Warn("Antes fb.get " + accessToken);
                // Get the user's information, like email, first name, middle name etc
                //dynamic me = fb.Get ("me") ;



                dynamic me = fb.Get("me?fields=id,email,name,picture");
                //FacebookUserModel facebookUser = Newtonsoft.Json.JsonConvert.DeserializeObject<FacebookUserModel>(fbresult.ToString());

                //,first_name,last_name,locale,location,picture

                //dynamic me = fb.Get("me?fields=first_name,middle_name,last_name,email");
                //("/me?fields=id,name,gender,email,birthday")

                log.Warn("DATOS " + me.email);


                string imagen = string.Format("https://graph.facebook.com/{0}/picture", me.id);
                log.Warn("DATOS 2 " + imagen);
                //string imagen = me.picture;
                string email  = me.email;
                string nombre = me.name;

                //string direccion =me.locale;
                log.Warn("despues datos fb.get  " + email + " " + nombre);

                user_sitio   = System.Web.HttpContext.Current.Session["usuario"] as UsuarioSite;
                valor_tenant = user_sitio.Dominio;
                if (!(_bl.ExisteUsuario(valor_tenant, email)))
                {
                    // if (user_sitio.Email == null) return RedirectToAction("Login", "Account");
                    //valor_tenant = user_sitio.Dominio.ToString();
                    proIBL = new BLProducto();
                    var lista_Origen = proIBL.ObtenerCategoriasPorTienda(user_sitio.idTienda);
                    List <System.Web.WebPages.Html.SelectListItem> lista_item_Cat = new List <System.Web.WebPages.Html.SelectListItem>();
                    foreach (var item in lista_Origen)
                    {
                        lista_item_Cat.Add(new System.Web.WebPages.Html.SelectListItem()
                        {
                            Value    = item.CategoriaId.ToString(),
                            Text     = item.Nombre,
                            Selected = true
                        });
                    }


                    log.Warn("Facebook creo alta usuario");
                    user = new Usuario
                    {
                        email             = email,
                        direccion         = "vacia",
                        imagen            = imagen,
                        fecha_Nacimiento  = DateTime.Now,
                        nombre            = nombre,
                        apellido          = "",
                        nick              = nombre,
                        password          = "******",
                        fecha_Alta        = (DateTime)DateTime.Now,
                        reputacion_Venta  = "0",
                        reputacion_Compra = "0",
                        //billetera = (Double)5000,
                        coordenadas = "sin direccion",
                        telefono    = "facebook"
                    };
                    log.Warn("Cargo preferencias del usuario ");
                    if (lista_item_Cat != null)
                    {
                        foreach (var item in lista_item_Cat)
                        {
                            if (item.Selected)
                            {
                                log.Warn("Item " + item.Selected.ToString() + " " + item.Text + " " + item.Value);
                                if (user.preferencias != null)
                                {
                                    user.preferencias = user.preferencias + ";" + item.Text;
                                }
                                else
                                {
                                    user.preferencias = item.Text;
                                }
                            }
                        }
                    }

                    //****************************************
                    log.Warn("Registrando por Facebook en  : " + valor_tenant + "Usuario : " + user.ToString());
                    _bl.RegistrarUsuario(valor_tenant, user);
                }

                Usuario usr = _bl.LoginUsuarioFacebook(valor_tenant, email);
                if (usr != null)
                {
                    int idTenant = _ibl.ObtenerIdTenant(valor_tenant);

                    var user_Session = Session["usuario"] as UsuarioSite;
                    user_Session.Email  = usr.email;
                    user_Session.Nombre = usr.nombre;
                    //user_Session.Password = usr.password;
                    user_Session.idUsuario = usr.id;
                    user_Session.idTienda  = idTenant;
                    user_Session.imagen    = user.imagen;
                }
                // Set the auth cookie
                FormsAuthentication.SetAuthCookie(email, false);
            }
            catch (Exception e)
            {
                log.Error("Error Facebook callback " + e);
                throw e;
            }



            return(RedirectToAction("Index", "Tenant"));
        }
예제 #3
0
 public ProductoController(IBLProducto bl)
 {
     this._blproducto = bl;
 }
예제 #4
0
        public ActionResult Register()
        {
            RegisterViewModel registro = new RegisterViewModel();

            registro.preferencias = new List <string>();

            try
            {
                user_sitio = System.Web.HttpContext.Current.Session["usuario"] as UsuarioSite;

                // if (user_sitio.Email == null) return RedirectToAction("Login", "Account");
                valor_tenant = user_sitio.Dominio.ToString();


                proIBL = new BLProducto();

                var lista_Origen = proIBL.ObtenerCategoriasPorTienda(user_sitio.idTienda);
                List <System.Web.WebPages.Html.SelectListItem> lista_item_Cat = new List <System.Web.WebPages.Html.SelectListItem>();

                foreach (var item in lista_Origen)
                {
                    lista_item_Cat.Add(new System.Web.WebPages.Html.SelectListItem()
                    {
                        Value    = item.CategoriaId.ToString(),
                        Text     = item.Nombre,
                        Selected = false
                    });
                }

                ViewData["Categorias"] = lista_item_Cat;

                //registro.lista_preferencias;
                registro.lista_preferencias = lista_item_Cat;
                if (lista_Origen != null)
                {
                    foreach (var item in lista_Origen)
                    {
                        registro.preferencias.Add(item.Nombre);
                    }
                }
                // ViewData["Productos"] = proIBL.ObtenerProductos();
                //  ViewData["Atributos"] = atrIBL.ObtenerAtributos();
                //   ViewBag.ListaAtributos = atrIBL.ObtenerAtributos();
                // ViewBag.CategoriaId = new SelectList(proIBL.ObtenerCategoriasPorTienda(user_sitio.idTienda), "CategoriaId","TiendaId", "Nombre");
                //System.Threading.
                // var user = Session["usuario"] as UsuarioSite;
                //if (user.Dominio != null) valor_tenant = user.Dominio;

                /* local = Thread.GetNamedDataSlot("tenant");
                 * if (local == null) System.Diagnostics.Debug.WriteLine("Valor tenant nulo");
                 * else System.Diagnostics.Debug.WriteLine("Tenant " + Thread.GetData(local));
                 * valor_tenant = System.Threading.Thread.GetData(local).ToString();*/
                //Sitio sitio = Session["sitio"] as Sitio;
            }
            catch (Exception)
            {
                throw;
            }

            return(View(registro));
        }