|
@@ -1,15 +1,19 @@
|
|
package com.sooka.web.controller.system;
|
|
package com.sooka.web.controller.system;
|
|
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
+
|
|
|
|
+import com.sooka.framework.util.ShiroUtils;
|
|
|
|
+import com.sooka.system.domain.SysUser;
|
|
|
|
+import com.sooka.system.service.ISysUserService;
|
|
import org.apache.shiro.SecurityUtils;
|
|
import org.apache.shiro.SecurityUtils;
|
|
import org.apache.shiro.authc.AuthenticationException;
|
|
import org.apache.shiro.authc.AuthenticationException;
|
|
import org.apache.shiro.authc.UsernamePasswordToken;
|
|
import org.apache.shiro.authc.UsernamePasswordToken;
|
|
import org.apache.shiro.subject.Subject;
|
|
import org.apache.shiro.subject.Subject;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.stereotype.Controller;
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
+import org.springframework.ui.ModelMap;
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
import com.sooka.common.core.controller.BaseController;
|
|
import com.sooka.common.core.controller.BaseController;
|
|
import com.sooka.common.core.domain.AjaxResult;
|
|
import com.sooka.common.core.domain.AjaxResult;
|
|
import com.sooka.common.utils.ServletUtils;
|
|
import com.sooka.common.utils.ServletUtils;
|
|
@@ -21,14 +25,11 @@ import com.sooka.common.utils.StringUtils;
|
|
* @author lei_wang
|
|
* @author lei_wang
|
|
*/
|
|
*/
|
|
@Controller
|
|
@Controller
|
|
-public class SysLoginController extends BaseController
|
|
|
|
-{
|
|
|
|
|
|
+public class SysLoginController extends BaseController {
|
|
@GetMapping("/login")
|
|
@GetMapping("/login")
|
|
- public String login(HttpServletRequest request, HttpServletResponse response)
|
|
|
|
- {
|
|
|
|
|
|
+ public String login(HttpServletRequest request, HttpServletResponse response) {
|
|
// 如果是Ajax请求,返回Json字符串。
|
|
// 如果是Ajax请求,返回Json字符串。
|
|
- if (ServletUtils.isAjaxRequest(request))
|
|
|
|
- {
|
|
|
|
|
|
+ if (ServletUtils.isAjaxRequest(request)) {
|
|
return ServletUtils.renderString(response, "{\"code\":\"1\",\"msg\":\"未登录或登录超时。请重新登录\"}");
|
|
return ServletUtils.renderString(response, "{\"code\":\"1\",\"msg\":\"未登录或登录超时。请重新登录\"}");
|
|
}
|
|
}
|
|
|
|
|
|
@@ -37,11 +38,9 @@ public class SysLoginController extends BaseController
|
|
|
|
|
|
|
|
|
|
@GetMapping("/syslogin")
|
|
@GetMapping("/syslogin")
|
|
- public String syslogin(HttpServletRequest request, HttpServletResponse response)
|
|
|
|
- {
|
|
|
|
|
|
+ public String syslogin(HttpServletRequest request, HttpServletResponse response) {
|
|
// 如果是Ajax请求,返回Json字符串。
|
|
// 如果是Ajax请求,返回Json字符串。
|
|
- if (ServletUtils.isAjaxRequest(request))
|
|
|
|
- {
|
|
|
|
|
|
+ if (ServletUtils.isAjaxRequest(request)) {
|
|
return ServletUtils.renderString(response, "{\"code\":\"1\",\"msg\":\"未登录或登录超时。请重新登录\"}");
|
|
return ServletUtils.renderString(response, "{\"code\":\"1\",\"msg\":\"未登录或登录超时。请重新登录\"}");
|
|
}
|
|
}
|
|
|
|
|
|
@@ -49,26 +48,31 @@ public class SysLoginController extends BaseController
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ ISysUserService iSysUserService;
|
|
|
|
+ @ResponseBody
|
|
|
|
+ @RequestMapping("getuserinfo")
|
|
|
|
+ public AjaxResult getuserinfo(){
|
|
|
|
+ String loginname =getSession().getAttribute("loginusername").toString();
|
|
|
|
+ SysUser sysUser = iSysUserService.selectUserByLoginName(loginname);
|
|
|
|
+ return AjaxResult.success(sysUser);
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
@PostMapping("/login")
|
|
@PostMapping("/login")
|
|
@ResponseBody
|
|
@ResponseBody
|
|
- public AjaxResult ajaxLogin(String username, String password, Boolean rememberMe)
|
|
|
|
- {
|
|
|
|
|
|
+ public AjaxResult ajaxLogin(String username, String password, Boolean rememberMe, ModelMap map) {
|
|
UsernamePasswordToken token = new UsernamePasswordToken(username, password, rememberMe);
|
|
UsernamePasswordToken token = new UsernamePasswordToken(username, password, rememberMe);
|
|
Subject subject = SecurityUtils.getSubject();
|
|
Subject subject = SecurityUtils.getSubject();
|
|
- try
|
|
|
|
- {
|
|
|
|
|
|
+ try {
|
|
String loginname = token.getUsername();
|
|
String loginname = token.getUsername();
|
|
- getSession().setAttribute("loginusername",loginname);
|
|
|
|
|
|
+ getSession().setAttribute("loginusername", loginname);
|
|
subject.login(token);
|
|
subject.login(token);
|
|
|
|
+ map.put("deptId", ShiroUtils.getSysUser().getDeptId());
|
|
return success();
|
|
return success();
|
|
- }
|
|
|
|
- catch (AuthenticationException e)
|
|
|
|
- {
|
|
|
|
|
|
+ } catch (AuthenticationException e) {
|
|
String msg = "用户或密码错误";
|
|
String msg = "用户或密码错误";
|
|
- if (StringUtils.isNotEmpty(e.getMessage()))
|
|
|
|
- {
|
|
|
|
|
|
+ if (StringUtils.isNotEmpty(e.getMessage())) {
|
|
msg = e.getMessage();
|
|
msg = e.getMessage();
|
|
}
|
|
}
|
|
return error(msg);
|
|
return error(msg);
|
|
@@ -76,8 +80,7 @@ public class SysLoginController extends BaseController
|
|
}
|
|
}
|
|
|
|
|
|
@GetMapping("/unauth")
|
|
@GetMapping("/unauth")
|
|
- public String unauth()
|
|
|
|
- {
|
|
|
|
|
|
+ public String unauth() {
|
|
return "error/unauth";
|
|
return "error/unauth";
|
|
}
|
|
}
|
|
}
|
|
}
|