コード例 #1
0
        public ActionResult Login(LoginModel loginModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var user = LoginMapper.GetMVCEntity(login.Login(loginModel.MailOrLogin, loginModel.Password));
                    FormsAuthentication.SetAuthCookie(user.Login, true);
                    return(RedirectToRoute("Home"));
                }
                catch (Exception e)
                {
                    ModelState.AddModelError(e.Message, e.Message);
                }
            }

            string errorMessage = GetModelStateErrors(ModelState);

            if (Request.IsAjaxRequest())
            {
                return(Json(new { Result = errorMessage }));
            }
            return(View());
        }
コード例 #2
0
        public IActionResult Login()
        {
            var model = new LoginModel();

            return(View(model));
        }