mirror of
https://github.com/getrebuild/rebuild.git
synced 2025-02-25 14:54:44 +08:00
#RB-16
This commit is contained in:
parent
f9534e9c5c
commit
172002c1d5
4 changed files with 26 additions and 9 deletions
|
@ -33,10 +33,15 @@ import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
import com.rebuild.server.Application;
|
||||||
|
import com.rebuild.server.metadata.EntityHelper;
|
||||||
import com.rebuild.server.service.bizz.CurrentCaller;
|
import com.rebuild.server.service.bizz.CurrentCaller;
|
||||||
|
import com.rebuild.server.service.bizz.UserService;
|
||||||
|
import com.rebuild.web.user.signin.LoginControll;
|
||||||
|
|
||||||
import cn.devezhao.commons.CalendarUtils;
|
import cn.devezhao.commons.CalendarUtils;
|
||||||
import cn.devezhao.commons.web.WebUtils;
|
import cn.devezhao.commons.web.WebUtils;
|
||||||
|
import cn.devezhao.persist4j.Record;
|
||||||
import cn.devezhao.persist4j.engine.ID;
|
import cn.devezhao.persist4j.engine.ID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -77,6 +82,14 @@ public class OnlineSessionStore extends CurrentCaller implements HttpSessionList
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Logout time
|
||||||
|
ID loginId = (ID) s.getAttribute(LoginControll.SK_LOGINID);
|
||||||
|
if (loginId != null) {
|
||||||
|
Record logout = EntityHelper.forUpdate(loginId, UserService.SYSTEM_USER);
|
||||||
|
logout.setDate("logoutTime", CalendarUtils.now());
|
||||||
|
Application.getCommonService().update(logout);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// --
|
// --
|
||||||
|
|
|
@ -54,11 +54,13 @@ import eu.bitwalker.useragentutils.UserAgent;
|
||||||
@RequestMapping("/user/")
|
@RequestMapping("/user/")
|
||||||
public class LoginControll extends BasePageControll {
|
public class LoginControll extends BasePageControll {
|
||||||
|
|
||||||
private static final String AUTOLOGIN_KEY = "rb.alt";
|
public static final String CK_AUTOLOGIN = "rb.alt";
|
||||||
|
|
||||||
|
public static final String SK_LOGINID = WebUtils.KEY_PREFIX + ".LOGINID";
|
||||||
|
|
||||||
@RequestMapping("login")
|
@RequestMapping("login")
|
||||||
public ModelAndView checkLogin(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
public ModelAndView checkLogin(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||||
String alt = ServletUtils.readCookie(request, AUTOLOGIN_KEY);
|
String alt = ServletUtils.readCookie(request, CK_AUTOLOGIN);
|
||||||
if (StringUtils.isNotBlank(alt)) {
|
if (StringUtils.isNotBlank(alt)) {
|
||||||
ID altUser = null;
|
ID altUser = null;
|
||||||
try {
|
try {
|
||||||
|
@ -168,15 +170,16 @@ public class LoginControll extends BasePageControll {
|
||||||
if (autoLogin) {
|
if (autoLogin) {
|
||||||
String alt = user + "," + System.currentTimeMillis();
|
String alt = user + "," + System.currentTimeMillis();
|
||||||
alt = AES.encrypt(alt);
|
alt = AES.encrypt(alt);
|
||||||
ServletUtils.addCookie(response, AUTOLOGIN_KEY, alt, 60 * 60 * 24 * 30, null, "/");
|
ServletUtils.addCookie(response, CK_AUTOLOGIN, alt, 60 * 60 * 24 * 30, null, "/");
|
||||||
} else {
|
} else {
|
||||||
ServletUtils.removeCookie(request, response, AUTOLOGIN_KEY);
|
ServletUtils.removeCookie(request, response, CK_AUTOLOGIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
loginLog(request, user);
|
ID loginId = loginLog(request, user);
|
||||||
|
ServletUtils.setSessionAttribute(request, SK_LOGINID, loginId);
|
||||||
|
|
||||||
ServletUtils.setSessionAttribute(request, WebUtils.CURRENT_USER, user);
|
ServletUtils.setSessionAttribute(request, WebUtils.CURRENT_USER, user);
|
||||||
Application.getSessionStore().storeLoginSuccessed(request);
|
Application.getSessionStore().storeLoginSuccessed(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -188,11 +191,13 @@ public class LoginControll extends BasePageControll {
|
||||||
String ipAddr = ServletUtils.getRemoteAddr(request);
|
String ipAddr = ServletUtils.getRemoteAddr(request);
|
||||||
String userAgent = request.getHeader("user-agent");
|
String userAgent = request.getHeader("user-agent");
|
||||||
UserAgent ua = UserAgent.parseUserAgentString(userAgent);
|
UserAgent ua = UserAgent.parseUserAgentString(userAgent);
|
||||||
|
String uaClean = String.format("%s-%s (%s)", ua.getBrowser(),
|
||||||
|
ua.getBrowserVersion().getMajorVersion(), ua.getOperatingSystem());
|
||||||
|
|
||||||
Record record = EntityHelper.forNew(EntityHelper.LoginLog, UserService.SYSTEM_USER);
|
Record record = EntityHelper.forNew(EntityHelper.LoginLog, UserService.SYSTEM_USER);
|
||||||
record.setID("user", user);
|
record.setID("user", user);
|
||||||
record.setString("ipAddr", ipAddr);
|
record.setString("ipAddr", ipAddr);
|
||||||
record.setString("userAgent", ua.toString());
|
record.setString("userAgent", uaClean);
|
||||||
record.setDate("loginTime", CalendarUtils.now());
|
record.setDate("loginTime", CalendarUtils.now());
|
||||||
record = Application.getCommonService().create(record);
|
record = Application.getCommonService().create(record);
|
||||||
return record.getPrimary();
|
return record.getPrimary();
|
||||||
|
@ -200,7 +205,7 @@ public class LoginControll extends BasePageControll {
|
||||||
|
|
||||||
@RequestMapping("logout")
|
@RequestMapping("logout")
|
||||||
public void logout(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
public void logout(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||||
ServletUtils.removeCookie(request, response, AUTOLOGIN_KEY);
|
ServletUtils.removeCookie(request, response, CK_AUTOLOGIN);
|
||||||
ServletUtils.getSession(request).invalidate();
|
ServletUtils.getSession(request).invalidate();
|
||||||
response.sendRedirect("login?exit=0");
|
response.sendRedirect("login?exit=0");
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,6 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<%@ include file="/_include/Foot.jsp"%>
|
<%@ include file="/_include/Foot.jsp"%>
|
||||||
<script>
|
<script>
|
||||||
window.__PageConfig = {
|
window.__PageConfig = {
|
||||||
|
|
Loading…
Reference in a new issue