use of com.topcom.cms.domain.User in project topcom-cloud by 545314690.
the class LoginLogService method doAfter.
@AfterReturning("loginMethod()")
public void doAfter(JoinPoint pjp) throws Exception {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
String contextPath = request.getContextPath();
User user = SubjectUtil.getCurrentUser(request);
LoginLog loginLog = new LoginLog();
loginLog.setUserId(user.getId());
loginLog.setUsername(user.getUsername());
loginLog.setHost(request.getRemoteHost());
if (StringUtils.isNotBlank(contextPath) && contextPath.length() > 0) {
loginLog.setSysName(contextPath.substring(1));
}
loginLogManager.save(loginLog);
}
use of com.topcom.cms.domain.User in project topcom-cloud by 545314690.
the class OperationLogService method doBasicProfiling.
@AfterReturning("anyMethod()")
public void doBasicProfiling(JoinPoint pjp) throws Throwable {
HttpServletRequest request = SubjectUtil.getRequest();
Object[] args = pjp.getArgs();
OperationLog ol = new OperationLog();
Object obj = args[0];
// 拦截的实体类 Object target = pjp.getTarget();
Class<?> entityClazz = (Class<?>) ((ParameterizedType) pjp.getTarget().getClass().getGenericSuperclass()).getActualTypeArguments()[0];
ol.setEntity(entityClazz.getName());
if (obj instanceof Long) {
ol.setOperation(OperationLog.Operation.DELETE);
} else if (obj instanceof BaseEntityModel) {
BaseEntityModel objModel = (BaseEntityModel) obj;
if (objModel.getId() == null || objModel.getId() == 0) {
ol.setOperation(OperationLog.Operation.CREATE);
} else {
ol.setOperation(OperationLog.Operation.MODIFY);
}
ol.setEntity(objModel.getEntityName());
} else {
return;
}
// 拦截的方法名称
String methodName = pjp.getSignature().getName();
/**
* request是null,说明是系统调用save,否则是用户调用
*/
if (request == null) {
ol.setUsername("系统操作");
} else {
User user = SubjectUtil.getCurrentUser();
ol.setHost(request.getRemoteHost());
if (user != null) {
ol.setUserId(user.getId());
ol.setUsername(user.getUsername());
}
}
ol.setMethod(methodName);
/**
* 不使用save方法,更改了操作日志的保存方法,否则会造成无限循环调用
*/
// TODO:写一个注解,在方法名上标注不被拦截的方法
operationLogManager.persist(ol);
}
use of com.topcom.cms.domain.User in project topcom-cloud by 545314690.
the class TokenManagerImpl method main.
public static void main(String[] args) {
TokenManager tokenManager = new TokenManagerImpl();
String token = tokenManager.createToken("102");
User user = new User(102L);
user.setUsername("sdmj");
tokenManager.saveToken(token, user);
System.out.println(token);
String token2 = tokenManager.createToken("1");
System.out.println(token2);
}
use of com.topcom.cms.domain.User in project topcom-cloud by 545314690.
the class SearchWordController method findByType.
/**
* 热词查询 查询排名前 limit 的word
* @return
*/
@RequestMapping(method = RequestMethod.GET, value = "/findByType", produces = "application/json")
@ResponseBody
public List<SearchWord> findByType(@CurrentUser User user, @ApiParam("limit") @RequestParam(required = true) Integer limit, @ApiParam("type") @RequestParam(required = true) Integer type) {
Sort sort = new Sort(new Sort.Order(Sort.Direction.DESC, "wordCount"));
Pageable page = new PageRequest(0, limit, sort);
User user1 = this.userManager.findById(user.getId());
Set<Group> groups = user1.getGroups();
String groupId = SearchWord.groupIdBySet(groups);
List<String> groupIdList = new ArrayList<>();
groupIdList.add(groupId);
if (groupId.indexOf(",") != -1) {
String[] split = groupId.split(",");
for (String s : split) {
groupIdList.add(s);
}
}
Page<SearchWord> searchWords = this.searchWordManager.findByTypeAndGroupIdIn(page, type, groupIdList);
return filterNull(searchWords);
}
use of com.topcom.cms.domain.User in project topcom-cloud by 545314690.
the class UserController method update.
/**
* 重写父类put方法 更改了父类的保存方法
*/
@Override
@RequestMapping(value = { "/{id}" }, method = { RequestMethod.PUT }, produces = { "application/json" }, consumes = { "application/json" })
@ResponseBody
public User update(@PathVariable Long id, @RequestBody User model) {
User user = this.manager.findById(id);
if (!StringUtils.equals(model.getPassword(), user.getPassword())) {
// 如果更改了密码,新密码加密
// model.encodePassword();
PasswordHelper.encryptPassword(model);
} else {
// 保存之前的salt
model.setSalt(user.getSalt());
}
model.setId(Long.valueOf(id.toString()));
model.setDateModified(new Date());
model = this.manager.save(model);
if (!StringUtils.equals(model.getPassword(), user.getPassword())) {
tokenManager.deleteToken(model.getId());
}
return model;
}
Aggregations