From 2acb05e99873c7f8e22cd6685985b3730e0028f6 Mon Sep 17 00:00:00 2001 From: HanZiyao <49408466+h56983577@users.noreply.github.com> Date: Thu, 9 Jan 2025 17:02:22 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=B5=81=E7=A8=8B=E5=93=8D?= =?UTF-8?q?=E5=BA=94=E6=B6=88=E6=81=AF=E6=94=B9=E4=B8=BA=E4=B8=AD=E6=96=87?= =?UTF-8?q?=20(#72)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/kotlin/cn/edu/buaa/scs/auth/Token.kt | 2 +- .../src/main/kotlin/cn/edu/buaa/scs/route/Auth.kt | 12 ++++++------ .../src/main/kotlin/cn/edu/buaa/scs/service/Auth.kt | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/auth/Token.kt b/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/auth/Token.kt index d0918c5..48b8f20 100644 --- a/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/auth/Token.kt +++ b/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/auth/Token.kt @@ -110,7 +110,7 @@ fun fetchToken(call: ApplicationCall) { // redis uuid token authRedis.checkToken(token) ?: // error - throw throw AuthorizationException("incorrect token") + throw throw AuthorizationException("登录已过期,请重新登录") val user = User.id(userId) setUser(user) diff --git a/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/route/Auth.kt b/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/route/Auth.kt index b3034c9..b2d5abe 100644 --- a/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/route/Auth.kt +++ b/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/route/Auth.kt @@ -39,7 +39,7 @@ fun Route.authRoute() { route("buaaSSOLogin") { post { - val ssoToken = call.request.queryParameters["ssoToken"] ?: throw BadRequestException("ssoToken is required") + val ssoToken = call.request.queryParameters["ssoToken"] ?: throw BadRequestException("请传入统一认证 token") call.respond( call.auth.buaaSSOLogin(ssoToken) ) @@ -55,8 +55,8 @@ fun Route.authRoute() { route("/tokenInfo") { post { val req = call.receiveParameters() - val token = req["token"] ?: throw BadRequestException("token is required") - val service = req["service"] ?: throw BadRequestException("service is required") + val token = req["token"] ?: throw BadRequestException("请传入统一认证 token") + val service = req["service"] ?: throw BadRequestException("请传入统一认证服务名") call.respond( call.auth.getTokenInfo(token, service) ) @@ -65,9 +65,9 @@ fun Route.authRoute() { route("/checkPermission") { get { - val entityType = call.parameters["entityType"] ?: throw BadRequestException("entityType is required") - val entityId = call.parameters["entityId"] ?: throw BadRequestException("entityId is required") - val action = call.parameters["action"] ?: throw BadRequestException("action is required") + val entityType = call.parameters["entityType"] ?: throw BadRequestException("请传入对象类型") + val entityId = call.parameters["entityId"] ?: throw BadRequestException("请传入对象Id") + val action = call.parameters["action"] ?: throw BadRequestException("请传入动作") call.respond(call.auth.checkPermission(entityType, entityId, action)) } } diff --git a/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/service/Auth.kt b/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/service/Auth.kt index 5656260..1b5685c 100644 --- a/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/service/Auth.kt +++ b/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/service/Auth.kt @@ -73,11 +73,11 @@ class AuthService(val call: ApplicationCall) : IService { ): LoginUserResponse { // check useId if (!mysql.users.exists { it.id.eq(userId) }) { - throw BadRequestException("") + throw BadRequestException("用户名或密码错误") } // check password val user = mysql.users.find { it.id.eq(userId) and it.password.eq(passwordHash) } - ?: throw BadRequestException("") + ?: throw BadRequestException("用户名或密码错误") // check active if (!user.isAccepted) { throw BadRequestException("账号未激活,或信息不完整,请重新激活账户") @@ -194,7 +194,7 @@ class AuthService(val call: ApplicationCall) : IService { fun sendActiveEmail(id: String, name: String, email: String) { val user = User.id(id) if (user.isAccepted) { - throw cn.edu.buaa.scs.error.BadRequestException("the user is already active") + throw cn.edu.buaa.scs.error.BadRequestException("用户已经激活") } val token = "${user.id}${user.password}${System.currentTimeMillis()}".md5() + UlidCreator.getUlid().toString()