|
|
@ -6,9 +6,9 @@ import io.ktor.request.* |
|
|
|
import io.ktor.response.* |
|
|
|
import io.ktor.response.* |
|
|
|
import io.ktor.routing.* |
|
|
|
import io.ktor.routing.* |
|
|
|
|
|
|
|
|
|
|
|
suspend inline fun <reified T : BaseVo> withToken(call: ApplicationCall, callback: (vo: T) -> Unit) { |
|
|
|
suspend inline fun <reified T : ClientBaseVo> withToken(call: ApplicationCall, callback: (vo: T) -> Unit) { |
|
|
|
val levelVo = call.receive<T>() |
|
|
|
val levelVo = call.receive<T>() |
|
|
|
if (AccountService.validToken(levelVo.token)) { |
|
|
|
if (AccountService.validToken(levelVo)) { |
|
|
|
callback(levelVo) |
|
|
|
callback(levelVo) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
call.respond(Simple.error("token校验失败")) |
|
|
|
call.respond(Simple.error("token校验失败")) |
|
|
@ -52,7 +52,7 @@ fun Application.AccountController() { |
|
|
|
|
|
|
|
|
|
|
|
//TODO 封装前后台登录逻辑 |
|
|
|
//TODO 封装前后台登录逻辑 |
|
|
|
route(path = "/login") { |
|
|
|
route(path = "/login") { |
|
|
|
route(path = ReceiverType.Foreground.name.toLowerCase()){ |
|
|
|
route(path = ClientType.Foreground.name.toLowerCase()){ |
|
|
|
post { |
|
|
|
post { |
|
|
|
val userLoginVo = call.receive<UserLoginVo>() |
|
|
|
val userLoginVo = call.receive<UserLoginVo>() |
|
|
|
val token = AccountService.login(userLoginVo, call.request.host()) |
|
|
|
val token = AccountService.login(userLoginVo, call.request.host()) |
|
|
@ -60,12 +60,12 @@ fun Application.AccountController() { |
|
|
|
} |
|
|
|
} |
|
|
|
post("/token"){ |
|
|
|
post("/token"){ |
|
|
|
val tokenVo = call.receive<Token>() |
|
|
|
val tokenVo = call.receive<Token>() |
|
|
|
val isValid = AccountService.validToken(tokenVo) |
|
|
|
val isValid = AccountService.validUserToken(tokenVo) |
|
|
|
call.respond(ApiResponse(message = if (isValid) "令牌合法" else "令牌不合法", body = isValid)) |
|
|
|
call.respond(ApiResponse(message = if (isValid) "令牌合法" else "令牌不合法", body = isValid)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
route(path = ReceiverType.Background.name.toLowerCase()){ |
|
|
|
route(path = ClientType.Background.name.toLowerCase()){ |
|
|
|
post{ |
|
|
|
post{ |
|
|
|
val managerLoginVo = call.receive<ManagerLoginVo>() |
|
|
|
val managerLoginVo = call.receive<ManagerLoginVo>() |
|
|
|
val token = AccountService.login(managerLoginVo, call.request.host()) |
|
|
|
val token = AccountService.login(managerLoginVo, call.request.host()) |
|
|
@ -83,9 +83,9 @@ fun Application.AccountController() { |
|
|
|
|
|
|
|
|
|
|
|
post(path = "/logout") { |
|
|
|
post(path = "/logout") { |
|
|
|
environment.log.info("退出登录") |
|
|
|
environment.log.info("退出登录") |
|
|
|
val userLogoutVo = call.receive<UserLogoutVo>() |
|
|
|
val onlyToken = call.receive<OnlyToken>() |
|
|
|
environment.log.info("$userLogoutVo") |
|
|
|
environment.log.info("$onlyToken") |
|
|
|
val flag = AccountService.logout(userLogoutVo.userId) |
|
|
|
val flag = AccountService.logout(onlyToken) |
|
|
|
call.respond(ApiResponse(message = if (flag) "退出成功" else "退出失败", body = flag)) |
|
|
|
call.respond(ApiResponse(message = if (flag) "退出成功" else "退出失败", body = flag)) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -146,8 +146,16 @@ fun Application.AssociationController() { |
|
|
|
} |
|
|
|
} |
|
|
|
post("/register"){ |
|
|
|
post("/register"){ |
|
|
|
withToken<RegAssociationVo>(call = call){ |
|
|
|
withToken<RegAssociationVo>(call = call){ |
|
|
|
|
|
|
|
try { |
|
|
|
val flag=AssociationService.register(vo=it) |
|
|
|
val flag=AssociationService.register(vo=it) |
|
|
|
call.respond(ApiResponse(message = if(flag) "社团注册资料已保存,请等待受理" else "社团注册资料保存失败",body=flag)) |
|
|
|
call.respond(ApiResponse(message = if(flag) "社团注册资料已提交,请等待受理" else "社团注册资料提交失败",body=flag)) |
|
|
|
|
|
|
|
} catch (e: UserIdError) { |
|
|
|
|
|
|
|
call.respond(ApiResponse(message = "社团资料提交失败,请联系管理员",body = false)) |
|
|
|
|
|
|
|
} catch (e:FileIdError){ |
|
|
|
|
|
|
|
call.respond(ApiResponse(message = "社团资料提交失败,请联系管理员",body = false)) |
|
|
|
|
|
|
|
}catch (e:HasAssociationError){ |
|
|
|
|
|
|
|
call.respond(ApiResponse(message = e.message?:"发生未知错误,请联系管理员",body = false)) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -163,10 +171,10 @@ enum class NotificationType{ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 通知接收客户端 |
|
|
|
* 客户端类型 |
|
|
|
* |
|
|
|
* |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
enum class ReceiverType{ |
|
|
|
enum class ClientType{ |
|
|
|
//前台 |
|
|
|
//前台 |
|
|
|
Foreground, |
|
|
|
Foreground, |
|
|
|
//后台 |
|
|
|
//后台 |
|
|
@ -179,7 +187,7 @@ enum class ReceiverType{ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
sealed class Receiver{ |
|
|
|
sealed class Receiver{ |
|
|
|
protected abstract val id:Int |
|
|
|
protected abstract val id:Int |
|
|
|
abstract val target:ReceiverType |
|
|
|
abstract val target:ClientType |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -187,14 +195,14 @@ sealed class Receiver{ |
|
|
|
* |
|
|
|
* |
|
|
|
* @property managerId 管理员id |
|
|
|
* @property managerId 管理员id |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
data class BackgroundReceiver(val managerId:Int,override val id: Int=managerId, override val target: ReceiverType=ReceiverType.Background):Receiver() |
|
|
|
data class BackgroundReceiver(val managerId:Int,override val id: Int=managerId, override val target: ClientType=ClientType.Background):Receiver() |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 前台客户端接收 |
|
|
|
* 前台客户端接收 |
|
|
|
* |
|
|
|
* |
|
|
|
* @property userId 用户id |
|
|
|
* @property userId 用户id |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
data class ForegroundReceiver(val userId:Int, override val id:Int=userId, override val target: ReceiverType=ReceiverType.Foreground):Receiver() |
|
|
|
data class ForegroundReceiver(val userId:Int, override val id:Int=userId, override val target: ClientType=ClientType.Foreground):Receiver() |
|
|
|
|
|
|
|
|
|
|
|
sealed class BaseNotification{ |
|
|
|
sealed class BaseNotification{ |
|
|
|
abstract val type:NotificationType |
|
|
|
abstract val type:NotificationType |
|
|
|