Skip to content

Commit

Permalink
successfully added a user, and shown messaging related to that from u…
Browse files Browse the repository at this point in the history
…sermanagement screen
  • Loading branch information
surajcm committed Feb 1, 2024
1 parent 30500ea commit 7e7f7e2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import java.util.AbstractMap;
import java.util.Map;
Expand Down Expand Up @@ -155,8 +156,10 @@ public String createUser(final Model model) {
}

@PostMapping("/users/save")
public String saveUser(final User user) {
public String saveUser(final User user, final RedirectAttributes redirectAttributes) {
logger.info("Into the saveUser method, user is {}", user);
userService.save(user);
redirectAttributes.addFlashAttribute("message", "The user has been saved successfully");
return "redirect:/userManagement";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ public void save(final User user) {
logger.info("User last name is " + user.getLastName());
logger.info("password is " + pass);
user.setPassword(pass);
user.setEnabled(false);
//todo : this need to be corrected
//user.setRoles(new HashSet<>(roleRepository.findAll()));
userRepository.save(user);
}

Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/templates/user/usermanagement.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
<h2>Manage Users</h2>
<a th:href="@{/user/create}">Create New User</a>
</div>
<div th:if="${message != null}">
<div class="alert alert-success text-center" role="alert">
[[${message}]]
</div>
</div>
<div>
<form action="#" method="post">
</form>
Expand Down

0 comments on commit 7e7f7e2

Please sign in to comment.