private void SetCurrentUserPrincipal(User user) { var principal = new GenericPrincipal(new GenericIdentity(user.UserName, "Basic"), user.Roles.Select(r => r.RoleName).ToArray()); Thread.CurrentPrincipal = principal; HttpContext.Current.User = principal; }
public bool CreateUser(User user, string password) { var hashedPassword = Crypto.HashPassword(password); user.HashedPassword = hashedPassword; _unitOfWork.UserRepository.Add(user); Save(); //if nothing happens, it must be successful return true; }
public void Can_Add_A_Record_To_The_Database() { //Arrange: var newUser = new User() {UserName = _randomString.NextString(10), HashedPassword = _randomString.NextString(10), Email= _randomString.NextString(20)}; //Act: _userRepo.Add(newUser); _unitOfWork.Commit(); //Assert: newUser.Id.Should(Be.GreaterThanOrEqualTo(1)); }
public string CreateLoginToken(User user) { string token = _tokenCreator.CreateToken(); user.AccessToken = token; return token; }
public void UpdateUser(User user) { _unitOfWork.UserRepository.Update(user); }
public void UpdateLastActivity(User user) { user.LastActivity = DateTime.Now; UpdateUser(user); Save(); }
public ActionResult Register(RegisterViewModel model) { if (ModelState.IsValid) { // Attempt to register the user var newUser = new User { UserName = model.UserName, Email = model.Email }; bool isUserCreated = _securityService.CreateUser(newUser, model.Password); if (isUserCreated) { FormsAuthentication.SetAuthCookie(model.UserName, createPersistentCookie: false); return RedirectToAction("Index", "Home"); } else { ModelState.AddModelError("", "Error Registering"); } } // If we got this far, something failed, redisplay form return View(model); }