Skip to content

Commit

Permalink
Merge pull request #304 from ODOICHON/dev
Browse files Browse the repository at this point in the history
Deploy for Dev
  • Loading branch information
dldmsql authored Oct 28, 2023
2 parents 6770824 + 8ad682c commit f535d64
Show file tree
Hide file tree
Showing 82 changed files with 2,198 additions and 757 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,42 @@ import org.springframework.web.bind.annotation.RequestMapping
@Controller
@RequestMapping("/admin/analysis")
class AdminAnalysisController (
/**
* =============================================================================================
* DI for Service
* =============================================================================================
* */
val analysisService: AnalysisService
){

/**
* =============================================================================================
* 사용자(일반 사용자, 공인중개사 ) 회원 가입 경로 조회
*
* @author YoonTaeminnnn
* @param model
* @return analysis/joinPath 회원 가입 경로 페이지
* =============================================================================================
* */
@GetMapping("/join-path")
fun getAnalysisJoinPath(model : Model) : String {
val result = analysisService.getAnalysisJoinPathResult()
model.addAttribute("joinPathResults", result)
model.addAttribute("joinPathResults", result) // 가입 경로 결과
return "analysis/joinPath"

}

/**
* =============================================================================================
* 사용자 연령대 조회
*
* @author YoonTaeminnnn
* @param model
* @return analysis/age 연령대 페이지
* =============================================================================================
* */
@GetMapping("/age")
fun getAnalysisAge(model : Model) : String {
val result = analysisService.getAnalysisAgeResult()
val label = Age.values().map { it.value }
val label = Age.values().map { it.value } // Age enum class value 리스트 추출
model.addAttribute("rate", result.map { it.rate })
model.addAttribute("count", result.map { it.count })
model.addAttribute("label", label)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
package com.example.jhouse_server.admin.anaylsis.dto

/**
* =============================================================================================
* AnalysisJoinPathResponse -- 회원 가입 경로 응답 DTO
* joinPath -- 가입경로명
* rate -- 비율
* count -- 실제 수
* =============================================================================================
*/
data class AnalysisJoinPathResponse(
val joinPath : String,
val rate : Double,
val count : Int,
)

/**
* =============================================================================================
* AnalysisAgeResponse -- 회원 연령대 응답 DTO
* age -- 연령대명 ( Age enum class 참고 )
* rate -- 비율
* count -- 실제 수
* =============================================================================================
*/
data class AnalysisAgeResponse(
val age: String,
val rate : Double,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,30 @@ import org.springframework.stereotype.Service

@Service
class AnalysisService (
/**
* =============================================================================================
* DI for Repository
* =============================================================================================
* */
val userRepository: UserRepository
){

/**
* =============================================================================================
* 사용자 연령대 분석을 위한 데이터 조회
*
* @return List<AnalysisAgeResponse>
* =============================================================================================
* */
fun getAnalysisAgeResult() : List<AnalysisAgeResponse> {
return userRepository.getAnalysisAgeResult()
}
/**
* =============================================================================================
* 사용자 회원 가입 경로 분석을 위한 데이터 조회
*
* @return List<AnalysisJoinPathResponse>
* =============================================================================================
* */
fun getAnalysisJoinPathResult() : List<AnalysisJoinPathResponse> {
return userRepository.getAnalysisJoinPathResults()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,75 +8,108 @@ import com.example.jhouse_server.domain.user.service.UserService
import org.springframework.stereotype.Controller
import org.springframework.validation.BindingResult
import org.springframework.validation.annotation.Validated
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.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.*
import java.math.BigInteger
import java.nio.charset.StandardCharsets
import java.security.MessageDigest
import javax.servlet.http.HttpServletRequest

@Controller
@RequestMapping("/admin")
class AdminAuthController (
val userRepository: UserRepository,
val userService: UserService
){
class AdminAuthController(
/**
* =============================================================================================
* DI for Service
* =============================================================================================
* */
val userRepository: UserRepository,
val userService: UserService
) {
/**
* =============================================================================================
* 최초 진입 시, 로그인 페이지
*
* @author YoonTaeminnnn
* @param loginForm
* @return login 로그인페이지
* =============================================================================================
* */
@GetMapping
fun getSignIn(@ModelAttribute("loginForm") loginForm: LoginForm): String {
return "login"
}

// 메인 페이지 - 로그인 화면
@GetMapping
fun getSignIn(@ModelAttribute("loginForm") loginForm: LoginForm) : String {
return "login"
/**
* =============================================================================================
* 로그인
*
* @author YoonTaeminnnn
* @param loginForm
* @param bindingResult
* @param redirectURI
* @param request
* @return login || redirect:redirectURI
* =============================================================================================
* */
@PostMapping
fun signIn(
@Validated @ModelAttribute("loginForm") loginForm: LoginForm,
bindingResult: BindingResult,
@RequestParam(
"redirectURI",
defaultValue = "/admin/analysis/join-path"
) redirectURI: String,
request: HttpServletRequest
): String {
val findUser = userRepository.findByUserNameAndAuthority(loginForm.email!!, Authority.ADMIN)
if (findUser.isEmpty) {
bindingResult.reject("emailNotFound", "존재하지 않는 아이디입니다")
return "login"
}

@GetMapping("/main")
fun getMain() : String{
return "main"
}

@GetMapping("/test")
fun getTest() : String{
return "test"
val user = findUser.get()
if (user.password != encodePassword(loginForm.password)) {
bindingResult.reject("passwordNotMatch", "비밀번호가 일치하지 않습니다")
return "login"
}
val session = request.getSession(true)
session.setAttribute(SessionConst.LOGINUSER, user)
return "redirect:$redirectURI"
}

/**
* =============================================================================================
* 로그아웃
*
* @author YoonTaeminnnn
* @param httpServletRequest
* @return redirect:/admin
* =============================================================================================
* */
@PostMapping("/logout")
fun logout(httpServletRequest: HttpServletRequest): String {
httpServletRequest.getSession(false)?.invalidate()
return "redirect:/admin"
}

@PostMapping
fun signIn(@Validated @ModelAttribute("loginForm") loginForm: LoginForm,
bindingResult: BindingResult,
@RequestParam("redirectURI", defaultValue = "/admin/analysis/join-path") redirectURI : String,
request: HttpServletRequest) : String {
val findUser = userRepository.findByUserNameAndAuthority(loginForm.email!!, Authority.ADMIN)
if (findUser.isEmpty){
bindingResult.reject("emailNotFound", "존재하지 않는 아이디입니다")
return "login"
}
val user = findUser.get()
if (user.password != encodePassword(loginForm.password)) {
bindingResult.reject("passwordNotMatch", "비밀번호가 일치하지 않습니다")
return "login"
}
val session = request.getSession(true)
session.setAttribute(SessionConst.LOGINUSER, user)
return "redirect:$redirectURI"
}
/**
* =============================================================================================
* PRIVATE FUNCTION
* =============================================================================================
* */

@PostMapping("/logout")
fun logout(httpServletRequest: HttpServletRequest): String {
httpServletRequest.getSession(false)?.invalidate()
return "redirect:/admin"
/**
* =============================================================================================
* 비밀번호 암호화
* =============================================================================================
* */
private fun encodePassword(password: String?): String {
val messageDigest = MessageDigest.getInstance("SHA-512")
messageDigest.reset()
if (password != null) {
messageDigest.update(password.toByteArray(StandardCharsets.UTF_8))
}

private fun encodePassword(password: String?): String {
val messageDigest = MessageDigest.getInstance("SHA-512")
messageDigest.reset()
if (password != null) {
messageDigest.update(password.toByteArray(StandardCharsets.UTF_8))
}
return String.format("%0128x", BigInteger(1, messageDigest.digest()))
}

return String.format("%0128x", BigInteger(1, messageDigest.digest()))
}


}
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package com.example.jhouse_server.admin.auth.dto

/**
* =============================================================================================
* LoginForm -- 로그인 요청 DTO
* email -- 이메일 계정
* password -- 비밀번호
* =============================================================================================
*/
data class LoginForm(
val email: String?,
val password: String?
Expand Down
Loading

0 comments on commit f535d64

Please sign in to comment.