use of com.publiccms.entities.sys.SysAppClient in project PublicCMS-preview by sanluan.
the class AppClientDirective method execute.
@Override
public void execute(RenderHandler handler, SysApp app, SysUser user) throws IOException, Exception {
String uuid = handler.getString("uuid");
String clientVersion = handler.getString("clientVersion");
if (CommonUtils.notEmpty(uuid)) {
SysAppClientId sysAppClientId = new SysAppClientId(getSite(handler).getId(), app.getChannel(), uuid);
SysAppClient appClient = appClientService.getEntity(sysAppClientId);
if (null == appClient) {
appClient = new SysAppClient(sysAppClientId, CommonUtils.getDate(), false);
appClient.setClientVersion(clientVersion);
appClient.setLastLoginIp(RequestUtils.getIpAddress(handler.getRequest()));
appClientService.save(appClient);
} else {
appClientService.updateLastLogin(sysAppClientId, clientVersion, RequestUtils.getIpAddress(handler.getRequest()));
}
}
}
use of com.publiccms.entities.sys.SysAppClient in project PublicCMS-preview by sanluan.
the class SysAppClientAdminController method enable.
/**
* @param id
* @param request
* @param session
* @param model
* @return view name
*/
@RequestMapping(value = "enable", method = RequestMethod.POST)
public String enable(Long id, HttpServletRequest request, HttpSession session, ModelMap model) {
SysAppClient entity = service.getEntity(id);
if (null != entity.getId()) {
SysSite site = getSite(request);
if (ControllerUtils.verifyNotEquals("siteId", site.getId(), entity.getId().getSiteId(), model)) {
return TEMPLATE_ERROR;
}
service.updateStatus(id, false);
logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "enable.appclient", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
}
return TEMPLATE_DONE;
}
use of com.publiccms.entities.sys.SysAppClient in project PublicCMS-preview by sanluan.
the class CreateAppClientDirective method execute.
@Override
public void execute(RenderHandler handler) throws IOException, Exception {
String uuid = handler.getString("uuid");
String channel = handler.getString("channel");
Long userId = handler.getLong("userId");
if (CommonUtils.notEmpty(uuid) && CommonUtils.notEmpty(channel)) {
SysAppClientId sysAppClientId = new SysAppClientId(getSite(handler).getId(), channel, uuid);
SysAppClient appClient = appClientService.getEntity(sysAppClientId);
if (null == appClient) {
appClient = new SysAppClient(sysAppClientId, CommonUtils.getDate(), false);
appClient.setClientVersion(uuid);
appClient.setLastLoginIp(RequestUtils.getIpAddress(handler.getRequest()));
if (CommonUtils.notEmpty(userId)) {
appClient.setUserId(userId);
}
appClientService.save(appClient);
} else {
appClientService.updateLastLogin(sysAppClientId, uuid, RequestUtils.getIpAddress(handler.getRequest()));
appClientService.updateUser(sysAppClientId, userId);
}
handler.render();
}
}
use of com.publiccms.entities.sys.SysAppClient in project PublicCMS-preview by sanluan.
the class AutoLoginDirective method execute.
@Override
public void execute(RenderHandler handler, SysApp app, SysUser user) throws IOException, Exception {
String uuid = handler.getString("uuid");
boolean result = false;
if (CommonUtils.notEmpty(uuid)) {
SysSite site = getSite(handler);
SysAppClientId sysAppClientId = new SysAppClientId(site.getId(), app.getChannel(), uuid);
SysAppClient appClient = appClientService.getEntity(sysAppClientId);
if (null != appClient && CommonUtils.notEmpty(appClient.getUserId())) {
user = service.getEntity(appClient.getUserId());
if (null != user && !user.isDisabled()) {
String authToken = UUID.randomUUID().toString();
String ip = RequestUtils.getIpAddress(handler.getRequest());
sysUserTokenService.save(new SysUserToken(authToken, site.getId(), user.getId(), app.getChannel(), CommonUtils.getDate(), ip));
service.updateLoginStatus(user.getId(), ip);
logLoginService.save(new LogLogin(site.getId(), uuid, user.getId(), ip, app.getChannel(), true, CommonUtils.getDate(), null));
user.setPassword(null);
result = true;
handler.put("authToken", authToken).put("user", user);
}
}
}
handler.put("result", result);
}
use of com.publiccms.entities.sys.SysAppClient in project PublicCMS-preview by sanluan.
the class SysAppClientService method updateLastLogin.
/**
* @param id
* @param clientVersion
* @param ip
* @return
*/
public SysAppClient updateLastLogin(Serializable id, String clientVersion, String ip) {
SysAppClient entity = getEntity(id);
if (null != entity) {
entity.setClientVersion(clientVersion);
entity.setLastLoginDate(CommonUtils.getDate());
entity.setLastLoginIp(ip);
}
return entity;
}
Aggregations