Search in sources :

Example 1 with SysAppClient

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()));
        }
    }
}
Also used : SysAppClient(com.publiccms.entities.sys.SysAppClient) SysAppClientId(com.publiccms.entities.sys.SysAppClientId)

Example 2 with SysAppClient

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;
}
Also used : LogOperate(com.publiccms.entities.log.LogOperate) SysAppClient(com.publiccms.entities.sys.SysAppClient) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with SysAppClient

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();
    }
}
Also used : SysAppClient(com.publiccms.entities.sys.SysAppClient) SysAppClientId(com.publiccms.entities.sys.SysAppClientId)

Example 4 with SysAppClient

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);
}
Also used : SysUserToken(com.publiccms.entities.sys.SysUserToken) LogLogin(com.publiccms.entities.log.LogLogin) SysAppClient(com.publiccms.entities.sys.SysAppClient) SysAppClientId(com.publiccms.entities.sys.SysAppClientId) SysSite(com.publiccms.entities.sys.SysSite)

Example 5 with SysAppClient

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;
}
Also used : SysAppClient(com.publiccms.entities.sys.SysAppClient)

Aggregations

SysAppClient (com.publiccms.entities.sys.SysAppClient)6 SysAppClientId (com.publiccms.entities.sys.SysAppClientId)3 SysSite (com.publiccms.entities.sys.SysSite)3 LogOperate (com.publiccms.entities.log.LogOperate)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 LogLogin (com.publiccms.entities.log.LogLogin)1 SysUserToken (com.publiccms.entities.sys.SysUserToken)1