Пример #1
0
        public ActionResult Login(User model)
        {
            if (ModelState.IsValid)
            {
                // поиск пользователя в бд
                User         user     = null;
                UserSecurity security = new UserSecurity();
                string       pass     = security.CalculateMD5Hash(model.UserPassword);
                using (db)
                {
                    user = db.Users.FirstOrDefault(u => ((u.UserName == model.UserName || u.UserEmail == model.UserName) && pass == u.UserPassword));
                }
                if (user != null)
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, true);
                    Repository.CurrentUser = user;
                    return(RedirectToAction("CheckLists", "CheckLists")); //todo заменить на админпанель когда она будет
                }
                else
                {
                    ModelState.AddModelError("", "Пользователя с таким логином и паролем нет");
                }
            }

            return(View(model));
        }
Пример #2
0
 public ActionResult Edit([Bind(Include = "UserId,UserName,UserEmail,UserPassword,UserAdmin,UserTestCreator,UserTestExecutor")] User user)
 {
     if (ModelState.IsValid)
     {
         UserSecurity security = new UserSecurity();
         user.UserPassword    = security.CalculateMD5Hash(user.UserPassword);
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(user));
 }