Demo entry 6732850



Submitted by anonymous on Apr 15, 2018 at 21:27
Language: C#. Code size: 1.0 kB.

        [HttpPost, AllowAnonymous, ValidateAntiForgeryToken]
        public async Task<IActionResult> LoginAsync(string returnUrl, LoginViewModel model)
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid && _userServices.ValidateUser(model.UserName, model.Password))
                var identity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme);
                identity.AddClaim(new Claim(ClaimTypes.Name, model.UserName));

                var principle = new ClaimsPrincipal(identity);
                var properties = new AuthenticationProperties {IsPersistent = model.RememberMe};
                await HttpContext.SignInAsync(principle, properties);

                return LocalRedirect(returnUrl ?? "/");

            ModelState.AddModelError(string.Empty, "Username or password is invalid.");
            return View("Login", model);

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).