Пример #1
0
 public ActionResult Login(LoginModel model, string returnUrl = "~/Books/")
 {
     if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe)) {
         return RedirectToLocal(returnUrl);
     }
     ModelState.AddModelError("", "Имя пользователя или пароль указаны неверно.");
     return View(model);
 }
Пример #2
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
            {
                return RedirectToLocal(returnUrl);
            }

            // If we got this far, something failed, redisplay form
            ModelState.AddModelError("", "The user name or password provided is incorrect.");
            return View(model);
        }
Пример #3
0
        public ActionResult LoginPost(LoginModel user, string returnUrl)
        {
            // Byte[] a = EncryptPassword(user.Password);
            //string tmppwd = System.Web.Helpers.Crypto.HashPassword(user.Password);

               User resultUser = db.User.Where(u => (u.Email == user.Email)).FirstOrDefault();

               bool verifyPassword = Crypto.VerifyHashedPassword(resultUser.pword, user.Password);
            if (!verifyPassword)
            {
                // If we got this far, something failed, redisplay form
                ModelState.AddModelError("", "The Email or Password provided is incorrect.");
                return View(user);
            }
            //HttpContext.User= new System.Web.Security.RolePrincipal();
            FormsAuthentication.SetAuthCookie(resultUser.Email, false);
            var role = Roles.GetRolesForUser(user.Email);
            if (role == null)
            {
                System.Web.Security.Roles.AddUsersToRole(new String[] { user.Email }, resultUser.Securitylevel);
            }
            return RedirectToLocal(returnUrl);
        }