加入註冊功能(草稿)
This commit is contained in:
parent
09a12c100d
commit
34ccc697dc
@ -12,6 +12,5 @@ fun Application.module() {
|
||||
DatabaseFactory.init()
|
||||
DatabaseFactory.createTable()
|
||||
configureRouting()
|
||||
configureSerialization()
|
||||
configureSecurity()
|
||||
}
|
||||
|
||||
6
src/main/kotlin/com/ray650128/model/LoginBody.kt
Normal file
6
src/main/kotlin/com/ray650128/model/LoginBody.kt
Normal file
@ -0,0 +1,6 @@
|
||||
package com.ray650128.model
|
||||
|
||||
data class LoginBody(
|
||||
val account: String,
|
||||
val password: String
|
||||
)
|
||||
@ -1,11 +1,11 @@
|
||||
package com.ray650128.model
|
||||
|
||||
data class User(
|
||||
var id: Long,
|
||||
var name: String,
|
||||
var id: Long = -1,
|
||||
var name: String = "",
|
||||
var account: String,
|
||||
var password: String,
|
||||
var token: String,
|
||||
var createTime: Long,
|
||||
var updateTime: Long
|
||||
var token: String = "",
|
||||
var createTime: Long = -1,
|
||||
var updateTime: Long = -1
|
||||
)
|
||||
|
||||
@ -1,16 +1,41 @@
|
||||
package com.ray650128.plugins
|
||||
|
||||
import com.ray650128.model.LoginBody
|
||||
import com.ray650128.model.User
|
||||
import com.ray650128.repository.UserRepository
|
||||
import io.ktor.server.routing.*
|
||||
import io.ktor.http.*
|
||||
import io.ktor.serialization.gson.*
|
||||
import io.ktor.server.application.*
|
||||
import io.ktor.server.plugins.contentnegotiation.*
|
||||
import io.ktor.server.response.*
|
||||
import io.ktor.server.request.*
|
||||
|
||||
fun Application.configureRouting() {
|
||||
|
||||
val userRepository = UserRepository()
|
||||
|
||||
install(ContentNegotiation) {
|
||||
gson {
|
||||
}
|
||||
}
|
||||
|
||||
routing {
|
||||
get("/") {
|
||||
call.respondText("Hello World!")
|
||||
}
|
||||
|
||||
post("/api/v1/register") {
|
||||
val body = call.receive<LoginBody>()
|
||||
val data = User(
|
||||
account = body.account,
|
||||
password = body.password
|
||||
)
|
||||
userRepository.add(data)
|
||||
call.respond(
|
||||
status = HttpStatusCode.OK,
|
||||
message = mapOf("token" to "aaaaaaa")
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,21 +0,0 @@
|
||||
package com.ray650128.plugins
|
||||
|
||||
import io.ktor.serialization.gson.*
|
||||
import io.ktor.server.plugins.contentnegotiation.*
|
||||
import io.ktor.server.application.*
|
||||
import io.ktor.server.response.*
|
||||
import io.ktor.server.request.*
|
||||
import io.ktor.server.routing.*
|
||||
|
||||
fun Application.configureSerialization() {
|
||||
install(ContentNegotiation) {
|
||||
gson {
|
||||
}
|
||||
}
|
||||
|
||||
routing {
|
||||
get("/json/gson") {
|
||||
call.respond(mapOf("hello" to "world"))
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user