Ejemplo n.º 1
0
        public static MvcHtmlString ImageHelper(this HtmlHelper helper, int imageId, UrlHelper urlHelper)
        {
            var image = TechbartRepository.GetImageRepository().GetImage(imageId);

            var tagBuilder = new TagBuilder("img");

            tagBuilder.Attributes["src"] = urlHelper.Content(image.ImagePath);

            tagBuilder.Attributes["alt"] = image.ImageName;

            tagBuilder.Attributes["title"] = image.ImageName;

            return(new MvcHtmlString(tagBuilder.ToString()));
        }
Ejemplo n.º 2
0
        public bool Login(Controllers.LoginModel loginModel)
        {
            var customer = TechbartRepository.GetCustomerRepository().GetCustomer(loginModel.Email, loginModel.Password) as Customer;

            if (customer == null)
            {
                return(false);
            }
            var roles = customer.GetRoles();

            if (roles == null || !roles.Contains("Admin"))
            {
                return(false);
            }

            string userData = string.Join("|", roles);

            // Create ticket
            var ticket = new FormsAuthenticationTicket(
                1,
                customer.Email,
                DateTime.Now,
                DateTime.Now.AddMinutes(120),
                false,
                userData,
                FormsAuthentication.FormsCookiePath);

            // Encrypt the ticket
            var encTicket = FormsAuthentication.Encrypt(ticket);

            // Create the cookie.
            HttpCookie faCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);

            faCookie.HttpOnly = true;
            HttpContext.Current.Response.Cookies.Add(faCookie);

            return(true);
        }