Ejemplo n.º 1
0
        public HttpCookie CreateFormsAuthenticationCookie(OpenIdUser user)
        {
            Random rand      = new Random();
            int    randomInt = rand.Next(0, int.MaxValue);
            string hashValue = MD5Encryptor.GetHash(randomInt.ToString());

            using (CookiesRepository cookiesRep = new CookiesRepository())
            {
                Cooky existingCookie = cookiesRep.GetList().FirstOrDefault(x => x.UserId == user.UserId);

                if (existingCookie != null)
                {
                    if (cookiesRep.Delete(existingCookie.Id) == false)
                    {
                        return(null);
                    }
                }
                Cooky newCookie = new Cooky()
                {
                    UserId    = user.UserId,
                    HashValue = hashValue
                };

                if (cookiesRep.Create(newCookie) == false)
                {
                    return(null);
                }
            }

            //var ticket = new FormsAuthenticationTicket(1, user.FullName, DateTime.Now, DateTime.Now.AddDays(7), true, user.GetCookieString(hashValue));
            //var encrypted = FormsAuthentication.Encrypt(ticket).ToString();
            var cookie = new HttpCookie(LOGIN_COOKIE_NAME, user.GetCookieString(hashValue));

            return(cookie);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Cooky cooky = db.Cookies.Find(id);

            db.Cookies.Remove(cooky);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "Id,Item,Description,Price")] Cooky cooky)
 {
     if (ModelState.IsValid)
     {
         db.Entry(cooky).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(cooky));
 }
        public ActionResult Create([Bind(Include = "Id,Item,Description,Price")] Cooky cooky)
        {
            if (ModelState.IsValid)
            {
                db.Cookies.Add(cooky);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(cooky));
        }
        // GET: Cookies/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Cooky cooky = db.Cookies.Find(id);

            if (cooky == null)
            {
                return(HttpNotFound());
            }
            return(View(cooky));
        }
Ejemplo n.º 6
0
        public ActionResult DeleteConfirmed(int id)
        {
            if (Authorized(RoleType.SystemManager))
            {
                User user;
                using (CookiesRepository cookieRep = new CookiesRepository())
                    using (UsersRepository userRep = new UsersRepository(CurrentUser.CompanyId))
                    {
                        user = userRep.GetEntity(id);

                        if (user == null)
                        {
                            return(Error(Loc.Dic.error_user_not_found));
                        }
                        if (user.Id == CurrentUser.UserId)
                        {
                            return(Error(Loc.Dic.error_user_cannot_delete_self));
                        }
                        if (user.CompanyId != CurrentUser.CompanyId || user.Roles == (int)RoleType.SuperAdmin)
                        {
                            return(Error(Loc.Dic.error_no_permission));
                        }

                        user.IsActive = false;
                        userRep.Update(user);

                        Cooky expiredCookie = cookieRep.GetList().SingleOrDefault(x => x.UserId == user.Id);
                        if (expiredCookie != null)
                        {
                            cookieRep.Delete(expiredCookie.Id);
                        }
                    }

                return(RedirectToAction("Index"));
            }
            else
            {
                return(Error(Loc.Dic.error_no_permission));
            }
        }