コード例 #1
0
        public ViewResult LogIn(string returnUrl)
        {
            LogInViewModel model = new LogInViewModel
            {
                ReturnUrl = returnUrl,
                LoginProviders = AuthenticationManager.GetExternalAuthenticationTypes()
            };

            return View(model);
        }
コード例 #2
0
        public async Task<ActionResult> LogIn(LogInViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            UserIntPK user = await userManager.FindAsync(model.Email, model.Password);
            if(user == null)
            {
                ModelState.AddModelError("", "Не правильный адрес эл. почты или пароль.");
            }
            else
            {
                ClaimsIdentity claim = await userManager.CreateIdentityAsync(user,
                                            DefaultAuthenticationTypes.ApplicationCookie);
                AuthenticationManager.SignOut();
                AuthenticationManager.SignIn(claim);
            }
                return Json(new { Url = GetRedirectUrl(model.ReturnUrl) });

        }