You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
2.3 KiB
60 lines
2.3 KiB
package com.gyf.csams
|
|
|
|
import io.ktor.application.*
|
|
import io.ktor.features.*
|
|
import io.ktor.request.*
|
|
import io.ktor.response.*
|
|
import io.ktor.routing.*
|
|
|
|
|
|
fun Application.AccountController() {
|
|
|
|
routing {
|
|
route(path = "$ApiPathPrefix/account"){
|
|
route(path="/register") {
|
|
/**
|
|
* 检测学号是否已注册
|
|
*/
|
|
get(path = "/checkId") {
|
|
val studentId = call.request.queryParameters["studentId"]
|
|
if (studentId?.isNotEmpty() == true) {
|
|
if (AccountService.registered(studentId)) {
|
|
call.respond(ApiResponse(message = "学号已注册", body = true))
|
|
} else {
|
|
call.respond(ApiResponse(message = "学号可注册", body = false))
|
|
}
|
|
} else {
|
|
call.respond(Simple.error("学号检测失败,请联系管理员"))
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 注册账号
|
|
*/
|
|
post {
|
|
val userVo = call.receive<UserVo>()
|
|
val userResDto = AccountService.register(userVo)
|
|
if (userResDto != null) {
|
|
call.respond(ApiResponse(message = "注册成功", body = userResDto))
|
|
} else {
|
|
call.respond(Simple.error("注册失败"))
|
|
}
|
|
}
|
|
}
|
|
|
|
route(path = "/login"){
|
|
post{
|
|
val userLoginVo= call.receive<UserLoginVo>()
|
|
val tokenResDto:TokenResDto=AccountService.login(userLoginVo,call.request.origin.remoteHost)
|
|
call.respond(ApiResponse(message = if(tokenResDto.token!=null) "登陆成功" else "账号或密码错误!!!",body = tokenResDto))
|
|
}
|
|
post(path = "/token"){
|
|
val tokenVo=call.receive<TokenVo>()
|
|
val isValid=AccountService.validToken(tokenVo)
|
|
call.respond(ApiResponse(message = if(isValid) "令牌合法" else "令牌不合法",body = isValid))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|