|
@@ -64,6 +64,7 @@ class BugController(
|
|
|
@GetMapping(value = ["/reg"])
|
|
|
fun showRegister(model: Model): String {
|
|
|
val userRole = UserRole()
|
|
|
+ userRole.oldPass = "***"
|
|
|
model.addAttribute("userRole", userRole)
|
|
|
model.addAttribute("role", getRole())
|
|
|
return "reg"
|
|
@@ -235,23 +236,22 @@ class BugController(
|
|
|
|
|
|
@PostMapping(value = ["/saveUser"])
|
|
|
fun saveUserEdit(
|
|
|
- @ModelAttribute("userRole") userRole: UserRole,
|
|
|
+ @Valid @ModelAttribute("userRole") userRole: UserRole,
|
|
|
+ bindingResult: BindingResult,
|
|
|
redirectAttributes: RedirectAttributes,
|
|
|
model: Model
|
|
|
): String {
|
|
|
+ if (bindingResult.hasErrors()){
|
|
|
+ return "edit_user"
|
|
|
+ }
|
|
|
val existUser = userService[userRole.id]
|
|
|
val editUser = User()
|
|
|
editUser.id = existUser.id
|
|
|
editUser.username = userRole.username
|
|
|
editUser.password = existUser.password
|
|
|
- userRole.password = existUser.password
|
|
|
editUser.roles = userRole.role
|
|
|
editUser.isEnabled = true
|
|
|
model.addAttribute("role", getRole())
|
|
|
- if (userRole.username.isEmpty()) {
|
|
|
- redirectAttributes.addFlashAttribute("successMessage", "User Name tidak boleh kosong")
|
|
|
- return "redirect:/userList/edit/" + userRole.id
|
|
|
- }
|
|
|
userService.save(editUser)
|
|
|
redirectAttributes.addFlashAttribute("successMessage", "Success save user")
|
|
|
return "redirect:/userList"
|
|
@@ -259,10 +259,14 @@ class BugController(
|
|
|
|
|
|
@PostMapping(value = ["/saveChangePass"])
|
|
|
fun saveChangePass(
|
|
|
- @ModelAttribute("userRole") userRole: UserRole,
|
|
|
+ @Valid @ModelAttribute("userRole") userRole: UserRole,
|
|
|
+ bindingResult: BindingResult,
|
|
|
redirectAttributes: RedirectAttributes,
|
|
|
model: Model
|
|
|
): String {
|
|
|
+ if (bindingResult.hasErrors()) {
|
|
|
+ return "change_pass"
|
|
|
+ }
|
|
|
val existUser = userService[userRole.id]
|
|
|
val editUser = User()
|
|
|
editUser.id = userRole.id
|
|
@@ -272,11 +276,7 @@ class BugController(
|
|
|
editUser.isEnabled = true
|
|
|
val check = userService.checkIfValidOldPassword(userRole.oldPass, existUser.password)
|
|
|
if (!check) {
|
|
|
- redirectAttributes.addFlashAttribute("successMessage", "old password not match")
|
|
|
- return "redirect:/userList/chgPass/" + userRole.id
|
|
|
- } else if (userRole.password.isBlank()) {
|
|
|
- redirectAttributes.addFlashAttribute("successMessage", "Password tidak boleh kosong")
|
|
|
- return "redirect:/userList/chgPass/" + userRole.id
|
|
|
+ return "change_pass"
|
|
|
}
|
|
|
userService.save(editUser)
|
|
|
redirectAttributes.addFlashAttribute("successMessage", "Success save user")
|
|
@@ -326,6 +326,7 @@ class BugController(
|
|
|
userRole.username = user.username
|
|
|
userRole.password = user.password
|
|
|
userRole.role = user.roles
|
|
|
+ userRole.oldPass = "***"
|
|
|
mav.addObject("userRole", userRole)
|
|
|
mav.addObject("role", getRole())
|
|
|
return mav
|