style: 修改了Repository命名
parent
254e76435a
commit
dbf1e3328d
|
@ -35,3 +35,4 @@ out/
|
|||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
logs
|
||||
|
|
|
@ -5,18 +5,18 @@ import cn.dev33.satoken.stp.StpUtil
|
|||
import cn.edu.hfut.auto.knowledge.entity.vo.LoginVO
|
||||
import cn.edu.hfut.auto.knowledge.exception.BusinessError
|
||||
import cn.edu.hfut.auto.knowledge.exception.ErrorCode
|
||||
import cn.edu.hfut.auto.knowledge.service.UserService
|
||||
import cn.edu.hfut.auto.knowledge.repository.UserRepository
|
||||
import org.springframework.web.bind.annotation.PostMapping
|
||||
import org.springframework.web.bind.annotation.RequestBody
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
|
||||
@RestController
|
||||
class AuthorizeController(
|
||||
private val userService: UserService
|
||||
private val userRepository: UserRepository
|
||||
) {
|
||||
@PostMapping("/login")
|
||||
fun login(@RequestBody vo: LoginVO) {
|
||||
val user = userService.findByUsername(vo.username)
|
||||
val user = userRepository.findByUsername(vo.username)
|
||||
?.takeIf { BCrypt.checkpw(vo.password, it.password) }
|
||||
?: throw BusinessError(ErrorCode.INVALID_USERNAME_OR_PASSWORD)
|
||||
StpUtil.login(user.id)
|
||||
|
|
|
@ -4,7 +4,7 @@ import cn.dev33.satoken.secure.BCrypt
|
|||
import cn.edu.hfut.auto.knowledge.entity.User
|
||||
import cn.edu.hfut.auto.knowledge.entity.by
|
||||
import cn.edu.hfut.auto.knowledge.entity.vo.LoginVO
|
||||
import cn.edu.hfut.auto.knowledge.service.UserService
|
||||
import cn.edu.hfut.auto.knowledge.repository.UserRepository
|
||||
import org.babyfish.jimmer.kt.new
|
||||
import org.springframework.context.annotation.Profile
|
||||
import org.springframework.web.bind.annotation.PostMapping
|
||||
|
@ -14,11 +14,11 @@ import org.springframework.web.bind.annotation.RestController
|
|||
@Profile("dev")
|
||||
@RestController
|
||||
class DevOnlyController(
|
||||
private val userService: UserService
|
||||
private val userRepository: UserRepository
|
||||
) {
|
||||
@PostMapping("/register")
|
||||
fun register(@RequestBody vo: LoginVO) {
|
||||
userService.insert(new(User::class).by {
|
||||
userRepository.insert(new(User::class).by {
|
||||
username = vo.username
|
||||
password = BCrypt.hashpw(vo.password)
|
||||
level = 2
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package cn.edu.hfut.auto.knowledge.service
|
||||
package cn.edu.hfut.auto.knowledge.repository
|
||||
|
||||
import cn.edu.hfut.auto.knowledge.entity.User
|
||||
import org.babyfish.jimmer.spring.repository.KRepository
|
||||
import org.babyfish.jimmer.sql.fetcher.Fetcher
|
||||
|
||||
interface UserService : KRepository<User, Long> {
|
||||
interface UserRepository : KRepository<User, Long> {
|
||||
fun findByUsername(username: String, fetcher: Fetcher<User>? = null): User?
|
||||
}
|
Loading…
Reference in New Issue