|
@@ -7,7 +7,6 @@ import com.server.alb.services.ProjectService
|
|
|
import com.server.alb.services.UserService
|
|
|
import jakarta.servlet.http.HttpServletRequest
|
|
|
import jakarta.validation.Valid
|
|
|
-import jakarta.validation.Validator
|
|
|
import org.springframework.security.authentication.AnonymousAuthenticationToken
|
|
|
import org.springframework.security.core.Authentication
|
|
|
import org.springframework.security.core.context.SecurityContextHolder
|
|
@@ -31,8 +30,7 @@ class BugController(
|
|
|
private val bugService: BugService,
|
|
|
private val userService: UserService,
|
|
|
private val projectService: ProjectService,
|
|
|
- private val passwordEncoder: PasswordEncoder,
|
|
|
- private val validator: Validator
|
|
|
+ private val passwordEncoder: PasswordEncoder
|
|
|
) {
|
|
|
val qcResultType = Status.QCResultType.values()
|
|
|
val worList = Status.WorkedType.values()
|
|
@@ -81,7 +79,6 @@ class BugController(
|
|
|
newUser.password = passwordEncoder.encode(userRole.password)
|
|
|
newUser.roles = userRole.role
|
|
|
newUser.isEnabled = true
|
|
|
- println(newUser)
|
|
|
return if (bindingResult.hasErrors()) {
|
|
|
model.addAttribute("role", getRole())
|
|
|
"reg"
|
|
@@ -94,7 +91,10 @@ class BugController(
|
|
|
|
|
|
@RequestMapping(value = ["/userList"])
|
|
|
fun viewUser(model: Model): String {
|
|
|
+ val myUserDetails = SecurityContextHolder.getContext().authentication.name
|
|
|
+ val userLogin = userRepository.findByUsername(myUserDetails)
|
|
|
model.addAttribute("user", getUser())
|
|
|
+ model.addAttribute("user2", userService[userLogin.get().id])
|
|
|
return "userList"
|
|
|
}
|
|
|
|
|
@@ -119,7 +119,6 @@ class BugController(
|
|
|
model: Model,
|
|
|
): String {
|
|
|
return if (bindingResult.hasErrors()) {
|
|
|
- println(project)
|
|
|
"add_proj"
|
|
|
} else {
|
|
|
projectRepository.save(project)
|
|
@@ -186,7 +185,6 @@ class BugController(
|
|
|
bug.qcId = userLogin.get()
|
|
|
}
|
|
|
}
|
|
|
- println(bug)
|
|
|
return if (bindingResult.hasErrors()) {
|
|
|
model.addAttribute("user", getUser())
|
|
|
model.addAttribute("platform", getPlatform())
|
|
@@ -210,7 +208,6 @@ class BugController(
|
|
|
): String {
|
|
|
val referer: String = request.getHeader("Referer")
|
|
|
val url = referer.split("=")
|
|
|
- val url2 = referer.split("8080/")
|
|
|
if (bug.qcId == null) {
|
|
|
val myUserDetails = SecurityContextHolder.getContext().authentication.name
|
|
|
val userLogin = userRepository.findByUsername(myUserDetails)
|
|
@@ -219,7 +216,6 @@ class BugController(
|
|
|
}
|
|
|
}
|
|
|
return if (bindingResult.hasErrors()) {
|
|
|
- println(bug)
|
|
|
model.addAttribute("listQc", getUser())
|
|
|
model.addAttribute("listPro", getUser())
|
|
|
model.addAttribute("platform", getPlatform())
|
|
@@ -229,7 +225,7 @@ class BugController(
|
|
|
model.addAttribute("dStList", dStList)
|
|
|
model.addAttribute("qcResultType", qcResultType)
|
|
|
redirectAttributes.addFlashAttribute("successMessage", "invalid value")
|
|
|
- "redirect:/" + url2.last()
|
|
|
+ "edit_bug"
|
|
|
} else {
|
|
|
bugService.save(bug)
|
|
|
redirectAttributes.addFlashAttribute("successMessage", "Success save bug")
|
|
@@ -239,29 +235,51 @@ class BugController(
|
|
|
|
|
|
@PostMapping(value = ["/saveUser"])
|
|
|
fun saveUserEdit(
|
|
|
- @Valid @ModelAttribute("userRole") userRole: UserRole,
|
|
|
- bindingResult: BindingResult,
|
|
|
+ @ModelAttribute("userRole") userRole: UserRole,
|
|
|
redirectAttributes: RedirectAttributes,
|
|
|
model: Model
|
|
|
): String {
|
|
|
val existUser = userService[userRole.id]
|
|
|
val editUser = User()
|
|
|
- editUser.id = userRole.id
|
|
|
+ editUser.id = existUser.id
|
|
|
editUser.username = userRole.username
|
|
|
- editUser.password = passwordEncoder.encode(userRole.password)
|
|
|
+ editUser.password = existUser.password
|
|
|
+ userRole.password = existUser.password
|
|
|
editUser.roles = userRole.role
|
|
|
editUser.isEnabled = true
|
|
|
- println(editUser)
|
|
|
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"
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping(value = ["/saveChangePass"])
|
|
|
+ fun saveChangePass(
|
|
|
+ @ModelAttribute("userRole") userRole: UserRole,
|
|
|
+ redirectAttributes: RedirectAttributes,
|
|
|
+ model: Model
|
|
|
+ ): String {
|
|
|
+ val existUser = userService[userRole.id]
|
|
|
+ val editUser = User()
|
|
|
+ editUser.id = userRole.id
|
|
|
+ editUser.username = existUser.username
|
|
|
+ editUser.password = passwordEncoder.encode(userRole.password)
|
|
|
+ editUser.roles = existUser.roles
|
|
|
+ editUser.isEnabled = true
|
|
|
val check = userService.checkIfValidOldPassword(userRole.oldPass, existUser.password)
|
|
|
if (!check) {
|
|
|
redirectAttributes.addFlashAttribute("successMessage", "old password not match")
|
|
|
- return "redirect:/userList/edit/" + editUser.id
|
|
|
- } else if (bindingResult.hasErrors()) {
|
|
|
- redirectAttributes.addFlashAttribute("successMessage", "invalid value")
|
|
|
- return "redirect:/userList/edit/" + editUser.id
|
|
|
+ return "redirect:/userList/chgPass/" + userRole.id
|
|
|
+ } else if (userRole.password.isBlank()) {
|
|
|
+ redirectAttributes.addFlashAttribute("successMessage", "Password tidak boleh kosong")
|
|
|
+ return "redirect:/userList/chgPass/" + userRole.id
|
|
|
}
|
|
|
userService.save(editUser)
|
|
|
+ redirectAttributes.addFlashAttribute("successMessage", "Success save user")
|
|
|
return "redirect:/userList"
|
|
|
}
|
|
|
|
|
@@ -273,9 +291,8 @@ class BugController(
|
|
|
model: Model
|
|
|
): String {
|
|
|
return if (bindingResult.hasErrors()) {
|
|
|
- println(project)
|
|
|
redirectAttributes.addFlashAttribute("successMessage", "invalid value")
|
|
|
- "redirect:/proj/edit/" + project.id
|
|
|
+ "edit_proj"
|
|
|
} else {
|
|
|
projectService.save(project)
|
|
|
"redirect:/proj"
|
|
@@ -303,8 +320,22 @@ class BugController(
|
|
|
@GetMapping("/userList/edit/{id}")
|
|
|
fun editUser(@PathVariable(name = "id") id: Long): ModelAndView {
|
|
|
val mav = ModelAndView("edit_user")
|
|
|
+ val userRole = UserRole()
|
|
|
val user: User = userService[id]
|
|
|
+ userRole.id = user.id
|
|
|
+ userRole.username = user.username
|
|
|
+ userRole.password = user.password
|
|
|
+ userRole.role = user.roles
|
|
|
+ mav.addObject("userRole", userRole)
|
|
|
+ mav.addObject("role", getRole())
|
|
|
+ return mav
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/userList/chgPass/{id}")
|
|
|
+ fun changePass(@PathVariable(name = "id") id: Long): ModelAndView {
|
|
|
+ val mav = ModelAndView("change_pass")
|
|
|
val userRole = UserRole()
|
|
|
+ val user: User = userService[id]
|
|
|
userRole.id = user.id
|
|
|
userRole.username = user.username
|
|
|
userRole.password = user.password
|
|
@@ -315,7 +346,9 @@ class BugController(
|
|
|
}
|
|
|
|
|
|
@GetMapping("/proj/edit/{id}")
|
|
|
- fun editProject(@PathVariable(name = "id") id: Long): ModelAndView {
|
|
|
+ fun editProject(
|
|
|
+ @PathVariable(name = "id") id: Long//, @ModelAttribute("project") project: Project
|
|
|
+ ): ModelAndView {
|
|
|
val mav = ModelAndView("edit_proj")
|
|
|
val project: Project = projectService[id]
|
|
|
mav.addObject("project", project)
|