Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [HttpPost]
- [ValidateAntiForgeryToken]
- public async Task<IActionResult> Login(UserData credentials)
- {
- if (credentials.Password == null || credentials.Username == null)
- {
- ViewBag.LoginFailed = "Something went wrong. Please try again.";
- return View("LoginForm");
- }
- else
- if (DBClases.Login.VerifyLogin(credentials))
- {
- #region Claims
- List<Claim> claims = new List<Claim>
- {
- new Claim(ClaimTypes.Name, credentials.Username),
- new Claim(ClaimTypes.SerialNumber, credentials.Id.ToString())
- };
- ClaimsIdentity identity = new ClaimsIdentity(claims, "cookie");
- ClaimsPrincipal principal = new ClaimsPrincipal(identity);
- await HttpContext.SignInAsync(
- scheme: "SnippetManager",
- principal: principal,
- properties: new AuthenticationProperties
- {
- });
- #endregion
- return base.RedirectToAction("Index", "Home");
- }
- else
- {
- return base.View("LoginForm");
- }
- }
- //#####Ce e mai sus am in "AccountControler" la functia de login#####//
- public void ConfigureServices(IServiceCollection services)
- {
- services.AddAuthentication("SnippetManager")
- .AddCookie("SnippetManager", options =>
- {
- options.Cookie = new CookieBuilder
- {
- HttpOnly = true,
- Name = "Snippet.Manager.Cookie",
- Path = "/",
- SameSite = SameSiteMode.Strict,
- SecurePolicy = CookieSecurePolicy.SameAsRequest
- };
- options.SlidingExpiration = true;
- options.LoginPath = new PathString("/Account/Login");
- options.LogoutPath = new PathString("/Account/Login");
- options.ReturnUrlParameter = "ReturnUrl";
- });
- services.AddMvc(/*options => {options.Filters.Add<CustomAuthentication>();}*/);
- }
- //#####Ce e mai sus am in Starup.cs####//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement