Search in sources :

Example 1 with Log

use of com.dimple.framework.aspectj.lang.annotation.Log in project DimpleBlog by martin-chips.

the class SettingController method editSiteSetting.

@PutMapping("siteSetting")
@PreAuthorize("@permissionService.hasPermission('system:setting:siteSetting:edit')")
@Log(title = "系统设置-网站设置", businessType = BusinessType.UPDATE)
public AjaxResult editSiteSetting(@RequestBody SiteSetting siteSetting) {
    String jsonString = JSON.toJSONString(siteSetting);
    Config config = new Config();
    config.setConfigKey(ConfigKey.CONFIG_KEY_SITE_SETTING);
    config.setConfigValue(jsonString);
    return AjaxResult.success(configService.updateConfigByConfigKey(config));
}
Also used : Config(com.dimple.project.system.domain.Config) Log(com.dimple.framework.aspectj.lang.annotation.Log) PutMapping(org.springframework.web.bind.annotation.PutMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 2 with Log

use of com.dimple.framework.aspectj.lang.annotation.Log in project DimpleBlog by martin-chips.

the class LogAspect method handleLog.

/**
 * for log record
 *
 * @param joinPoint  join point
 * @param e          exception
 * @param jsonResult result
 * @param cost       the time of this method cost
 */
protected void handleLog(final JoinPoint joinPoint, final Exception e, Object jsonResult, long cost) {
    try {
        // get annotation
        Log controllerLog = getAnnotationLog(joinPoint);
        if (controllerLog == null) {
            return;
        }
        // get current user from servlet
        LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
        OperateLog operateLog = new OperateLog();
        operateLog.setStatus(Constants.SUCCESS);
        // get the IP of this request
        operateLog.setIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
        // get result with JSON format
        operateLog.setJsonResult(JSON.toJSONString(jsonResult));
        operateLog.setCost(cost);
        operateLog.setUrl(ServletUtils.getRequest().getRequestURI());
        if (loginUser != null) {
            operateLog.setOperateName(loginUser.getUsername());
        }
        if (e != null) {
            operateLog.setStatus(Constants.FAILED);
            operateLog.setErrorMsg(StringUtils.substring(e.getMessage(), 0, 2000));
        }
        // get the class name
        String className = joinPoint.getTarget().getClass().getName();
        // get method name
        String methodName = joinPoint.getSignature().getName();
        operateLog.setMethod(StringUtils.format("{}.{}()", className, methodName));
        // get request method
        operateLog.setRequestMethod(ServletUtils.getRequest().getMethod());
        // set method args
        getControllerMethodDescription(joinPoint, controllerLog, operateLog);
        // save log
        AsyncManager.me().execute(AsyncFactory.recordOperateLog(operateLog));
    } catch (Exception exception) {
        log.error("get exception in handleLog,{} ", exception.getMessage(), exception);
    }
}
Also used : OperateLog(com.dimple.project.log.domain.OperateLog) Log(com.dimple.framework.aspectj.lang.annotation.Log) LoginUser(com.dimple.framework.security.LoginUser) TokenService(com.dimple.framework.security.service.TokenService) OperateLog(com.dimple.project.log.domain.OperateLog)

Example 3 with Log

use of com.dimple.framework.aspectj.lang.annotation.Log in project DimpleBlog by martin-chips.

the class CarouselController method changeDisplay.

@PreAuthorize("@permissionService.hasPermission('system:carousel:edit')")
@Log(title = "轮播图管理", businessType = BusinessType.UPDATE)
@PutMapping("/{id}/display/{display}")
public AjaxResult changeDisplay(@PathVariable Long id, @PathVariable Boolean display) {
    Carousel carousel = new Carousel();
    carousel.setDisplay(display);
    carousel.setId(id);
    return toAjax(carouselService.updateCarousel(carousel));
}
Also used : Carousel(com.dimple.project.system.domain.Carousel) Log(com.dimple.framework.aspectj.lang.annotation.Log) PutMapping(org.springframework.web.bind.annotation.PutMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 4 with Log

use of com.dimple.framework.aspectj.lang.annotation.Log in project DimpleBlog by martin-chips.

the class CarouselController method changeTarget.

@PreAuthorize("@permissionService.hasPermission('system:carousel:edit')")
@Log(title = "轮播图管理", businessType = BusinessType.UPDATE)
@PutMapping("/{id}/target/{target}")
public AjaxResult changeTarget(@PathVariable Long id, @PathVariable Boolean target) {
    Carousel carousel = new Carousel();
    carousel.setTarget(target);
    carousel.setId(id);
    return toAjax(carouselService.updateCarousel(carousel));
}
Also used : Carousel(com.dimple.project.system.domain.Carousel) Log(com.dimple.framework.aspectj.lang.annotation.Log) PutMapping(org.springframework.web.bind.annotation.PutMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 5 with Log

use of com.dimple.framework.aspectj.lang.annotation.Log in project DimpleBlog by martin-chips.

the class ProfileController method updatePwd.

/**
 * 重置密码
 */
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
@PutMapping("/updatePwd")
public AjaxResult updatePwd(String oldPassword, String newPassword) {
    LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
    String userName = loginUser.getUsername();
    String password = loginUser.getPassword();
    if (!SecurityUtils.matchesPassword(oldPassword, password)) {
        return AjaxResult.error("修改密码失败,旧密码错误");
    }
    if (SecurityUtils.matchesPassword(newPassword, password)) {
        return AjaxResult.error("新密码不能与旧密码相同");
    }
    return toAjax(userService.resetUserPwd(userName, SecurityUtils.encryptPassword(newPassword)));
}
Also used : LoginUser(com.dimple.framework.security.LoginUser) Log(com.dimple.framework.aspectj.lang.annotation.Log) PutMapping(org.springframework.web.bind.annotation.PutMapping)

Aggregations

Log (com.dimple.framework.aspectj.lang.annotation.Log)8 PutMapping (org.springframework.web.bind.annotation.PutMapping)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 Config (com.dimple.project.system.domain.Config)3 LoginUser (com.dimple.framework.security.LoginUser)2 Carousel (com.dimple.project.system.domain.Carousel)2 TokenService (com.dimple.framework.security.service.TokenService)1 Comment (com.dimple.project.blog.domain.Comment)1 OperateLog (com.dimple.project.log.domain.OperateLog)1