| 
					
				 | 
			
			
				@@ -3,12 +3,10 @@ package com.server.alb.controllers 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.server.alb.models.* 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.server.alb.repositories.* 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.server.alb.services.BugService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.server.alb.services.BugValidationService.Companion.isValid 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 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 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -32,13 +30,13 @@ 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() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     val wStList = Status.WorkedStatusType.values() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     val dStList = Status.DevStatusType.values() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    var global:String = "" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private fun getProject(): MutableList<Project> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return this.projectRepository.findAll() 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -67,6 +65,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" 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -82,7 +81,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" 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -95,7 +93,11 @@ class BugController( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @RequestMapping(value = ["/userList"]) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     fun viewUser(model: Model): String { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        val myUserDetails = SecurityContextHolder.getContext().authentication.name 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        val userLogin = userRepository.findByUsername(myUserDetails) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        val user2 = userService[userLogin.get().id] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         model.addAttribute("user", getUser()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        model.addAttribute("user2", user2) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return "userList" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -120,7 +122,6 @@ class BugController( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         model: Model, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     ): String { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return if (bindingResult.hasErrors()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            println(project) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             "add_proj" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             projectRepository.save(project) 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -187,8 +188,6 @@ class BugController( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 bug.qcId = userLogin.get() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        println(bug) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        println(bindingResult) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return if (bindingResult.hasErrors()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             model.addAttribute("user", getUser()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             model.addAttribute("platform", getPlatform()) 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -202,34 +201,37 @@ class BugController( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    @RequestMapping(value = ["/save"], method = [RequestMethod.POST]) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @PostMapping(value = ["/save"]) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     fun saveBug( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         @Valid @ModelAttribute("bug") bug: ListBug, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        bindingResult: BindingResult, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         redirectAttributes: RedirectAttributes, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        result: BindingResult, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        request: HttpServletRequest, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        httpServletRequest: HttpServletRequest, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        @RequestParam page: String, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        model: Model, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     ): String { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        val referer: String = request.getHeader("Referer") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        val url = referer.split("=") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (bug.qcId == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            val myUserDetails = SecurityContextHolder.getContext().authentication.name 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            val userLogin = userRepository.findByUsername(myUserDetails) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (userLogin.isPresent) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                bug.qcId = userLogin.get() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        val successMessage: String = if (isValid(bug)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            bugService.save(bug) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            "Success save bug" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            "Failed ! Please try again" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (bindingResult.hasErrors()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            model.addAttribute("listQc", getUser()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            model.addAttribute("listPro", getUser()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            model.addAttribute("platform", getPlatform()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            model.addAttribute("bug", bug) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            model.addAttribute("worList", worList) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            model.addAttribute("wStList", wStList) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            model.addAttribute("dStList", dStList) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            model.addAttribute("qcResultType", qcResultType) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return "edit_bug" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        redirectAttributes.addFlashAttribute("successMessage", successMessage) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return if (referer.endsWith("=index")) "redirect:/" + url.last() else "redirect:/" + url.last() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        bugService.save(bug) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        redirectAttributes.addFlashAttribute("successMessage", "Success save bug") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return "redirect:/$global" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    @RequestMapping(value = ["/saveUser"], method = [RequestMethod.POST]) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    fun saveUserEdit(@Valid @ModelAttribute("userRole") userRole: UserRole): String { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @PostMapping(value = ["/saveUser"]) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    fun saveUserEdit( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        @Valid @ModelAttribute("userRole") userRole: UserRole, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        bindingResult: BindingResult, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        model: Model 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    ): String { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         val existUser = userService[userRole.id] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         val editUser = User() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         editUser.id = userRole.id 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -237,14 +239,55 @@ class BugController( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         editUser.password = passwordEncoder.encode(userRole.password) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         editUser.roles = userRole.role 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         editUser.isEnabled = true 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (userService.checkIfValidOldPassword(userRole.oldPass, existUser.password)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            userService.save(editUser) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (bindingResult.hasErrors()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return "edit_user" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        userService.save(editUser) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return "redirect:/userList" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    @RequestMapping(value = ["/saveProj"], method = [RequestMethod.POST]) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    fun saveProjEdit(@Valid @ModelAttribute("project") project: Project): String { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @PostMapping(value = ["/chgPass"]) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    fun saveChangePass( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        @Valid @ModelAttribute("userRole") userRole: UserRole, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        bindingResult: BindingResult, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        model: Model, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        redirectAttributes: RedirectAttributes 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    ): String { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        val existUser = userService[userRole.id] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        val editUser = User() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        editUser.id = userRole.id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        editUser.username = userRole.username 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        editUser.password = passwordEncoder.encode(userRole.password) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        editUser.roles = existUser.roles 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        editUser.isEnabled = true 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        userRole.role = existUser.roles 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (bindingResult.hasErrors()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            model.addAttribute("userRole", userRole) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            model.addAttribute("role", getRole()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return "change_pass" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (!userService.checkIfValidOldPassword(userRole.oldPass, existUser.password)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            model.addAttribute("userRole", userRole) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            model.addAttribute("role", getRole()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            redirectAttributes.addFlashAttribute("successMessage", "old password not match") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return "redirect:/userList/chgPass/" + userRole.id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        userService.save(editUser) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        redirectAttributes.addFlashAttribute("successMessage", "Success save user") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return "redirect:/userList" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @PostMapping(value = ["/saveProj"]) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    fun saveProjEdit( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        @Valid @ModelAttribute("project") project: Project, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        bindingResult: BindingResult, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        model: Model, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        redirectAttributes: RedirectAttributes 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    ): String { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (bindingResult.hasErrors()){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return "edit_proj" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        redirectAttributes.addFlashAttribute("successMessage", "Success save project") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         projectService.save(project) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return "redirect:/proj" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -254,6 +297,7 @@ class BugController( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         @PathVariable(name = "id") id: Long, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         @RequestParam page: String, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     ): ModelAndView { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        global = page 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         val mav = ModelAndView("edit_bug") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         val bug: ListBug = bugService[id] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         mav.addObject("listQc", getUser()) 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -276,6 +320,21 @@ 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 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @RequestMapping("/userList/chgPass/{id}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    fun changePass(@PathVariable(name = "id") id: Long): ModelAndView { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        val mav = ModelAndView("change_pass") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        val user: User = userService[id] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        val userRole = UserRole() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        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 
			 |