public User UpdateUser(User user) { var existingUser = GetByUsername(user.UserName); if(existingUser != null) { existingUser = user; _context.SaveChanges(); } return existingUser; }
public User CreateUser(string username, byte[] passwordSalt, byte[] passwordHash, UserDetails userDetails) { var user = new User() { Hash = passwordHash, Salt = passwordSalt, UserName = username, IsAdmin = false, UserDetails = userDetails }; _context.Users.Add(user); _context.SaveChanges(); return user; }
private static FormsAuthenticationTicket CreateAuthenticationTicket(User user, bool isPersistent, HttpContextBase context) { var expirationDate = isPersistent ? DateTime.Now.AddDays(30) : DateTime.Now.AddMinutes( (context == null || context.Session == null) ? 20 : context.Session.Timeout); var ticket = new FormsAuthenticationTicket( 1, user.UserName, DateTime.Now, expirationDate, isPersistent, string.Empty); return ticket; }
public Response<User> UpdateUser(User user) { return new Response<User> { Entity = _userRepository.UpdateUser(user) }; }
public ActionResult Index(UserViewModel viewModel) { var login = _userService.Login(viewModel.Username, viewModel.Password); if(login.Success) { _authenticationService.LoginUser(login.Entity, HttpContext, false); CurrentUser = HttpContext.User as User; if(login.Entity.IsAdmin) { return RedirectToAction("Admin"); } return RedirectToAction("Profile"); } ModelState.AddModelError("username", login.Error.ToString()); return View(); }