mirror of
https://github.com/SOR2171/Springboot4-Vue3_Demo.git
synced 2026-10-23 19:41:12 +08:00
refactor
This commit is contained in:
Generated
+6
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="AndroidProjectSystem">
|
||||||
|
<option name="providerId" value="com.android.tools.idea.GradleProjectSystem" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
+5
@@ -1,5 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
|
<component name="EntryPointsManager">
|
||||||
|
<list size="1">
|
||||||
|
<item index="0" class="java.lang.String" itemvalue="org.apache.ibatis.type.MappedJdbcTypes" />
|
||||||
|
</list>
|
||||||
|
</component>
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
<component name="FrameworkDetectionExcludesConfiguration">
|
<component name="FrameworkDetectionExcludesConfiguration">
|
||||||
<file type="web" url="file://$PROJECT_DIR$/backend" />
|
<file type="web" url="file://$PROJECT_DIR$/backend" />
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ class WsTokenService(
|
|||||||
expireTime: Long? = null,
|
expireTime: Long? = null,
|
||||||
): Mono<String> {
|
): Mono<String> {
|
||||||
val token = UUID.randomUUID().toString()
|
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(
|
return template.opsForValue().set(
|
||||||
key,
|
key,
|
||||||
"1",
|
"1",
|
||||||
|
|||||||
+1
-1
@@ -114,7 +114,7 @@ class AuthorizationService(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun jwtTokenRelogin(headerToken: String?): Mono<ReloginVO>? {
|
fun jwtTokenRelogin(headerToken: String?): Mono<ReloginVO>? {
|
||||||
val user = jwtUtils.resolveJwt(headerToken?.substring("Bearer ".length))
|
val user = jwtUtils.resolveJwt(headerToken)
|
||||||
?.let { jwtUtils.toUser(it) }
|
?.let { jwtUtils.toUser(it) }
|
||||||
?: return null
|
?: return null
|
||||||
val accountMono = accountService.findAccountByName(user.username)
|
val accountMono = accountService.findAccountByName(user.username)
|
||||||
|
|||||||
@@ -1,15 +1,49 @@
|
|||||||
package com.github.sor2171.backend
|
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.junit.jupiter.api.Test
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
import org.springframework.boot.test.context.SpringBootTest
|
import org.springframework.boot.test.context.SpringBootTest
|
||||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
|
import org.springframework.security.crypto.password.PasswordEncoder
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
class BackendApplicationTests {
|
class BackendApplicationTests {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private lateinit var passwordEncoder: PasswordEncoder
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private lateinit var accountMapper: AccountMapper
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun contextLoads() {
|
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<Account>().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.")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user