Exemple #1
0
        //[ValidateAntiForgeryToken]
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            //ReturnUrl = returnUrl;

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var user = await Authentification.AuthenticateUser(_userManager, LoginInfo.UserName, LoginInfo.Password);

            if (user == null)
            {
                ModelState.AddModelError("", "Invalid logging attempt");
                return(Page());
            }


            var claims = new List <Claim>
            {
                new Claim(ClaimTypes.Name, user.UserName)
            };

            var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);

            await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme,
                                          new ClaimsPrincipal(claimsIdentity));

            if (String.IsNullOrWhiteSpace(returnUrl))
            {
                return(LocalRedirect("/Success?op=Login"));
            }
            else
            {
                return(LocalRedirect(Url.GetLocalUrl(returnUrl)));
            }
        }