예제 #1
0
        public ActionResult Edit(User userFromForm)
        {
            var userToUpdate = _userRepository.Find(userFromForm.Id);

              userToUpdate.Email = userFromForm.Email;
              userToUpdate.Name = userFromForm.Name;
              userToUpdate.Comment = userFromForm.Comment;

              if (ModelState.IsValid) {
            _userRepository.InsertOrUpdate(userToUpdate);
            _userRepository.Save();
            return RedirectToAction("Index");
              }
              else {
            return View(userToUpdate);
              }
        }
예제 #2
0
        private User SetNewPassword(User user, string password)
        {
            var passwordSalt = BCryptHelper.GenerateSalt(12);
            var passwordHash = BCryptHelper.HashPassword(password, passwordSalt);

            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;
            user.DateLastPasswordChange = DateTime.Now;

            return user;
        }
예제 #3
0
        public RegisterUserViewModel RegisterUser(User user)
        {
            var viewModel = new RegisterUserViewModel();

            viewModel.User = user;

            // check if email exists
            if (GetByEmail(user.Email) != null) {
              viewModel.HasError = true;
              viewModel.Message = "Email address is already in use";

              return viewModel;
            }

            viewModel.GeneratedPassword = GeneratePassword(8);

            viewModel.User = SetNewPassword(viewModel.User, viewModel.GeneratedPassword);

            viewModel.User.PasswordNeedsUpdating = true;
            viewModel.User.DateCreated = DateTime.Now;
            viewModel.User.DateLastActivity = DateTime.Now;
            viewModel.User.DateLastLogin = DateTime.Now;
            viewModel.User.DateLastPasswordChange = DateTime.Now;

            context.Users.Add(viewModel.User);
            context.SaveChanges();

            return viewModel;
        }
예제 #4
0
 public void InsertOrUpdate(User user)
 {
     if (user.Id == default(int)) {
         // New entity
         context.Users.Add(user);
     } else {
         // Existing entity
         context.Entry(user).State = EntityState.Modified;
     }
 }
예제 #5
0
        public ActionResult Register(User user)
        {
            var userDto = _userRepository.RegisterUser(user);

              if (ModelState.IsValid) {
            if (!userDto.HasError) {
              // SEND EMAIL TO USER
              var siteroot = string.Format("{0}{1}", Request.DomainApplicationPath().TrimEnd('/'),
                                       Url.Action("ChangePassword", "Account"));

              _userMailer.Welcome(userDto.User.Name, userDto.User.Email, userDto.GeneratedPassword, siteroot).Send();

              TempData["SuccessMessage"] = "The user was successfully registered.";
              return RedirectToAction("Edit", new {id = userDto.User.Id});

            }
            ViewData.ModelState.AddModelError("_FORM", userDto.Message);

              }
              userDto.User = user;

              //MvcValidationAdapter.TransferValidationMessagesTo(ViewData.ModelState, userDto.User.ValidationResults());

              return View(userDto.User);
        }