예제 #1
0
        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);
        }
        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 IndexActionReturnsIndexView()
        {
            string expected = "Index";
            HomeController controller = new HomeController();

            LoginModel log = new LoginModel();
            log.EmailId = "*****@*****.**";
            log.Password = "******";

            var result = controller.LogOn(log) as ViewResult;

            Assert.AreEqual(expected, result);
        }
예제 #4
0
 public ActionResult LogOn(LoginModel model)
 {
     if (ModelState.IsValid)
     {
         if (model.IsUserExist(model.EmailId, model.Password))
         {
             FormsAuthentication.RedirectFromLoginPage(model.EmailId, false);
         }
         else
         {
             ModelState.AddModelError("", "EmailId or Password Incorrect.");
         }
     }
     return View(model);
 }
예제 #5
0
        public JsonResult JsonLogin(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                    return Json(new { success = true, redirect = returnUrl });
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            // If we got this far, something failed
            return Json(new { errors = GetErrorsFromModelState() });
        }
예제 #6
0
        public HttpResponseMessage PostLogIn(LoginModel log)
        {
            if (log.EmailId == null || log.Password == null)
                return this.Request.CreateResponse(HttpStatusCode.BadRequest);

            try
            {
                // check if credentials are valid
                String decodedUsername = Encoding.UTF8.GetString(Convert.FromBase64String(log.EmailId));
                String decodedPassword = Encoding.UTF8.GetString(Convert.FromBase64String(log.Password));
                if (!PictogramsDb.IsUserExist(decodedUsername, decodedPassword))
                {
                    return new HttpResponseMessage(HttpStatusCode.Unauthorized);
                }
            }
            catch (FormatException e)
            {
                return this.Request.CreateResponse(HttpStatusCode.BadRequest, "Parâmetros não foram bem formatados");
            }
            return new HttpResponseMessage(HttpStatusCode.OK);
        }
        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);
        }
예제 #8
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
            {
                return RedirectToLocal(returnUrl);
            }

            // Si llegamos a este punto, es que se ha producido un error y volvemos a mostrar el formulario
            ModelState.AddModelError("", "El nombre de usuario o la contraseña especificados son incorrectos.");
            return View(model);
        }
예제 #9
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);
        }
예제 #10
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
            {
                return RedirectToLocal(returnUrl);
            }

            // Se si arriva a questo punto, significa che si è verificato un errore, rivisualizzare il form
            ModelState.AddModelError("", "Il nome utente o la password fornita non è corretta.");
            return View(model);
        }