public ActionResult Register(RegisterVM model) { if (ModelState.IsValid) { UserManager userManager = UserManager.Create(_dal.Database.GetConnectionString()); UserManageResult userManagerResult = userManager.CreateUser(model.EmailAddress, model.Password.Secure()); if (userManagerResult.Success) { userManager.AddClaim("http://21brews.com/identity/claims/account-state", "registered"); ClaimsPrincipal userPrincipal = SignInManager.Create(userManager).CreateUserPrincipal(userManager.User); HttpContext.SignInAsync( CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(userPrincipal)); //HttpContext.User = new ClaimsPrincipal(userPrincipal); //FormsAuthentication.SetAuthCookie(userPrincipal.Identity.Name, false); //HttpContext.User = userPrincipal; //if (!_dal.Profiles.Any(x => x.Id == userPrincipal.Identity.Name)) // return RedirectToAction("", "Profile"); return(RedirectToAction("", "")); } //addErrors(userManagerResult); } return(View(model)); }
public async Task <IActionResult> Login(LoginVM model, string returnUrl) { if (!ModelState.IsValid) { return(View(model)); } UserManager userManager = UserManager.Create(_dal.Database.GetConnectionString()); SignInManager signInManager = SignInManager.Create(userManager); // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, change to shouldLockout: true SignInResult signInResult = signInManager.PasswordSignIn(model.EmailAddress, model.Password.Secure(), false); if (signInResult.Succeeded) { ClaimsPrincipal userPrincipal = signInManager.CreateUserPrincipal(userManager.User); await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, userPrincipal); return(redirectToLocal(returnUrl)); } if (signInResult.IsLockedOut) { return(View("Lockout")); } ModelState.AddModelError("", "Invalid Username or Password"); return(View(model)); }
public ManageController() { _userManager = GebruikerManager.Create(System.Web.HttpContext.Current.GetOwinContext().Get <AppBuilderProvider>().Get().GetDataProtectionProvider()); // AppbuilerProvider is een custom klasse die geregistreerd wordt in de startup.auth.cs _signInManager = SignInManager.Create(_userManager, System.Web.HttpContext.Current.GetOwinContext()); }