public ActionResult Login(Login login) { // UserStore and UserManager manages data retreival. UserStore<IdentityUser> userStore = new UserStore<IdentityUser>(); UserManager<IdentityUser> manager = new UserManager<IdentityUser>(userStore); IdentityUser identityUser = manager.Find(login.UserName, login.Password); TempData["Login"] = login; if (ModelState.IsValid) { AccountRepo accountRepo = new AccountRepo(); if (accountRepo.ValidLogin(login)) { IAuthenticationManager authenticationManager = HttpContext.GetOwinContext().Authentication; authenticationManager .SignOut(DefaultAuthenticationTypes.ExternalCookie); var identity = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, login.UserName), }, DefaultAuthenticationTypes.ApplicationCookie, ClaimTypes.Name, ClaimTypes.Role); // SignIn() accepts ClaimsIdentity and issues logged in cookie. authenticationManager.SignIn(new AuthenticationProperties { IsPersistent = false }, identity); if (identityUser.Roles.Count == 1) { return RedirectToAction("AdminOnly", "Account"); } if (identityUser.Roles.Count == 0) { return RedirectToAction("UserArea", "Account"); } } } return View(); }
public ActionResult Update(RegisteredUser registeredUser) { AccountRepo accountRepo = new AccountRepo(); accountRepo.UpdateUser(registeredUser.TelNumber, registeredUser.UserName); return View(); }
public ActionResult ProfileDetails() { AccountRepo accountRepo = new AccountRepo(); var login = TempData["Login"]; RegisteredUser aspNetUser = accountRepo.GetProfileDetail((Login)login); return PartialView("_ProfileDetails",aspNetUser); }
public ActionResult UserArea() { AccountRepo accountRepo = new AccountRepo(); var login = TempData["Login"]; TempData["orders"] = db.OrderDetails.ToList(); TempData["profile"] = accountRepo.GetProfileDetail((Login)login); return View(); }