diff --git a/FrontEnd/index.html b/FrontEnd/index.html index 17c8977..e349c64 100644 --- a/FrontEnd/index.html +++ b/FrontEnd/index.html @@ -1,12 +1,12 @@ - + DormStar - +
diff --git a/FrontEnd/package.json b/FrontEnd/package.json index 5e55e17..77fa82c 100644 --- a/FrontEnd/package.json +++ b/FrontEnd/package.json @@ -15,6 +15,7 @@ "vue-router": "^4.2.5" }, "devDependencies": { + "@headlessui/vue": "^1.7.16", "@vitejs/plugin-vue": "^4.4.0", "autoprefixer": "^10.4.16", "postcss": "^8.4.31", diff --git a/FrontEnd/src/router/index.js b/FrontEnd/src/router/index.js index a1e7853..b8d271d 100644 --- a/FrontEnd/src/router/index.js +++ b/FrontEnd/src/router/index.js @@ -15,6 +15,13 @@ const router = createRouter({ { path: '/sign/up', component: () => import('../views/Sign/SignUp.vue'), + }, + { + path: '/sign/reset', + }, + { + path: '/dashboard', + component: () => import('../views/Dashboard.vue'), } ] }) diff --git a/FrontEnd/src/views/Dashboard.vue b/FrontEnd/src/views/Dashboard.vue new file mode 100644 index 0000000..d9d08a1 --- /dev/null +++ b/FrontEnd/src/views/Dashboard.vue @@ -0,0 +1,158 @@ + + + + + \ No newline at end of file diff --git a/FrontEnd/src/views/IndexWelcome.vue b/FrontEnd/src/views/IndexWelcome.vue index e1ff314..f4cad83 100644 --- a/FrontEnd/src/views/IndexWelcome.vue +++ b/FrontEnd/src/views/IndexWelcome.vue @@ -1,59 +1,67 @@ - - - + + + diff --git a/FrontEnd/src/views/Sign/SignIn.vue b/FrontEnd/src/views/Sign/SignIn.vue index f79cdd8..505b9b2 100644 --- a/FrontEnd/src/views/Sign/SignIn.vue +++ b/FrontEnd/src/views/Sign/SignIn.vue @@ -1,11 +1,90 @@ - - - - - \ No newline at end of file + + + \ No newline at end of file diff --git a/FrontEnd/src/views/Sign/SignUp.vue b/FrontEnd/src/views/Sign/SignUp.vue index f79cdd8..34e611c 100644 --- a/FrontEnd/src/views/Sign/SignUp.vue +++ b/FrontEnd/src/views/Sign/SignUp.vue @@ -1,11 +1,107 @@ - - - - - \ No newline at end of file + + + \ No newline at end of file diff --git a/info_upload.sql b/info_upload.sql index 4b32a6e..d348392 100644 --- a/info_upload.sql +++ b/info_upload.sql @@ -7,4 +7,5 @@ INSERT INTO ds_info (value, data, commit) VALUES ('sub_title', '我们的宿舍', '网站副标题'), ('register', true, '是否允许注册'), ('autoLogin', true, '是否允许自动登录'), - ('schoolLoginAddress', 'http://10.1.99.100:801/', '校园登录IP地址') \ No newline at end of file + ('schoolLoginAddress', '10.1.99.100', '校园登录IP地址'), + ('schoolLoginPort', '801', '校园网登录接口端口') \ No newline at end of file diff --git a/src/main/kotlin/com/xlf/dromstarkotlin/config/CorsConfiguration.kt b/src/main/kotlin/com/xlf/dromstarkotlin/config/CorsConfiguration.kt index e55db34..821f264 100644 --- a/src/main/kotlin/com/xlf/dromstarkotlin/config/CorsConfiguration.kt +++ b/src/main/kotlin/com/xlf/dromstarkotlin/config/CorsConfiguration.kt @@ -1,19 +1,19 @@ -package com.xlf.dromstarkotlin.config - -import org.springframework.context.annotation.Configuration -import org.springframework.web.servlet.config.annotation.CorsRegistry - -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer - - -@Configuration -class CorsConfiguration : WebMvcConfigurer { - override fun addCorsMappings(registry: CorsRegistry) { - registry.addMapping("/**") //是否发送Cookie - .allowCredentials(true) //放行哪些原始域 - .allowedOriginPatterns("*") - .allowedMethods(*arrayOf("GET", "POST", "PUT", "DELETE")) - .allowedHeaders("*") - .exposedHeaders("*") - } +package com.xlf.dromstarkotlin.config + +import org.springframework.context.annotation.Configuration +import org.springframework.web.servlet.config.annotation.CorsRegistry + +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer + + +@Configuration +class CorsConfiguration : WebMvcConfigurer { + override fun addCorsMappings(registry: CorsRegistry) { + registry.addMapping("/**") //是否发送Cookie + .allowCredentials(true) //放行哪些原始域 + .allowedOriginPatterns("*") + .allowedMethods(*arrayOf("GET", "POST", "PUT", "DELETE")) + .allowedHeaders("*") + .exposedHeaders("*") + } } \ No newline at end of file diff --git a/src/main/kotlin/com/xlf/dromstarkotlin/controllers/AccountController.kt b/src/main/kotlin/com/xlf/dromstarkotlin/controllers/AccountController.kt index 96a1248..c21a57e 100644 --- a/src/main/kotlin/com/xlf/dromstarkotlin/controllers/AccountController.kt +++ b/src/main/kotlin/com/xlf/dromstarkotlin/controllers/AccountController.kt @@ -23,10 +23,17 @@ class AccountController( .also { it.find() } val matcherType = Pattern.compile("[a-z]+$").matcher(getMap?.get("uid").toString()) .also { it.find() } - hashMap["ip"] = getMap?.get("v46ip") - hashMap["time"] = getMap?.get("time") - hashMap["uid"] = matcherUid.group(0) - hashMap["type"] = matcherType.group(0) + try { + hashMap["ip"] = getMap?.get("v46ip") + hashMap["time"] = getMap?.get("time") + hashMap["uid"] = matcherUid.group(0) + hashMap["type"] = matcherType.group(0) + } catch (e: IllegalStateException) { + hashMap["ip"] = getMap?.get("v46ip") + hashMap["time"] = null + hashMap["uid"] = matcherUid.group(0) + hashMap["type"] = null + } return ResultUtil.success(hashMap, httpServletRequest) } } \ No newline at end of file diff --git a/src/main/kotlin/com/xlf/dromstarkotlin/controllers/InfoController.kt b/src/main/kotlin/com/xlf/dromstarkotlin/controllers/InfoController.kt new file mode 100644 index 0000000..05e6c0b --- /dev/null +++ b/src/main/kotlin/com/xlf/dromstarkotlin/controllers/InfoController.kt @@ -0,0 +1,24 @@ +package com.xlf.dromstarkotlin.controllers + +import com.frontleaves.general.utils.BaseResponse +import com.xlf.dromstarkotlin.services.InfoService +import jakarta.servlet.http.HttpServletRequest +import org.springframework.http.ResponseEntity +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController + +@RestController +@RequestMapping("/api/info") +class InfoController( + val infoService: InfoService +) { + + /** + * 获取内容 + */ + @GetMapping("/data") + fun getWebInfo(httpServletRequest: HttpServletRequest): ResponseEntity { + return infoService.getWebInfo(httpServletRequest) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/xlf/dromstarkotlin/controllers/LogController.kt b/src/main/kotlin/com/xlf/dromstarkotlin/controllers/LogController.kt new file mode 100644 index 0000000..53d67e3 --- /dev/null +++ b/src/main/kotlin/com/xlf/dromstarkotlin/controllers/LogController.kt @@ -0,0 +1,34 @@ +package com.xlf.dromstarkotlin.controllers + +import com.frontleaves.general.utils.BaseResponse +import com.frontleaves.general.utils.ErrorCode +import com.frontleaves.general.utils.ResultUtil +import com.xlf.dromstarkotlin.services.LogService +import jakarta.servlet.http.HttpServletRequest +import jakarta.servlet.http.HttpServletResponse +import org.springframework.http.ResponseEntity +import org.springframework.web.bind.annotation.CookieValue +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController + +@RestController +@RequestMapping("/api/log") +class LogController( + val logService: LogService +) { + + @GetMapping("/auto-login") + fun getAutoLoginLog( + @CookieValue("session") token: String?, + httpServletRequest: HttpServletRequest, + httpServletResponse: HttpServletResponse + ): ResponseEntity? { + // token 存在鉴权 + return if (token != null) { + logService.getAutoLoginLog(token, httpServletRequest, httpServletResponse) + } else { + ResultUtil.error(ErrorCode.TOKEN_NOT_FOUNDED, httpServletRequest) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/xlf/dromstarkotlin/controllers/TokenController.kt b/src/main/kotlin/com/xlf/dromstarkotlin/controllers/TokenController.kt index d1960b1..f2e260a 100644 --- a/src/main/kotlin/com/xlf/dromstarkotlin/controllers/TokenController.kt +++ b/src/main/kotlin/com/xlf/dromstarkotlin/controllers/TokenController.kt @@ -7,16 +7,10 @@ import jakarta.servlet.http.Cookie import jakarta.servlet.http.HttpServletRequest import jakarta.servlet.http.HttpServletResponse import org.springframework.http.ResponseEntity -import org.springframework.web.bind.annotation.CookieValue -import org.springframework.web.bind.annotation.CrossOrigin -import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RequestParam -import org.springframework.web.bind.annotation.RestController +import org.springframework.web.bind.annotation.* @RestController @RequestMapping("/api/token") -@CrossOrigin(origins = ["*"]) class TokenController( private val tokenService: TokenService ) { @@ -25,28 +19,21 @@ class TokenController( */ @GetMapping("/create") fun createToken( - @CookieValue("session") token: String?, httpServletResponse: HttpServletResponse, + @CookieValue("session") token: String?, + httpServletResponse: HttpServletResponse, @RequestParam("return") returnLink: String?, httpServletRequest: HttpServletRequest ): ResponseEntity { // 检查 token 是否存在 return if (token == null) { val newToken = tokenService.tokenCreate(httpServletRequest) - httpServletResponse.addCookie( - Cookie("session", newToken) - .also { it.path = "/" } - .also { it.maxAge = 43200 } - ) + httpServletResponse.addCookie(Cookie("session", newToken).also { it.path = "/" }.also { it.maxAge = 43200 }) ResultUtil.redirect("SuccessCreate", "Token创建成功", newToken, returnLink, httpServletRequest) } else { if (tokenService.tokenVerify(token, httpServletResponse)) { ResultUtil.redirect("StillValid", "Token依旧有效", null, returnLink, httpServletRequest) } else { - httpServletResponse.addCookie( - Cookie("session", null) - .also { it.path = "/" } - .also { it.maxAge = 0 } - ) + httpServletResponse.addCookie(Cookie("session", null).also { it.path = "/" }.also { it.maxAge = 0 }) this.createToken(null, httpServletResponse, returnLink, httpServletRequest) } } diff --git a/src/main/kotlin/com/xlf/dromstarkotlin/controllers/UserController.kt b/src/main/kotlin/com/xlf/dromstarkotlin/controllers/UserController.kt index c71d50b..396c412 100644 --- a/src/main/kotlin/com/xlf/dromstarkotlin/controllers/UserController.kt +++ b/src/main/kotlin/com/xlf/dromstarkotlin/controllers/UserController.kt @@ -12,12 +12,8 @@ import com.xlf.dromstarkotlin.services.UserService import jakarta.servlet.http.HttpServletRequest import jakarta.servlet.http.HttpServletResponse import org.springframework.http.ResponseEntity -import org.springframework.web.bind.annotation.CookieValue -import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.RequestBody -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RestController -import java.util.Date +import org.springframework.web.bind.annotation.* +import java.util.* /** * 用户控制器 @@ -39,7 +35,9 @@ class UserController( */ @GetMapping("/sign/in") fun signIn( - @RequestBody signInVO: SignInVO?, @CookieValue("session") token: String?, httpServletResponse: HttpServletResponse, + @RequestBody signInVO: SignInVO?, + @CookieValue("session") token: String?, + httpServletResponse: HttpServletResponse, httpServletRequest: HttpServletRequest ): ResponseEntity { // 判断请求体是否为空 @@ -72,7 +70,9 @@ class UserController( */ @GetMapping("/sign/up") fun signUp( - @RequestBody signUpVO: SignUpVO?, @CookieValue("session") token: String?, httpServletResponse: HttpServletResponse, + @RequestBody signUpVO: SignUpVO?, + @CookieValue("session") token: String?, + httpServletResponse: HttpServletResponse, httpServletRequest: HttpServletRequest ): ResponseEntity { // 检查是否允许注册 @@ -103,4 +103,26 @@ class UserController( } } } + + /** + * 获取用户信息组件 + */ + fun getUserCurrent( + @CookieValue("session") token: String?, httpServletRequest: HttpServletRequest, httpServletResponse: HttpServletResponse + ): ResponseEntity { + return if (token!= null) { + // 对 token 进行校验 + if (!tokenService.tokenVerify(token, httpServletResponse)) { + // 校验失败 + BusinessException().backInfo(ErrorCode.TOKEN_VERIFY_FAILED, httpServletRequest) + } else { + // 获取当前用户信息 + userService.getUserCurrent(token, httpServletRequest) + } + } else { + // 跳转至创建 Token 页面 + ResultUtil.redirect("/api/token/create", httpServletRequest) + } + } + } \ No newline at end of file diff --git a/src/main/kotlin/com/xlf/dromstarkotlin/controllers/ViewController.kt b/src/main/kotlin/com/xlf/dromstarkotlin/controllers/ViewController.kt index 80dc2e7..b5d5d7e 100644 --- a/src/main/kotlin/com/xlf/dromstarkotlin/controllers/ViewController.kt +++ b/src/main/kotlin/com/xlf/dromstarkotlin/controllers/ViewController.kt @@ -1,13 +1,13 @@ -package com.xlf.dromstarkotlin.controllers - -import org.springframework.stereotype.Controller -import org.springframework.web.bind.annotation.PathVariable -import org.springframework.web.bind.annotation.RequestMapping - -@Controller -class ViewController { - @RequestMapping("/{path:[^.]*}") - fun forward(@PathVariable path: String): String? { - return "forward:/index.html" - } +package com.xlf.dromstarkotlin.controllers + +import org.springframework.stereotype.Controller +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.RequestMapping + +@Controller +class ViewController { + @RequestMapping("/{path:[^.]*}/") + fun forward(@PathVariable path: String): String? { + return "forward:/index.html" + } } \ No newline at end of file diff --git a/src/main/kotlin/com/xlf/dromstarkotlin/entity/InfoDO.kt b/src/main/kotlin/com/xlf/dromstarkotlin/entity/InfoDO.kt new file mode 100644 index 0000000..afc7509 --- /dev/null +++ b/src/main/kotlin/com/xlf/dromstarkotlin/entity/InfoDO.kt @@ -0,0 +1,8 @@ +package com.xlf.dromstarkotlin.entity + +data class InfoDO ( + val id: Int, + val value: String, + val data: String? = null, + val commit: String, +) \ No newline at end of file diff --git a/src/main/kotlin/com/xlf/dromstarkotlin/mapper/InfoMapper.kt b/src/main/kotlin/com/xlf/dromstarkotlin/mapper/InfoMapper.kt index 0124708..6101762 100644 --- a/src/main/kotlin/com/xlf/dromstarkotlin/mapper/InfoMapper.kt +++ b/src/main/kotlin/com/xlf/dromstarkotlin/mapper/InfoMapper.kt @@ -1,5 +1,6 @@ package com.xlf.dromstarkotlin.mapper +import com.xlf.dromstarkotlin.entity.InfoDO import org.apache.ibatis.annotations.Mapper import org.apache.ibatis.annotations.Select @@ -14,4 +15,10 @@ interface InfoMapper { @Select("SELECT * FROM ds_info WHERE value = 'autoLogin'") fun autoLogin(): Boolean + + @Select("SELECT * FROM ds_info WHERE value = 'title'") + fun getTitle(): InfoDO + + @Select("SELECT * FROM ds_info WHERE value = 'sub_title'") + fun getSubTitle(): InfoDO } \ No newline at end of file diff --git a/src/main/kotlin/com/xlf/dromstarkotlin/mapper/LogMapper.kt b/src/main/kotlin/com/xlf/dromstarkotlin/mapper/LogMapper.kt new file mode 100644 index 0000000..9414beb --- /dev/null +++ b/src/main/kotlin/com/xlf/dromstarkotlin/mapper/LogMapper.kt @@ -0,0 +1,11 @@ +package com.xlf.dromstarkotlin.mapper + +import org.apache.ibatis.annotations.Mapper +import org.apache.ibatis.annotations.Select + +@Mapper +interface LogMapper { + + @Select("SELECT * FROM ds_login_log ORDER BY id DESC LIMIT 50") + fun getAutoLoginLog(): String +} diff --git a/src/main/kotlin/com/xlf/dromstarkotlin/services/AccountService.kt b/src/main/kotlin/com/xlf/dromstarkotlin/services/AccountService.kt index b6ef60e..634fadf 100644 --- a/src/main/kotlin/com/xlf/dromstarkotlin/services/AccountService.kt +++ b/src/main/kotlin/com/xlf/dromstarkotlin/services/AccountService.kt @@ -83,7 +83,7 @@ class AccountService( .build() try { val response = okHttpClient.newCall(request).execute() - val matcher = Pattern.compile("dr1003\\(([^)]+)\\)").matcher(response.body!!.string()) + val matcher = Pattern.compile("dr1002\\(([^)]+)\\)").matcher(response.body!!.string()) matcher.find() val getResponseBody = Gson().fromJson(matcher.group(1), HashMap::class.java) if (getResponseBody["result"] == "1") { diff --git a/src/main/kotlin/com/xlf/dromstarkotlin/services/InfoService.kt b/src/main/kotlin/com/xlf/dromstarkotlin/services/InfoService.kt new file mode 100644 index 0000000..5b29850 --- /dev/null +++ b/src/main/kotlin/com/xlf/dromstarkotlin/services/InfoService.kt @@ -0,0 +1,25 @@ +package com.xlf.dromstarkotlin.services + +import com.frontleaves.general.utils.BaseResponse +import com.frontleaves.general.utils.ResultUtil +import com.xlf.dromstarkotlin.mapper.InfoMapper +import jakarta.servlet.http.HttpServletRequest +import org.springframework.http.ResponseEntity +import org.springframework.stereotype.Service + +@Service +class InfoService( + val infoMapper: InfoMapper +) { + + /** + * 获取内容 + */ + fun getWebInfo(httpServletRequest: HttpServletRequest): ResponseEntity { + val hashMap = HashMap() + hashMap["title"] = infoMapper.getTitle().data + hashMap["sub_title"] = infoMapper.getSubTitle().data + return ResultUtil.success(hashMap, httpServletRequest) + } + +} diff --git a/src/main/kotlin/com/xlf/dromstarkotlin/services/LogService.kt b/src/main/kotlin/com/xlf/dromstarkotlin/services/LogService.kt new file mode 100644 index 0000000..f91f6aa --- /dev/null +++ b/src/main/kotlin/com/xlf/dromstarkotlin/services/LogService.kt @@ -0,0 +1,30 @@ +package com.xlf.dromstarkotlin.services + +import com.frontleaves.general.utils.BaseResponse +import com.frontleaves.general.utils.ErrorCode +import com.frontleaves.general.utils.ResultUtil +import com.xlf.dromstarkotlin.mapper.LogMapper +import jakarta.servlet.http.HttpServletRequest +import jakarta.servlet.http.HttpServletResponse +import org.springframework.http.ResponseEntity +import org.springframework.stereotype.Service + +@Service +class LogService( + val tokenService: TokenService, + val logMapper: LogMapper +) { + + /** + * 获取自动登录日志 + */ + fun getAutoLoginLog(token: String, httpServletRequest: HttpServletRequest, httpServletResponse: HttpServletResponse): ResponseEntity? { + // token 鉴权 + return if (tokenService.tokenVerify(token, httpServletResponse)) { + // 获取自动登录日志 + ResultUtil.success(logMapper.getAutoLoginLog(), httpServletRequest) + } else { + ResultUtil.error(ErrorCode.TOKEN_NOT_FOUNDED, httpServletRequest) + } + } +} diff --git a/src/main/kotlin/com/xlf/dromstarkotlin/services/ScheduleService.kt b/src/main/kotlin/com/xlf/dromstarkotlin/services/ScheduleService.kt index ca3c18b..b1aa4d6 100644 --- a/src/main/kotlin/com/xlf/dromstarkotlin/services/ScheduleService.kt +++ b/src/main/kotlin/com/xlf/dromstarkotlin/services/ScheduleService.kt @@ -49,7 +49,7 @@ class ScheduleService( /** * 登录校园网(5分钟自动检查) */ - @Scheduled(fixedDelay = 300000) + @Scheduled(fixedDelay = 60000) fun schoolLogin() { if (CacheData.autoLogin) { val calendar = Calendar.getInstance() @@ -64,12 +64,13 @@ class ScheduleService( accountService.regularLogin() } } else { - // 切换校园网 - do { - accountService.regularLogout() - Thread.sleep(5000) - } while (accountService.getInformation()?.get("uid") == null) - accountService.switchTheCampusNetwork() + if (accountService.getInformation()?.get("type") != null) { + do { + accountService.regularLogout() + Thread.sleep(5000) + accountService.switchTheCampusNetwork() + } while (accountService.getInformation()?.get("uid") == null) + } } } else { if (hour in 7 .. 23) { @@ -80,11 +81,13 @@ class ScheduleService( } } else{ // 切换校园网 - do { - accountService.regularLogout() - Thread.sleep(5000) - } while (accountService.getInformation()?.get("uid") == null) - accountService.switchTheCampusNetwork() + if (accountService.getInformation()?.get("type") != null) { + do { + accountService.regularLogout() + Thread.sleep(5000) + accountService.switchTheCampusNetwork() + } while (accountService.getInformation()?.get("uid") == null) + } } } } diff --git a/src/main/kotlin/com/xlf/dromstarkotlin/services/UserService.kt b/src/main/kotlin/com/xlf/dromstarkotlin/services/UserService.kt index 0cfbb8d..c83c9b6 100644 --- a/src/main/kotlin/com/xlf/dromstarkotlin/services/UserService.kt +++ b/src/main/kotlin/com/xlf/dromstarkotlin/services/UserService.kt @@ -81,4 +81,8 @@ class UserService( return ResultUtil.error(ErrorCode.USER_EXIST, httpServletRequest) } } + + fun getUserCurrent(token: String, httpServletRequest: HttpServletRequest): ResponseEntity { + TODO("Not yet implemented") + } } \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 7699b8b..18e838f 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,6 +1,6 @@ -server: - port: 8080 -spring: - web: - resources: +server: + port: 8080 +spring: + web: + resources: static-locations: classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,classpath:/static/frontend/ \ No newline at end of file