|
@ -1,14 +1,21 @@
|
|
|
package com.yihu.hos.common;
|
|
|
|
|
|
import com.yihu.hos.web.framework.util.PKUtil;
|
|
|
import com.yihu.hos.web.framework.util.controller.BaseController;
|
|
|
import com.yihu.hos.system.model.SystemUser;
|
|
|
import com.yihu.hos.tenant.service.AuthenticateService;
|
|
|
import com.yihu.hos.web.framework.util.controller.BaseController;
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.ui.Model;
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.servlet.http.HttpSession;
|
|
|
import java.io.IOException;
|
|
|
import java.io.PrintWriter;
|
|
|
|
|
|
/**
|
|
|
* 数据采集配置页面
|
|
@ -18,14 +25,85 @@ import javax.servlet.http.HttpSession;
|
|
|
@Controller("commonPageController")
|
|
|
public class CommonPageController extends BaseController {
|
|
|
|
|
|
@Value("${spring.administrators}")
|
|
|
private String saasAdmin;
|
|
|
|
|
|
@Autowired
|
|
|
private AuthenticateService authenticateService;
|
|
|
|
|
|
/*
|
|
|
登录页面
|
|
|
*/
|
|
|
@RequestMapping("loginPage")
|
|
|
public String login(Model model) {
|
|
|
public String login(Model model, HttpServletRequest request,HttpServletResponse response) {
|
|
|
HttpSession session = request.getSession();
|
|
|
try {
|
|
|
boolean auth = authenticateService.auth(session, saasAdmin);
|
|
|
if (!auth){
|
|
|
//授权失败
|
|
|
response.setCharacterEncoding("UTF-8");
|
|
|
response.setHeader("Content-type", "text/html;charset=UTF-8");
|
|
|
PrintWriter out = null;
|
|
|
try {
|
|
|
out = response.getWriter();
|
|
|
out.print("<script>alert('登录地址有误-用户授权失败!');</script>");
|
|
|
response.sendRedirect("/esb/loginPage");
|
|
|
out.flush();
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
} finally {
|
|
|
IOUtils.closeQuietly(out);
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
|
|
|
model.addAttribute("contentPage","/common/login");
|
|
|
return "pageView";
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 租户登录页面
|
|
|
* @param model
|
|
|
* @param tenantName
|
|
|
* @param request
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping("{tenantName}/loginPage")
|
|
|
public String tenantLogin(Model model,
|
|
|
@PathVariable(name = "tenantName") String tenantName,
|
|
|
HttpServletRequest request,HttpServletResponse response) throws IOException {
|
|
|
HttpSession session = request.getSession();
|
|
|
boolean auth = false;
|
|
|
try {
|
|
|
auth = authenticateService.auth(session, tenantName);
|
|
|
System.out.println("auth: "+auth);
|
|
|
if (!auth) {
|
|
|
//授权失败,切换回管理平台数据库
|
|
|
auth = authenticateService.auth(session, saasAdmin);
|
|
|
response.setCharacterEncoding("UTF-8");
|
|
|
response.setHeader("Content-type", "text/html;charset=UTF-8");
|
|
|
PrintWriter out = null;
|
|
|
try {
|
|
|
out = response.getWriter();
|
|
|
out.print("<script>alert('请求地址不存在!');</script>");
|
|
|
response.sendRedirect("/esb/loginPage");
|
|
|
out.flush();
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
} finally {
|
|
|
IOUtils.closeQuietly(out);
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
|
|
|
model.addAttribute("contentPage","/common/login");
|
|
|
return "pageView";
|
|
|
|
|
|
}
|
|
|
|
|
|
/*
|