Ejemplo n.º 1
0
        public ActionResult CreateNew(NewsViewModel model)
        {
            if (Request.Cookies["MagazineId"].Value == null)
            {
                SetMessage("Lo sentimos, ha ocurrido un error. Inténtelo de nuevo.", BootstrapAlertTypes.Danger); return(RedirectToAction("Index", "Magazines"));
            }
            int magId = Int32.Parse(Request.Cookies["MagazineId"].Value);

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var category = MagazineService.GetCategoryById(model.CategoryId);

            if (category == null)
            {
                return(RedirectToAction("Index", "Magazines"));
            }

            var imageCode = "Expose_Default_New.png";

            if (model.Image != null && model.Image.ContentLength > 0)
            {
                var imageModel = ResourceService.SaveImage(Server.MapPath("~/content/data/"), model.Image, false);
                if (imageModel == null)
                {
                    ModelState.AddModelError("", "No se pudo guardar la imagen. Intentalo de nuevo.");
                    return(View(model));
                }
                imageCode = imageModel.FullFileName;
            }

            var create = MagazineService.CreateNews(model.Title, model.Description, model.MainImage, model.Thumbnail, model.Body,
                                                    model.CategoryId, model.Permalink, model.MetaDesc, model.MetaTags, model.Alt, model.VideoEmbed, DateTime.Now);

            if (create == null)
            {
                SetMessage(MagazineService.ServiceTempData);
                return(RedirectToAction("Index", "Magazines"));
            }

            var user = MagazineService.GetCurrentUser();

            if (user == null)
            {
                TweetNews("http://www.expose.mx/noticia/" + create.NewsId + "/tw/" + 2 + " " + create.Description);
            }
            else
            {
                TweetNews("Expose.mx http://www.expose.mx/noticia/" + create.NewsId + "/tw/" + user.UserId + " " + create.Description);
            }

            return(RedirectToAction("MagazineNews", "News", new { id = create.Category.MagazineId }));
        }
Ejemplo n.º 2
0
        public ActionResult Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                SetMessage("Algo salio mal, intenta iniciar sesion de nuevo.", BootstrapAlertTypes.Warning);
                return(Redirect("/"));
            }

            if (System.Web.HttpContext.Current.Request.Cookies["currentUser"] != null)
            {
                HttpCookie currentUserCookie = System.Web.HttpContext.Current.Request.Cookies["currentUser"];
                System.Web.HttpContext.Current.Response.Cookies.Remove("currentUser");
                currentUserCookie.Expires = DateTime.Now.AddDays(-10);
                currentUserCookie.Value   = null;
                System.Web.HttpContext.Current.Response.SetCookie(currentUserCookie);
            }

            if (!WebSecurity.Login(model.Email, model.Password))
            {
                SetMessage("Alguno de los datos que ingresaste son incorrectos. Intentelo de nuevo.", BootstrapAlertTypes.Danger);
                return(RedirectToAction("Login"));
            }

            var user = UserService.GetUserbyEmail(model.Email);

            if (user == null)
            {
                SetMessage("Lo sentimos, no se encontró el usuario. Inténtelo de nuevo.", BootstrapAlertTypes.Danger);
                return(RedirectToAction("Login"));
            }

            if (user.ActivationDate == null)
            {
                SetMessage("Valida tu cuenta de correo electrónico para poder iniciar sesión.", BootstrapAlertTypes.Warning);
                return(RedirectToAction("Login"));
            }

            var claims = new List <Claim>();

            claims.Add(new Claim(ClaimTypes.Name, model.Email));
            claims.Add(new Claim(ClaimTypes.Email, model.Email));
            var id = new ClaimsIdentity(claims,
                                        DefaultAuthenticationTypes.ApplicationCookie);

            var ctx = Request.GetOwinContext();
            var authenticationManager = ctx.Authentication;

            authenticationManager.SignIn(id);

            SetAuthCookie(model.Email);

            SetEncryptedCookie(Configuration.UserCookie, new Dictionary <String, String>
            {
                { "Email", user.Email },
                { "Code", user.Code }
            });

            var currentUser = MagazineService.GetCurrentUser();

            SetCookie("currentUser", user.Email, true);

            if (RoleService.IsUserInRole(model.Email, "SuperAdmin"))
            {
                return(RedirectToAction("Index", "Magazines"));
            }

            if (RoleService.IsUserInRole(model.Email, "Admin"))
            {
                return(RedirectToAction("Index", "Magazines"));
            }

            if (RoleService.IsUserInRole(model.Email, "Influencer"))
            {
                return(RedirectToAction("Index", "Influencer"));
            }
            var editor = RoleService.IsUserInRole(model.Email, "Editor");

            if (RoleService.IsUserInRole(model.Email, "Editor"))
            {
                return(RedirectToAction("Index", "Magazines"));
            }

            if (!String.IsNullOrEmpty(returnUrl))
            {
                return(Redirect("/"));
            }

            return(Redirect(returnUrl));
        }