diff --git a/.idea/AndroidProjectSystem.xml b/.idea/AndroidProjectSystem.xml
new file mode 100644
index 0000000..4a53bee
--- /dev/null
+++ b/.idea/AndroidProjectSystem.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 603e70a..f8809e4 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,5 +1,10 @@
+
+
+
+
+
diff --git a/backend/src/main/kotlin/com/github/sor2171/backend/service/WsTokenService.kt b/backend/src/main/kotlin/com/github/sor2171/backend/service/WsTokenService.kt
index 3515917..b381c9d 100644
--- a/backend/src/main/kotlin/com/github/sor2171/backend/service/WsTokenService.kt
+++ b/backend/src/main/kotlin/com/github/sor2171/backend/service/WsTokenService.kt
@@ -24,7 +24,7 @@ class WsTokenService(
expireTime: Long? = null,
): Mono {
val token = UUID.randomUUID().toString()
- val key = "$WS_REQUEST_TOKEN:${wsType.simpleName}:" + UUID.randomUUID().toString()
+ val key = "$WS_REQUEST_TOKEN:${wsType.simpleName}:$token"
return template.opsForValue().set(
key,
"1",
diff --git a/backend/src/main/kotlin/com/github/sor2171/backend/service/v1/AuthorizationService.kt b/backend/src/main/kotlin/com/github/sor2171/backend/service/v1/AuthorizationService.kt
index 996b47b..da5e5e9 100644
--- a/backend/src/main/kotlin/com/github/sor2171/backend/service/v1/AuthorizationService.kt
+++ b/backend/src/main/kotlin/com/github/sor2171/backend/service/v1/AuthorizationService.kt
@@ -114,7 +114,7 @@ class AuthorizationService(
}
fun jwtTokenRelogin(headerToken: String?): Mono? {
- val user = jwtUtils.resolveJwt(headerToken?.substring("Bearer ".length))
+ val user = jwtUtils.resolveJwt(headerToken)
?.let { jwtUtils.toUser(it) }
?: return null
val accountMono = accountService.findAccountByName(user.username)
diff --git a/backend/src/test/kotlin/com/github/sor2171/backend/BackendApplicationTests.kt b/backend/src/test/kotlin/com/github/sor2171/backend/BackendApplicationTests.kt
index ab79936..20fff0e 100644
--- a/backend/src/test/kotlin/com/github/sor2171/backend/BackendApplicationTests.kt
+++ b/backend/src/test/kotlin/com/github/sor2171/backend/BackendApplicationTests.kt
@@ -1,15 +1,49 @@
package com.github.sor2171.backend
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
+import com.github.sor2171.backend.entity.dto.Account
+import com.github.sor2171.backend.mapper.AccountMapper
+import com.github.sor2171.backend.utils.DateUtils
import org.junit.jupiter.api.Test
+import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
-import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
+import org.springframework.security.crypto.password.PasswordEncoder
@SpringBootTest
class BackendApplicationTests {
+ @Autowired
+ private lateinit var passwordEncoder: PasswordEncoder
+
+ @Autowired
+ private lateinit var accountMapper: AccountMapper
+
@Test
fun contextLoads() {
- println(BCryptPasswordEncoder().encode("123456"))
- }
+ val rawPassword = "123456"
+ val encodedPassword = passwordEncoder.encode(rawPassword)
+ println("==================================================================")
+ println("Default password '$rawPassword' BCrypt hash: $encodedPassword")
+ println("==================================================================")
+ val queryWrapper = QueryWrapper().eq("username", "test")
+ val existingAccount = accountMapper.selectOne(queryWrapper)
+
+ if (existingAccount == null) {
+ val newAccount = Account(
+ id = null,
+ username = "test",
+ password = encodedPassword,
+ email = "1234567890@gmail.com",
+ role = "user",
+ registerTime = DateUtils.getCurrentDateTime()
+ )
+ accountMapper.insert(newAccount)
+ println("Created default test user 'test' in database (ID: ${newAccount.id}).")
+ } else {
+ val updatedAccount = existingAccount.copy(password = encodedPassword)
+ accountMapper.updateById(updatedAccount)
+ println("Existing test user 'test' found (ID: ${existingAccount.id}), updated password hash.")
+ }
+ }
}
\ No newline at end of file