public ActionResult Edit(int id, User userFromForm)
        {
            if (ModelState.IsValid) {
            var user = _userTasks.UpdateUser(id, userFromForm);

            TempData["SuccessMessage"] = string.Format("{0} has been updated", user.Email);
            return RedirectToAction("Index");
              }
              return View(userFromForm);
        }
 private static AccountTasks GetAccountServiceWithValidUser()
 {
     var userRepositoryMock = new Mock<IUserRepository>();
       var myUser = new User {
     Username = "******",
     Email = "*****@*****.**",
     Disabled = false,
     PasswordHash = "$2a$12$h0qgj3gpg4939GulaP6yPuBeuaWGlwZq0aiq1atMGpkxZ.XVWZEhe",
     PasswordSalt = "$2a$12$h0qgj3gpg4939GulaP6yPu",
       };
       userRepositoryMock.Setup(x => x.Get("*****@*****.**")).Returns(myUser);
       var accountService = new AccountTasks(UnitOfWorkMock.Create(), userRepositoryMock.Object);
       return accountService;
 }
Beispiel #3
0
        public User UpdateUser(int id, User userFromForm)
        {
            var user = _userRepository.Get(id);
              user.Username = userFromForm.Username;
              user.Email = userFromForm.Email;
              user.UserRole = userFromForm.UserRole;
              user.Comment = userFromForm.Comment;
              user.Disabled = userFromForm.Disabled;
              user.Agreement = userFromForm.Agreement;
              user.PasswordNeedsUpdating = userFromForm.PasswordNeedsUpdating;

              _unitOfWork.Commit();

              return user;
        }
        public void AuthenticateUser_DisabledUser_ReturnsAccountDisabled()
        {
            var userRepositoryMock = new Mock<IUserRepository>();
              var disabledUser = new User {
            Username = "******",
            Email = "*****@*****.**",
            Disabled = true,
            PasswordHash = "$2a$12$h0qgj3gpg4939GulaP6yPuBeuaWGlwZq0aiq1atMGpkxZ.XVWZEhe",
            PasswordSalt = "$2a$12$h0qgj3gpg4939GulaP6yPu"
              };
              userRepositoryMock.Setup(x => x.Get("*****@*****.**")).Returns(disabledUser);
              var accountService = new AccountTasks(UnitOfWorkMock.Create(), userRepositoryMock.Object);

              var result = accountService.AuthenticateUser("*****@*****.**", "jzs3qv7d");

              // assert
              Assert.AreEqual(AccountTasks.AuthenticationResult.AccountDisabled, result);
        }
Beispiel #5
0
        public RegisterUserResult RegisterUser(string username, string email)
        {
            // check if username is available
              if (_userRepository.GetAll().SingleOrDefault(x => x.Username == username) != null)
            return new RegisterUserResult() {RegistrationRequestResult = RegistrationRequestResult.UsernameTaken};
              if (_userRepository.GetAll().SingleOrDefault(x => x.Email == email) != null)
            return new RegisterUserResult() {RegistrationRequestResult = RegistrationRequestResult.EmailRegistered};

              // check if email has been registered
              var password = GeneratePassword(8);
              string passwordSalt = BCryptHelper.GenerateSalt(12);
              var user = new User
              {
            Username = username,
            Email = email,
            DateCreated = DateTime.Now,
            PasswordHash = BCryptHelper.HashPassword(password, passwordSalt),
            PasswordSalt = passwordSalt,
            DateLastPasswordChange = DateTime.Now,
            PasswordNeedsUpdating = true
              };
              // save
              _userRepository.Add(user);
              _unitOfWork.Commit();
              return new RegisterUserResult()
              {
            TempPassword = password,
            RegistrationRequestResult = RegistrationRequestResult.Success
              };
        }