From 576932da3d863db79857bb6f41f5c698431ba54a Mon Sep 17 00:00:00 2001 From: lunaticbum Date: Mon, 2 Dec 2024 18:32:14 +0900 Subject: [PATCH] ... --- build.gradle.kts | 6 +- .../lunaticbum/back/lun/configs/AppConfig.kt | 5 + .../back/lun/configs/BumsInterceptor.kt | 43 ++++++ .../back/lun/configs/SecurityConfig.kt | 1 + .../back/lun/controllers/BlogController.kt | 21 ++- .../back/lun/controllers/BumsPrivate.kt | 28 ++-- .../lunaticbum/back/lun/controllers/Home.kt | 10 +- .../back/lun/controllers/UserController.kt | 123 +++++++++--------- .../lunaticbum/back/lun/model/BaseResult.kt | 7 + .../back/lun/model/ResponceResult.kt | 5 +- .../kr/lunaticbum/back/lun/model/ResultMV.kt | 26 ++++ .../lunaticbum/back/lun/utils/StringUtils.kt | 36 ++++- src/main/resources/application.properties | 2 + src/main/resources/static/js/common.js | 70 +++++++++- .../templates/content/private/where.html | 10 +- .../resources/templates/fragments/header.html | 6 +- 16 files changed, 287 insertions(+), 112 deletions(-) create mode 100644 src/main/kotlin/kr/lunaticbum/back/lun/configs/BumsInterceptor.kt create mode 100644 src/main/kotlin/kr/lunaticbum/back/lun/model/BaseResult.kt create mode 100644 src/main/kotlin/kr/lunaticbum/back/lun/model/ResultMV.kt diff --git a/build.gradle.kts b/build.gradle.kts index 27ba626..9e7d482 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -52,7 +52,11 @@ dependencies { implementation ("com.drewnoakes:metadata-extractor:2.19.0") implementation("org.springframework.boot:spring-boot-starter-security") compileOnly("org.projectlombok:lombok") -// runtimeOnly("org.mariadb.jdbc:mariadb-java-client") + + implementation("io.jsonwebtoken:jjwt-api:0.11.5") + implementation("io.jsonwebtoken:jjwt-impl:0.11.5") + implementation("io.jsonwebtoken:jjwt-jackson:0.11.5") + annotationProcessor("org.projectlombok:lombok") testImplementation("org.springframework.boot:spring-boot-starter-test") testImplementation("io.projectreactor:reactor-test") diff --git a/src/main/kotlin/kr/lunaticbum/back/lun/configs/AppConfig.kt b/src/main/kotlin/kr/lunaticbum/back/lun/configs/AppConfig.kt index 3f623d9..c56cc60 100644 --- a/src/main/kotlin/kr/lunaticbum/back/lun/configs/AppConfig.kt +++ b/src/main/kotlin/kr/lunaticbum/back/lun/configs/AppConfig.kt @@ -2,6 +2,7 @@ package kr.lunaticbum.back.lun.configs import org.springframework.beans.factory.annotation.Value import org.springframework.context.annotation.Configuration +import org.springframework.web.servlet.config.annotation.InterceptorRegistry import org.springframework.web.servlet.config.annotation.WebMvcConfigurer @@ -17,6 +18,10 @@ class AppConfig : WebMvcConfigurer { registry.addResourceHandler(resourceHandler).addResourceLocations(resourceLocation) } + override fun addInterceptors(registry: InterceptorRegistry) { + registry.addInterceptor(BumsInterceptor()) + super.addInterceptors(registry) + } // @Bean // fun getProperty() : Map{ // println("telegramBotKey >>>> $telegramBotKey") diff --git a/src/main/kotlin/kr/lunaticbum/back/lun/configs/BumsInterceptor.kt b/src/main/kotlin/kr/lunaticbum/back/lun/configs/BumsInterceptor.kt new file mode 100644 index 0000000..c16070d --- /dev/null +++ b/src/main/kotlin/kr/lunaticbum/back/lun/configs/BumsInterceptor.kt @@ -0,0 +1,43 @@ +package kr.lunaticbum.back.lun.configs + +import com.google.gson.Gson +import jakarta.servlet.http.Cookie +import jakarta.servlet.http.HttpServletRequest +import jakarta.servlet.http.HttpServletResponse +import org.springframework.lang.Nullable +import org.springframework.web.servlet.HandlerInterceptor +import org.springframework.web.servlet.ModelAndView + + +class BumsInterceptor : HandlerInterceptor{ + @Throws(Exception::class) + override fun preHandle(request: HttpServletRequest, response: HttpServletResponse, handler: Any): Boolean { + println("===============================================") + println("==================== BEGIN ====================") + println("Request URL ===> " + request.requestURL) + return super.preHandle(request, response, handler) + } + val WRITE_PERMISSION_KEY = "PERMISSION" + @Throws(Exception::class) + override fun postHandle( + request: HttpServletRequest, + response: HttpServletResponse, + handler: Any, + @Nullable modelAndView: ModelAndView? + ) { + if (request.requestURI.contains("logout") == false && !request.cookies.isNullOrEmpty() && request.cookies.filter { it.name.equals("S33-DATA") && it.value.length > 0 }.size > 0) { + response.addCookie(Cookie("S33-DATA",request.cookies.filter { it.name.equals("S33-DATA") && it.value.length > 0 }.get(0).value)) + modelAndView?.modelMap?.put(WRITE_PERMISSION_KEY,"OK") + println("Response modelMap ===> ${Gson().toJson(modelAndView?.modelMap)}") + } else if (request.requestURI.contains("logout")) { + response.addCookie(Cookie("S33-DATA",null)) + modelAndView?.modelMap?.put(WRITE_PERMISSION_KEY,"NO") + } + + println("==================== END ======================") + println("===============================================") + + super.postHandle(request, response, handler, modelAndView) + } + +} \ No newline at end of file diff --git a/src/main/kotlin/kr/lunaticbum/back/lun/configs/SecurityConfig.kt b/src/main/kotlin/kr/lunaticbum/back/lun/configs/SecurityConfig.kt index 070bff3..72b79e8 100644 --- a/src/main/kotlin/kr/lunaticbum/back/lun/configs/SecurityConfig.kt +++ b/src/main/kotlin/kr/lunaticbum/back/lun/configs/SecurityConfig.kt @@ -41,6 +41,7 @@ class SecurityConfig { frameOptionsConfig.disable() } } + http.authorizeHttpRequests { logService.log(it.toString()) it.requestMatchers(HttpMethod.POST,"/user/**").permitAll() diff --git a/src/main/kotlin/kr/lunaticbum/back/lun/controllers/BlogController.kt b/src/main/kotlin/kr/lunaticbum/back/lun/controllers/BlogController.kt index e191bb9..5e89b3f 100644 --- a/src/main/kotlin/kr/lunaticbum/back/lun/controllers/BlogController.kt +++ b/src/main/kotlin/kr/lunaticbum/back/lun/controllers/BlogController.kt @@ -21,7 +21,6 @@ import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.* import org.springframework.web.multipart.MultipartFile import org.springframework.web.reactive.function.client.WebClient -import org.springframework.web.servlet.ModelAndView import java.io.* import java.net.URLDecoder import java.text.SimpleDateFormat @@ -47,8 +46,8 @@ class BlogController() { lateinit var logService: LogService val WRITE_PERMISSION_KEY = "PERMISSION" @GetMapping("write/{token}","write") - fun writ(@PathVariable token : String? ) : ModelAndView{ - val vm = ModelAndView("content/blog/write") + fun writ(@PathVariable token : String? ) : ResultMV{ + val vm = ResultMV("content/blog/write") if (token.equals(TEMPTOKEN)) { vm.modelMap.put(WRITE_PERMISSION_KEY,"OK") vm.modelMap.put(EncTypeKey, EncType11) @@ -126,8 +125,8 @@ class BlogController() { } @GetMapping("viewer/{postId}") - fun viewer(@PathVariable postId : String) : ModelAndView{ - val vm = ModelAndView("content/blog/viewer") + fun viewer(@PathVariable postId : String) : ResultMV{ + val vm = ResultMV("content/blog/viewer") postManageg.getPost(postId).block().apply { this?.title = URLDecoder.decode(this?.title) this?.content = URLDecoder.decode(this?.content) @@ -137,9 +136,9 @@ class BlogController() { } @GetMapping("modify") - fun modify(@RequestParam("token") token : String?) : ModelAndView{ + fun modify(@RequestParam("token") token : String?) : ResultMV{ logService.log("incoming modify") - val vm = ModelAndView("content/blog/modify") + val vm = ResultMV("content/blog/modify") if (TEMPTOKEN.equals(token)) { postManageg.find20()?.apply { forEach { @@ -160,8 +159,8 @@ class BlogController() { } @GetMapping("editor/{postId}") - fun editor(@PathVariable postId : String, @RequestParam("token") token : String?) : ModelAndView{ - val vm = ModelAndView("content/blog/editor") + fun editor(@PathVariable postId : String, @RequestParam("token") token : String?) : ResultMV{ + val vm = ResultMV("content/blog/editor") postManageg.getPost(postId).block().apply { this?.title = URLDecoder.decode(this?.title) this?.content = URLDecoder.decode(this?.content) @@ -177,8 +176,8 @@ class BlogController() { @GetMapping("recent") - fun recent() : ModelAndView{ - val vm = ModelAndView("content/blog/viewer") + fun recent() : ResultMV{ + val vm = ResultMV("content/blog/viewer") locationLogService.find20().forEach { logService.log(Gson().toJson(it)) } diff --git a/src/main/kotlin/kr/lunaticbum/back/lun/controllers/BumsPrivate.kt b/src/main/kotlin/kr/lunaticbum/back/lun/controllers/BumsPrivate.kt index c7c8629..0fcab16 100644 --- a/src/main/kotlin/kr/lunaticbum/back/lun/controllers/BumsPrivate.kt +++ b/src/main/kotlin/kr/lunaticbum/back/lun/controllers/BumsPrivate.kt @@ -6,17 +6,16 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kr.lunaticbum.back.lun.configs.GlobalEnvironment -import kr.lunaticbum.back.lun.model.LocationLog -import kr.lunaticbum.back.lun.model.LocationLogService -import kr.lunaticbum.back.lun.model.ResponceResult +import kr.lunaticbum.back.lun.model.* import kr.lunaticbum.back.lun.utils.LogService +import kr.lunaticbum.back.lun.utils.plainText import org.springframework.beans.factory.annotation.Autowired import org.springframework.http.MediaType import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.* import org.springframework.web.reactive.function.client.WebClient import org.springframework.web.servlet.ModelAndView -import java.util.* +import java.util.Base64 @RestController @@ -32,15 +31,15 @@ class BumsPrivate { lateinit var locationService: LocationLogService @GetMapping("where") - fun where() : ModelAndView { - val m = ModelAndView("content/private/where") + fun where() : ResultMV { + val m = ResultMV("content/private/where") locationService.find20().apply { m.modelMap.put("locations",this.reversed()) - forEach { - logService.log(it.timeString.plus(it.mAddressLines.joinToString(","))) - } +// forEach { +// logService.log(it.timeString.plus(it.mAddressLines.joinToString(","))) +// } } - m.modelMap.put("title","돼지 여기있다요~!!") + m.setTitle("돼지 여기있다요~!!") return m } @@ -49,11 +48,9 @@ class BumsPrivate { fun login(httpServletRequest: HttpServletRequest, @RequestBody jsonString: String) : ResponseEntity { logService.log("${httpServletRequest.requestURI}") logService.log(jsonString) - var lResultCode = 0 - var lResultMsg = "Suscces" + var location : LocationLog? = null - val decodedBytes: ByteArray = Base64.getMimeDecoder().decode(jsonString) - String(decodedBytes).let { + jsonString.plainText().let { Gson().fromJson(it, LocationLog::class.java)?.let { model -> location = model logService.log(model.toString()) @@ -61,8 +58,7 @@ class BumsPrivate { } } val responce = ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(ResponceResult().apply { - this.resultCode = lResultCode - this.resultMsg = lResultMsg + }) CoroutineScope(Dispatchers.IO).launch { location?.let { diff --git a/src/main/kotlin/kr/lunaticbum/back/lun/controllers/Home.kt b/src/main/kotlin/kr/lunaticbum/back/lun/controllers/Home.kt index 009335a..74f6be1 100644 --- a/src/main/kotlin/kr/lunaticbum/back/lun/controllers/Home.kt +++ b/src/main/kotlin/kr/lunaticbum/back/lun/controllers/Home.kt @@ -3,13 +3,13 @@ package kr.lunaticbum.back.lun.controllers import com.google.gson.Gson import jakarta.servlet.http.HttpServletResponse import kr.lunaticbum.back.lun.model.PostManageg +import kr.lunaticbum.back.lun.model.ResultMV import kr.lunaticbum.back.lun.utils.LogService import org.springframework.beans.factory.annotation.Autowired import org.springframework.data.domain.Pageable import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController -import org.springframework.web.servlet.ModelAndView import java.net.URLDecoder @RestController @@ -23,8 +23,8 @@ class Home { private lateinit var postManageg: PostManageg @GetMapping("/","/home") - fun home() : ModelAndView { - val vm = ModelAndView("content/home") + fun home() : ResultMV { + val vm = ResultMV("content/home") vm.modelMap.put("Posts", postManageg.find20(Pageable.ofSize(20)).apply { this.forEach { it.title = URLDecoder.decode(it.title) @@ -41,8 +41,8 @@ class Home { } @GetMapping("/licenses") - fun licenses() : ModelAndView { - val vm = ModelAndView("content/licenses") + fun licenses() : ResultMV { + val vm = ResultMV("content/licenses") return vm } diff --git a/src/main/kotlin/kr/lunaticbum/back/lun/controllers/UserController.kt b/src/main/kotlin/kr/lunaticbum/back/lun/controllers/UserController.kt index 2fb8356..e935a20 100644 --- a/src/main/kotlin/kr/lunaticbum/back/lun/controllers/UserController.kt +++ b/src/main/kotlin/kr/lunaticbum/back/lun/controllers/UserController.kt @@ -6,18 +6,16 @@ import kr.lunaticbum.back.lun.configs.GlobalEnvironment import kr.lunaticbum.back.lun.configs.GlobalEnvironment.Companion.ApiKeyWordKey import kr.lunaticbum.back.lun.configs.GlobalEnvironment.Companion.EncType11 import kr.lunaticbum.back.lun.configs.GlobalEnvironment.Companion.EncTypeKey -import kr.lunaticbum.back.lun.model.RequestModel -import kr.lunaticbum.back.lun.model.ResponceResult -import kr.lunaticbum.back.lun.model.User -import kr.lunaticbum.back.lun.model.UserManager +import kr.lunaticbum.back.lun.model.* import kr.lunaticbum.back.lun.utils.LogService +import kr.lunaticbum.back.lun.utils.extractModelData import org.springframework.beans.factory.annotation.Autowired import org.springframework.http.MediaType import org.springframework.http.ResponseEntity import org.springframework.security.core.userdetails.UserDetails import org.springframework.web.bind.annotation.* import org.springframework.web.reactive.function.client.WebClient -import org.springframework.web.servlet.ModelAndView + import java.io.File import java.util.* @@ -37,9 +35,9 @@ class UserController { lateinit var userManager: UserManager @GetMapping("join") - fun hello(httpServletRequest: HttpServletRequest): ModelAndView { + fun hello(httpServletRequest: HttpServletRequest): ResultMV { logService.log("onJoin") - val vm = ModelAndView("content/user/join") + val vm = ResultMV("content/user/join") // when(System.currentTimeMillis() % 5L) { // 0L -> vm.modelMap.put(EncTypeKey,"T4") // 1L -> vm.modelMap.put(EncTypeKey,"T3") @@ -56,9 +54,9 @@ class UserController { } @GetMapping("login") - fun userLogin(httpServletRequest: HttpServletRequest): ModelAndView { + fun userLogin(httpServletRequest: HttpServletRequest): ResultMV { logService.log("onJoin") - val vm = ModelAndView("content/user/login") + val vm = ResultMV("content/user/login") // when(System.currentTimeMillis() % 5L) { // 0L -> vm.modelMap.put(EncTypeKey,"T4") // 1L -> vm.modelMap.put(EncTypeKey,"T3") @@ -79,45 +77,48 @@ class UserController { var lResultCode = 0 var lResultMsg = "Suscces" var u : UserDetails? = null - val decodedBytes: ByteArray = Base64.getDecoder().decode(jsonString) - String(decodedBytes).let { - Gson().fromJson(it,RequestModel::class.java)?.let { model -> - logService.log(Gson().toJson(model)) - model.data?.let { jsonString -> - try { - val originDataString = model.extractData() - logService.log(originDataString) - val target = Gson().fromJson(originDataString, User::class.java) ?: User() - var user = userManager.findById(target.user_id!!)?.block() - if (user == null && ((target.user_id?.length ?: 0) > 3 == true)) { - user = userManager.findByEmail(target.user_id!!)?.block() - } - if (user != null) { - if(userManager.isCorrectUser(user,target.user_pw!!)){ - - } else { - lResultMsg = "is wrong infomation id or passord" - lResultCode = 7100 - } - } else { - lResultMsg = "not founding user[can't find same id,email.. ]" - lResultCode = 7100 - } - } catch (e: Exception) { - e.printStackTrace() - lResultMsg = "unknown exception" - lResultCode = 7999 - } + jsonString.extractModelData { exception, originDataString -> + if (exception == null) { + logService.log(originDataString) + val target = Gson().fromJson(originDataString, User::class.java) ?: User() + var user = userManager.findById(target.user_id!!)?.block() + if (user == null && ((target.user_id?.length ?: 0) > 3 == true)) { + user = userManager.findByEmail(target.user_id!!)?.block() } + if (user != null) { + if(userManager.isCorrectUser(user,target.user_pw!!)){ + + } else { + lResultMsg = "is wrong infomation id or passord" + lResultCode = 7100 + } + } else { + lResultMsg = "not founding user[can't find same id,email.. ]" + lResultCode = 7100 + } + } else { + exception.printStackTrace() + lResultMsg = exception.message ?: "unknown exception" + lResultCode = 7999 } } - val responce = ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(ResponceResult().apply { + val responce = ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).headers { + it.put("S33-DATA", listOf(UUID.randomUUID().toString())) + }.body(ResponceResult().apply { this.resultCode = lResultCode this.resultMsg = lResultMsg }) return responce } + @ResponseBody + @PostMapping("logout.ajax") + fun logout(httpServletRequest: HttpServletRequest) : ResponseEntity { + val responce = ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(ResponceResult().apply { + + }) + return responce + } @ResponseBody @PostMapping("joinUser.ajax") @@ -127,33 +128,25 @@ class UserController { var lResultCode = 0 var lResultMsg = "Suscces" var u : User? = null - val decodedBytes: ByteArray = Base64.getDecoder().decode(jsonString) - String(decodedBytes).let { - Gson().fromJson(it,RequestModel::class.java)?.let { model -> - logService.log(Gson().toJson(model)) - model.data?.let { jsonString -> - try { - val originDataString = model.extractData() - logService.log(originDataString) - val user = Gson().fromJson(originDataString, User::class.java) ?: User() - if (user.checkValid() == false) { - lResultCode = 7009 - lResultMsg = "user insert Fail Reason : Not Correct Data" - }else if (userManager.findById(user!!.user_id!!)?.block() != null) { - lResultCode = 7001 - lResultMsg = "user insert Fail Reason : already has Same Id" - }else if (userManager.findByEmail(user!!.user_email!!)?.block() != null ) { - lResultCode = 7002 - lResultMsg = "user insert Fail Reason : already has Same Email" - } else { - u = userManager.save(user).block() - } - } catch (e: Exception) { - e.printStackTrace() - lResultMsg = "unknown exception" - lResultCode = 7999 - } + jsonString.extractModelData { exception, s -> + if (exception == null) { + val user = Gson().fromJson(s, User::class.java) ?: User() + if (user.checkValid() == false) { + lResultCode = 7009 + lResultMsg = "user insert Fail Reason : Not Correct Data" + }else if (userManager.findById(user!!.user_id!!)?.block() != null) { + lResultCode = 7001 + lResultMsg = "user insert Fail Reason : already has Same Id" + }else if (userManager.findByEmail(user!!.user_email!!)?.block() != null ) { + lResultCode = 7002 + lResultMsg = "user insert Fail Reason : already has Same Email" + } else { + u = userManager.save(user).block() } + } else { + exception.printStackTrace() + lResultMsg = exception.message ?: "unknown exception" + lResultCode = 7999 } } val responce = ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(ResponceResult().apply { diff --git a/src/main/kotlin/kr/lunaticbum/back/lun/model/BaseResult.kt b/src/main/kotlin/kr/lunaticbum/back/lun/model/BaseResult.kt new file mode 100644 index 0000000..c3edc0d --- /dev/null +++ b/src/main/kotlin/kr/lunaticbum/back/lun/model/BaseResult.kt @@ -0,0 +1,7 @@ +package kr.lunaticbum.back.lun.model + +open class BaseResult { + var resultCode = 0 + var resultMsg = "Suscces" + var isOk = true +} \ No newline at end of file diff --git a/src/main/kotlin/kr/lunaticbum/back/lun/model/ResponceResult.kt b/src/main/kotlin/kr/lunaticbum/back/lun/model/ResponceResult.kt index b5fd53d..5cad54e 100644 --- a/src/main/kotlin/kr/lunaticbum/back/lun/model/ResponceResult.kt +++ b/src/main/kotlin/kr/lunaticbum/back/lun/model/ResponceResult.kt @@ -4,9 +4,8 @@ import lombok.Getter @Getter -open class ResponceResult { - var resultCode: Int = 0 - var resultMsg: String? = null +open class ResponceResult : BaseResult() { + } diff --git a/src/main/kotlin/kr/lunaticbum/back/lun/model/ResultMV.kt b/src/main/kotlin/kr/lunaticbum/back/lun/model/ResultMV.kt new file mode 100644 index 0000000..549af9e --- /dev/null +++ b/src/main/kotlin/kr/lunaticbum/back/lun/model/ResultMV.kt @@ -0,0 +1,26 @@ +package kr.lunaticbum.back.lun.model + +import org.springframework.http.HttpStatusCode +import org.springframework.web.servlet.ModelAndView +import org.springframework.web.servlet.View + +class ResultMV : ModelAndView { + + constructor() : super() + constructor(viewName: String) : super(viewName) + constructor(view: View) : super(view) + constructor(viewName: String, model: MutableMap?) : super(viewName, model) + constructor(view: View, model: MutableMap?) : super(view, model) + constructor(viewName: String, status: HttpStatusCode) : super(viewName, status) + constructor(viewName: String?, model: MutableMap?, status: HttpStatusCode?) : super(viewName, model, status) + constructor(viewName: String, modelName: String, modelObject: Any) : super(viewName, modelName, modelObject) + constructor(view: View, modelName: String, modelObject: Any) : super(view, modelName, modelObject) + + init { + modelMap.put("title", "LUNATICBUM") + } + + fun setTitle(title : String){ + modelMap.put("title", title) + } +} \ No newline at end of file diff --git a/src/main/kotlin/kr/lunaticbum/back/lun/utils/StringUtils.kt b/src/main/kotlin/kr/lunaticbum/back/lun/utils/StringUtils.kt index 578fbef..b7d2e8a 100644 --- a/src/main/kotlin/kr/lunaticbum/back/lun/utils/StringUtils.kt +++ b/src/main/kotlin/kr/lunaticbum/back/lun/utils/StringUtils.kt @@ -1,4 +1,9 @@ -//package kr.lunaticbum.back.lun.utils +package kr.lunaticbum.back.lun.utils + +import com.google.gson.Gson +import kr.lunaticbum.back.lun.model.RequestModel +import java.util.Base64 + // // //import javax.crypto.Cipher @@ -49,4 +54,31 @@ // //Decode Base64 //// byte[] decodeByte = Base64.decodeBase64(encodeText); // return String(c.doFinal(decodeByte), charset("UTF-8")) -//} \ No newline at end of file +//} +fun String.plainText() = String(Base64.getMimeDecoder().decode(this)) + +fun String.extractModelData(calback : (Exception?,String)->Unit) { + try { + val decodedBytes: ByteArray = Base64.getDecoder().decode(this) + String(decodedBytes).let { resultString -> + try { + Gson().fromJson(resultString, RequestModel::class.java).let { model -> + model.data?.let { jsonString -> + try { + calback.invoke(null,model.extractData()) + } catch (e: Exception) { + calback.invoke(ExtractDataRequestModelException("Exception on extractData with ${Gson().toJson(model)}", e.cause), jsonString) + } + } + } + } catch (e: Exception) { + calback.invoke(MakeRequestModelException("Exception on make RequestModel with $resultString", e.cause),this@extractModelData) + } + } + } catch (e: Exception) { + calback.invoke(Base64DecodeException("Exception on Base64 decode", e.cause),this@extractModelData) + } +} +class Base64DecodeException(message: String, cause : Throwable? = null) : Exception(message, cause) +class MakeRequestModelException(message: String, cause : Throwable? = null) : Exception(message, cause) +class ExtractDataRequestModelException(message: String, cause : Throwable? = null) : Exception(message, cause) \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 63002ed..8d67a21 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -61,4 +61,6 @@ spring.data.mongodb.option.heartbeat-connect-timeout=20000 spring.data.mongodb.option.min-heartbeat-frequency=500 spring.data.mongodb.option.heartbeat-frequency=10000 spring.data.mongodb.option.local-threshold=15 + #>>>>>>> ab915d0a416c69708f1df1ad76d7a14c779c1f59 + diff --git a/src/main/resources/static/js/common.js b/src/main/resources/static/js/common.js index d5da10c..a652dbb 100644 --- a/src/main/resources/static/js/common.js +++ b/src/main/resources/static/js/common.js @@ -1,3 +1,8 @@ + +onload = function() { + history.replaceState({}, null, location.pathname); +} + function divider(key) { return merge(padding(),key,padding()) } @@ -36,7 +41,7 @@ function checkDebug(){ } } - +var acpt_key = "" function post(target,type, data, key,callBackResult) { var httpRequest; /* 통신에 사용 될 XMLHttpRequest 객체 정의 */ @@ -52,6 +57,47 @@ function post(target,type, data, key,callBackResult) { } } } + + httpRequest.open('POST', target, true); + httpRequest.setRequestHeader("Content-Type", "text/plain"); + var odd = [] + var even = [] + var dataStr = JSON.stringify(data) + var src = dataStr.split("") + src.forEach(function (s,i,a) {if (i % 2 === 0) {even.push(s)} else {odd.push(s)}}) + httpRequest.send(btoa(JSON.stringify({ + 'data': unformat(type,data,key), + 'key':key, + 'type':type, + }))); +} +function postLogin(target,type, data, key,callBackResult) { + var httpRequest; + /* 통신에 사용 될 XMLHttpRequest 객체 정의 */ + httpRequest = new XMLHttpRequest(); + /* httpRequest의 readyState가 변화했을때 함수 실행 */ + httpRequest.onreadystatechange = () => { + /* readyState가 Done이고 응답 값이 200일 때, 받아온 response로 name과 age를 그려줌 */ + if (httpRequest.readyState === XMLHttpRequest.DONE) { + if (httpRequest.status === 200) { + try { + var uuid= httpRequest.getResponseHeader("S33-DATA") + console.log("LOG __ 0" + document.cookie) + console.log("LOG __ 1" + uuid) + document.cookie = "S33-DATA="+uuid + console.log("LOG __ 2" + document.cookie) + console.log("LOG __ 3" + uuid) + callBackResult(httpRequest.response) + document.location.href = document.location + } catch (e) { + + } + } else { + alert('Request Error!'); + } + } + } + httpRequest.open('POST', target, true); httpRequest.setRequestHeader("Content-Type", "text/plain"); var odd = [] @@ -76,6 +122,26 @@ function mainPath() { } +function logout() { + if(document.cookie.split(";").length > 1) { + document.cookie.split(";").forEach(function (v,i,a){ + if(v.search("S33-DATA") > 0) { + document.cookie.replace(v,"S33-DATA=") + } else { + + } + }) + } else { + document.cookie = "S33-DATA=" + } + let logOutUrl = getMainPath() + "/user/logout.ajax"; + post(logOutUrl,"","","", function (resultData) { + alert(resultData) + document.location.href = document.location + }) + +} + function gotoLogin() { console.log(`location.port >> ${location.port}`) location.href = getMainPath()+"/login" @@ -92,7 +158,7 @@ function onclickLogin(type, keyword) { 'user_id': user_id.value, 'user_pw': user_pw.value, } - post(getMainPath()+"/user/login.ajax",type,JSON.stringify(data),keyword, function (resultData) { + postLogin(getMainPath()+"/user/login.ajax",type,JSON.stringify(data),keyword, function (resultData) { alert(resultData) }) } diff --git a/src/main/resources/templates/content/private/where.html b/src/main/resources/templates/content/private/where.html index 7e36ecc..bd18b40 100644 --- a/src/main/resources/templates/content/private/where.html +++ b/src/main/resources/templates/content/private/where.html @@ -11,11 +11,11 @@
- - - - - +
diff --git a/src/main/resources/templates/fragments/header.html b/src/main/resources/templates/fragments/header.html index c9f67a5..c052397 100644 --- a/src/main/resources/templates/fragments/header.html +++ b/src/main/resources/templates/fragments/header.html @@ -3,7 +3,7 @@
-

HOME

+

HOME

@@ -18,7 +18,9 @@ - +