Exemplo n.º 1
0
        public async Task<ActionResult> Login(LoginModel model)
        {
            if (ModelState.IsValid)
            {
                SmsServiceUser user = await Usermanager.FindAsync(model.Login, model.Password);
                if (user == null)
                {
                    ModelState.AddModelError(String.Empty, "Неверный логин или пароль");
                }
                else
                {
                    ClaimsIdentity claims =
                        await Usermanager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);
                    AuthenticationManager.SignOut();
                    AuthenticationManager.SignIn(new AuthenticationProperties
                    {
                        IsPersistent = true
                    }, claims);

                    
                    //if (Request.UrlReferrer != null) return Redirect(Request.UrlReferrer.ToString());
                    
                    return RedirectToAction("Index", "Home");
                }
            }

            return View(model);
        }
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (Membership.ValidateUser(model.UserName, model.Password))
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                    if (Url.IsLocalUrl(returnUrl))
                    {
                        return Redirect(returnUrl);
                    }
                    else
                    {
                        return RedirectToAction("Index", "Home");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Exemplo n.º 3
0
        public ActionResult Login(LoginModel user, string returnUrl)
        {
            try
            {
                if (ModelState.IsValid && membership.ValidateUser(user.Login, user.Password))
                {
                    FormsAuthentication.SetAuthCookie(user.Login, true);

                    if (Url.IsLocalUrl(returnUrl))
                        return Redirect(returnUrl);
                    else
                        return RedirectToAction("Index", "Test");
                }
                else
                    ModelState.AddModelError("", "Invalid username or password");

                return View();
            }
            catch(AccountException acc)
            {
                ModelState.AddModelError("", acc.Message);
            }

            return View();
        }
Exemplo n.º 4
0
 public void Login(LoginModel model)
 {
     Employee employee = _repository.GetByUserName(model.UserName);
     _session.LogIn(employee);
 }
Exemplo n.º 5
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);
        }
 public void Login(LoginModel model)
 {
     Employee employee = _bus.Send(new EmployeeByUserNameQuery(model.UserName)).Result;
     _session.LogIn(employee);
 }
Exemplo n.º 7
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
            {
                return RedirectToLocal(returnUrl);
            }

            // 如果我们进行到这一步时某个地方出错,则重新显示表单
            ModelState.AddModelError("", "提供的用户名或密码不正确。");
            return View(model);
        }