org.zodiac.monitor.console.ui.AbstractUiController Maven / Gradle / Ivy
package org.zodiac.monitor.console.ui;
import org.zodiac.commons.util.lang.Strings;
import org.zodiac.monitor.console.constants.MonitorConsoleConstants;
import org.zodiac.monitor.console.model.UserInfo;
import org.zodiac.sdk.toolkit.util.lang.StrUtil;
/**
* @author zodiac
*/
//@Controller
public abstract class AbstractUiController {
private UserInfo userInfo;
public AbstractUiController() {}
public AbstractUiController(UserInfo userInfo) {
this.userInfo = userInfo;
}
public String index(String monitorId) {
/*不设置用户名密码直接返回成功*/
if (userInfo.getUsername() == null || userInfo.getPassword() == null) {
return "redirect:/monitor/index.html";
}
if (monitorId != null && monitorId.equals(userInfo.getUsernameToken())) {
return "redirect:/monitor/index.html";
}
return "redirect:/monitor/login.html";
}
public String context() {
String uri = contextPath();
if (!uri.endsWith("/")) {
uri = uri + "/";
}
return uri;
}
public String setCookies(String reqUserName, String reqPassword) {
/*不设置用户名密码直接返回成功。*/
if (userInfo.getUsername() == null || userInfo.getPassword() == null) {
return "redirect:/monitor/index.html";
}
if (reqUserName == null || reqPassword == null) {
return "redirect:/monitor/login.html";
}
if (StrUtil.isNotEmpty(reqUserName) && StrUtil.isNotEmpty(reqPassword)) {
if (reqUserName.equals(userInfo.getUsername()) && reqPassword.equals(userInfo.getPassword())) {
addMonitorIdCookie(MonitorConsoleConstants.CONSOLE_MONITOR_ID_COOKIE_NAME, userInfo.getUsernameToken());
// Cookie cookie = new Cookie(MonitorConsoleConstants.CONSOLE_MONITOR_ID_COOKIE_NAME, userInfo.getUserNameToken());
// response.addCookie(cookie);
return "redirect:/monitor/index.html";
}
}
return "redirect:/monitor/login.html";
}
protected abstract String contextPath();
protected abstract void addMonitorIdCookie(String monitorId, String monitorValue);
}