Browse Source

修复登录错误问题

NorthLan 7 years ago
parent
commit
614a268449

+ 35 - 30
zen-web/src/main/kotlin/com/gxzc/zen/web/sys/controller/AuthController.kt

@@ -1,11 +1,16 @@
 package com.gxzc.zen.web.sys.controller
 
+import com.baomidou.kisso.SSOConfig
 import com.baomidou.kisso.SSOHelper
+import com.baomidou.kisso.SSOToken
 import com.baomidou.kisso.annotation.Action
 import com.baomidou.kisso.annotation.Login
 import com.gxzc.zen.api.sys.service.ISysUserService
 import com.gxzc.zen.common.base.BaseController
 import com.gxzc.zen.common.dto.RequestDto
+import com.gxzc.zen.common.exception.ZenException
+import com.gxzc.zen.common.exception.ZenExceptionEnum
+import com.gxzc.zen.umps.util.MD5Salt
 import io.swagger.annotations.ApiOperation
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.http.ResponseEntity
@@ -27,36 +32,36 @@ class AuthController : BaseController() {
     @ApiOperation(value = "登录")
     @PostMapping("/login")
     fun login(@RequestBody data: RequestDto): ResponseEntity<*> {
-//        // 验证输入合法性
-//        val account = data.data["account"]?.toString()?.trim()
-//        val password = data.data["password"]?.toString()
-//        val rememberMe = data.data["rememberMe"]?.let { it as Boolean }
-//
-//        if (account.isNullOrEmpty() || password.isNullOrEmpty()) {
-//            throw ZenException(ZenExceptionEnum.REQUEST_NULL)
-//        }
-//        // 验证账号密码
-//        val user = userService.getUserByAccountCacheable(account!!)
-//                ?: throw ZenException(ZenExceptionEnum.AUTH_ACCOUNT_NOT_EXISTS)
-//        // 对密码进行盐值处理比对
-//        if (user.password != MD5Salt.md5SaltEncode(user.salt!!, password!!)) {
-//            throw ZenException(ZenExceptionEnum.AUTH_PASSWORD_ERROR)
-//        }
-//
-//        // 生成登陆 token->cookie
-//        if (rememberMe != null && rememberMe) {
-//            SSOConfig.getInstance().cookieMaxage = 604800
-//        } else {
-//            val attrMaxAge = getRequest().getAttribute(SSOConfig.SSO_COOKIE_MAXAGE)?.let {
-//                it as Int
-//            }
-//            if (attrMaxAge != null) {
-//                getRequest().removeAttribute(SSOConfig.SSO_COOKIE_MAXAGE)
-//            }
-//        }
-//        SSOHelper.setSSOCookie(getRequest(), getResponse(), SSOToken().also {
-//            it.uid = user.id.toString()
-//        }, true)
+        // 验证输入合法性
+        val account = data["account"]?.toString()?.trim()
+        val password = data["password"]?.toString()
+        val rememberMe = data["rememberMe"]?.let { it as Boolean }
+
+        if (account.isNullOrEmpty() || password.isNullOrEmpty()) {
+            throw ZenException(ZenExceptionEnum.REQUEST_NULL)
+        }
+        // 验证账号密码
+        val user = userService.getUserByAccountCacheable(account!!)
+                ?: throw ZenException(ZenExceptionEnum.AUTH_ACCOUNT_NOT_EXISTS)
+        // 对密码进行盐值处理比对
+        if (user.password != MD5Salt.md5SaltEncode(user.salt!!, password!!)) {
+            throw ZenException(ZenExceptionEnum.AUTH_PASSWORD_ERROR)
+        }
+
+        // 生成登陆 token->cookie
+        if (rememberMe != null && rememberMe) {
+            SSOConfig.getInstance().cookieMaxage = 604800
+        } else {
+            val attrMaxAge = getRequest().getAttribute(SSOConfig.SSO_COOKIE_MAXAGE)?.let {
+                it as Int
+            }
+            if (attrMaxAge != null) {
+                getRequest().removeAttribute(SSOConfig.SSO_COOKIE_MAXAGE)
+            }
+        }
+        SSOHelper.setSSOCookie(getRequest(), getResponse(), SSOToken().also {
+            it.uid = user.id.toString()
+        }, true)
         return ResponseEntity.ok(null)
     }
 

+ 1 - 7
zen-web/src/main/kotlin/com/gxzc/zen/web/sys/controller/SysDicController.kt

@@ -5,8 +5,6 @@ import com.gxzc.zen.api.sys.service.ISysDicService
 import com.gxzc.zen.common.base.BaseController
 import com.gxzc.zen.common.config.response.annotation.ZenResponseFilter
 import com.gxzc.zen.common.dto.ResponseDto
-import com.gxzc.zen.common.exception.ZenException
-import com.gxzc.zen.common.exception.ZenExceptionEnum
 import org.slf4j.LoggerFactory
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.http.ResponseEntity
@@ -46,11 +44,7 @@ class SysDicController : BaseController() {
 
     @PutMapping("{key}")
     @ZenResponseFilter(type = SysDic::class, filter = ["createBy", "updateBy", "createTime", "updateTime"])
-    fun putDic(@PathVariable key: String, @RequestBody requestDic: SysDic?): ResponseEntity<*> {
-        if (requestDic == null) {
-            throw ZenException(ZenExceptionEnum.REQUEST_NULL)
-        }
-
+    fun putDic(@PathVariable key: String, @RequestBody requestDic: SysDic): ResponseEntity<*> {
         return ResponseEntity.ok(ResponseDto().apply {
             data = sysDicService.modifySysDic(requestDic)
         })