use of com.yuzhyn.hidoc.app.application.entity.sys.SysUser in project Hidoc by yuzhengyang.
the class UserController method changePassword.
@PostMapping("changePassword")
public ResponseData changePassword(@RequestBody Map<String, Object> params) {
if (MapTool.ok(params, "password", "password2")) {
String password = MapTool.get(params, "password", "").toString();
String password2 = MapTool.get(params, "password2", "").toString();
if (!StringTool.ok(password, password2))
return ResponseData.error("修改失败,请输入密码");
if (!password.equals(password2))
return ResponseData.error("修改失败,两次密码不一致");
SysUser user = sysUserMapper.selectById(CurrentUserManager.getUser().getId());
user.setPassword(MixdeTool.md5Mix(user.getName(), password));
int flag = sysUserMapper.updateById(user);
if (flag > 0) {
return ResponseData.ok("修改成功");
}
}
return ResponseData.error("修改失败,请完善信息");
}
use of com.yuzhyn.hidoc.app.application.entity.sys.SysUser in project Hidoc by yuzhengyang.
the class UserController method register.
@PostMapping("register")
public ResponseData register(@RequestBody Map<String, Object> params) {
if (MapTool.ok(params, "username", "email", "password", "realname", "authCode", "uid")) {
String avatar = MapTool.get(params, "avatar", "").toString();
String name = MapTool.get(params, "username", "").toString();
String email = MapTool.get(params, "email", "").toString();
String password = MapTool.get(params, "password", "").toString();
String realname = MapTool.getString(params, "realname", "");
String authCode = MapTool.getString(params, "authCode", "");
String uid = MapTool.getString(params, "uid", "");
if (name.length() < R.MinPasswordLength || !RegexPattern.GENERAL.isMatch(name)) {
return ResponseData.error("账号不符合规则,仅支持6位及以上字母数字下划线组合");
}
if (password.length() < R.MinPasswordLength || !RegexPattern.GENERAL.isMatch(password)) {
return ResponseData.error("密码不符合规则,仅支持6位及以上字母数字下划线组合");
}
if (!StringTool.ok(uid)) {
return ResponseData.error("请获取验证码,验证邮箱可用");
}
if (!StringTool.ok(authCode)) {
return ResponseData.error("请输入验证码");
}
Tuple2<Boolean, String> checkFlag = authCodeService.checkCode(email, uid, authCode);
if (!checkFlag.getT1()) {
return ResponseData.error(checkFlag.getT2());
}
SysUser user = new SysUser();
user.setId(R.SnowFlake.nexts());
user.setName(name);
user.setRealName(realname);
user.setAvatar(avatar);
user.setEmail(email);
user.setPassword(MixdeTool.md5Mix(user.getName(), password));
user.setCreateTime(LocalDateTime.now());
user.setIsFrozen(false);
int flag = sysUserMapper.insert(user);
if (flag > 0) {
SysUserFileConf conf = new SysUserFileConf();
conf.setUserId(user.getId());
conf.setCreateTime(LocalDateTime.now());
conf.setExpiryTime(LocalDateTimeTool.max());
conf.setSpaceLimit(1024 * 1024 * 1024L);
conf.setUrlPrefix(name);
conf.setUsedSpace(0L);
sysUserFileConfMapper.insert(conf);
FileBucket fileBucket = new FileBucket();
fileBucket.setId(R.SnowFlake.nexts());
fileBucket.setIsOpen(true);
fileBucket.setName(".hidoc");
fileBucket.setUserId(user.getId());
fileBucketMapper.insert(fileBucket);
return ResponseData.okData("sysUser", user);
}
}
return ResponseData.error("注册失败,请完善信息");
}
use of com.yuzhyn.hidoc.app.application.entity.sys.SysUser in project Hidoc by yuzhengyang.
the class JavaDocCreateService method uploadZip.
@Transactional
public ResponseData uploadZip(String projectName, List<String> fileList, List<String> step) {
step.add("获取修改用户信息");
SysUser curUser = CurrentUserManager.getUser();
if (curUser == null) {
curUser = CurrentUserManager.getOpenUser();
}
boolean isCreateProject = false;
step.add("查询项目,如果没有则新建项目,如果有则更新版本、时间等信息");
JavaDocProject javaDocProject = javaDocProjectMapper.selectOne(new LambdaQueryWrapper<JavaDocProject>().eq(JavaDocProject::getName, projectName));
if (javaDocProject == null) {
isCreateProject = true;
javaDocProject = new JavaDocProject();
javaDocProject.setId("[id:" + projectName + "]");
javaDocProject.setId(javaDocProject.getId().replace(" ", ""));
javaDocProject.setName(projectName);
javaDocProject.setToken(UUIDTool.get());
javaDocProject.setDescription(projectName);
javaDocProject.setCreateUserId(curUser.getId());
javaDocProject.setCreateTime(LocalDateTime.now());
}
javaDocProject.setUpdateUserId(curUser.getId());
javaDocProject.setUpdateTime(LocalDateTime.now());
step.add("准备解析后的数据列表");
List<JavaDocClass> javaDocClassList = new ArrayList<>();
List<JavaDocMethod> javaDocMethodList = new ArrayList<>();
List<JavaDocMenu> javaDocMenuList = new ArrayList<>();
step.add("准备数据开始分解存储");
step.add("解析项目、类、方法");
for (String fileItem : fileList) {
try {
// parse() 参数可以是 String, File, InputStream等
parseJavaDoc(fileItem, javaDocProject, javaDocClassList, javaDocMethodList);
} catch (IOException ex) {
step.add("解析项目、类、方法异常");
}
}
try {
parseJavaDocMenu(javaDocProject, javaDocClassList, javaDocMenuList);
step.add("解析菜单成功");
} catch (Exception ex) {
step.add("解析菜单异常");
}
step.add("最终汇总数据,如果有异常,则直接退出,不做任何数据落库");
if (javaDocProject != null && javaDocClassList != null && javaDocMethodList != null) {
step.add("清理数据库数据");
cleanJavaDocData(projectName);
step.add("更新或保存项目信息");
if (isCreateProject) {
javaDocProjectMapper.insert(javaDocProject);
} else {
javaDocProjectMapper.updateById(javaDocProject);
}
step.add("保存类信息");
if (ListTool.ok(javaDocClassList)) {
for (JavaDocClass item : javaDocClassList) {
javaDocClassMapper.insert(item);
}
}
step.add("保存方法信息");
if (ListTool.ok(javaDocMethodList)) {
for (JavaDocMethod item : javaDocMethodList) {
javaDocMethodMapper.insert(item);
}
}
step.add("保存菜单信息");
if (ListTool.ok(javaDocMenuList)) {
for (JavaDocMenu item : javaDocMenuList) {
javaDocMenuMapper.insert(item);
}
}
return ResponseData.ok("JavaDoc创建完成");
}
return ResponseData.error("没有发现要创建的内容");
}
use of com.yuzhyn.hidoc.app.application.entity.sys.SysUser in project Hidoc by yuzhengyang.
the class SecurityInterceptor method preHandle.
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object arg2) throws Exception {
// 检测LocalThread是否泄露
try {
boolean isLogin = CurrentUserManager.isLogin();
if (isLogin) {
SysUser user = CurrentUserManager.getUser();
CurrentUserManager.clearCurrentUser();
log.warn("LocalThread 泄露:" + user.getId() + ", " + user.getName() + "(强制清除泄露的内容)");
}
} catch (Exception ex) {
log.error("LocalThread 泄露检查异常");
}
// 登录信息设置和使用处理
boolean isLogin = false;
String uri = request.getRequestURI();
// 获取所有header信息
log.info("解析并确认当前用户身份");
Enumeration<String> headerNames = request.getHeaderNames();
while (headerNames.hasMoreElements()) {
String name = headerNames.nextElement();
String value = request.getHeader(name);
// log.info("header: " + name + " = " + value);
if (name.equals("access-token")) {
UserInfo userInfo = R.Cache.UserInfo.get(value);
if (userInfo != null) {
// 判断登录身份有效期
if (LocalDateTime.now().isBefore(userInfo.getExpiryTime())) {
isLogin = true;
CurrentUserManager.set(userInfo);
// 给用户续期有效期
userInfo.setExpiryTime(LocalDateTime.now().plusHours(8));
R.Cache.UserInfo.replace(value, userInfo);
} else {
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json; charset=utf-8");
ResponseData rs = new ResponseData(50014, "登录身份过期,请重新登录!");
response.setContentLength(rs.toJSONString().getBytes().length);
response.getOutputStream().write(rs.toJSONString().getBytes());
return false;
}
}
}
}
if (isLogin) {
log.info("已核对身份,用户信息已载入缓存");
return true;
} else {
// 过滤掉不需要权限验证的请求(OPTIONS)
String method = CurrentUserManager.getRequestMethod();
if (method != null && method.equals("OPTIONS")) {
log.info("特殊请求方法,已过滤");
return true;
}
if (UrlAccess.isAnonymous(uri)) {
log.info("未登录用户,访问开放内容,已准许");
return true;
}
log.info("未登录用户,访问受限内容,已拒绝");
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json; charset=utf-8");
ResponseData rs = new ResponseData(50008, "拒绝访问受限内容,请登录访问!");
response.setContentLength(rs.toJSONString().getBytes().length);
response.getOutputStream().write(rs.toJSONString().getBytes());
return false;
}
}
use of com.yuzhyn.hidoc.app.application.entity.sys.SysUser in project Hidoc by yuzhengyang.
the class CurrentUserManager method createOpenUser.
/**
* 开放接口时,自动预制开放用户,没有用户信息,获取一个通用开放的用户信息
*
* @return
*/
public static void createOpenUser() {
SysUser user = new SysUser();
user.setId("open-user");
user.setName("OpenUser");
user.setRealName("开放用户");
openUser.set(user);
}
Aggregations