mirror of
https://gitee.com/likeadmin/likeadmin_java.git
synced 2026-05-08 08:07:46 +08:00
优化: 移动端接入sa-token权限管理依赖
This commit is contained in:
@@ -34,4 +34,7 @@
|
||||
<tree path="/like-admin/src/main/java/com/mdd/admin/crontab" title="任务层"/>
|
||||
<tree path="/like-common/src/main/java/com/mdd/common/util" title="公共工具"/>
|
||||
<tree path="/like-common/src/main/java/com/mdd/common/aop" title="公共切面"/>
|
||||
<tree path="/like-front/src/main/java/com/mdd/front/cache" title="缓存层"/>
|
||||
<tree path="/like-admin/src/main/java/com/mdd/admin/cache" title="缓存层"/>
|
||||
<tree path="/like-admin/src/main/java/com/mdd/admin/aop" title="切面层"/>
|
||||
</trees>
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.mdd.admin;
|
||||
|
||||
import com.mdd.common.util.ArrayUtils;
|
||||
import com.mdd.common.util.ListUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -60,7 +60,7 @@ public class LikeAdminThreadLocal {
|
||||
if (roleIds.equals("") || roleIds.equals("0")) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return ArrayUtils.stringToListAsInt(roleIds, ",");
|
||||
return ListUtils.stringToListAsInt(roleIds, ",");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
31
server/like-admin/src/main/java/com/mdd/admin/cache/CaptchaCache.java
vendored
Normal file
31
server/like-admin/src/main/java/com/mdd/admin/cache/CaptchaCache.java
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
package com.mdd.admin.cache;
|
||||
|
||||
import com.mdd.common.util.*;
|
||||
|
||||
/**
|
||||
* 验证码缓存器
|
||||
*/
|
||||
public class CaptchaCache {
|
||||
|
||||
public static String get(String uuid) {
|
||||
String ip = IpUtils.getIpAddress().replaceAll("\\.", "");
|
||||
String captchaKey = YmlUtils.get("like.captcha.token") + ip + ":" + uuid;
|
||||
Object code = RedisUtils.get(captchaKey);
|
||||
|
||||
if (StringUtils.isNull(code) || StringUtils.isEmpty(code.toString())) {
|
||||
return "";
|
||||
}
|
||||
|
||||
RedisUtils.del(captchaKey);
|
||||
return code.toString();
|
||||
}
|
||||
|
||||
public static void set(String code, String uuid) {
|
||||
String ip = IpUtils.getIpAddress().replaceAll("\\.", "");
|
||||
String verifyKey = YmlUtils.get("like.captcha.token") + ip + ":" + uuid;
|
||||
long expireTime = Long.parseLong(YmlUtils.get("like.captcha.expire"));
|
||||
|
||||
RedisUtils.set(verifyKey, code.toLowerCase(), expireTime);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -87,7 +87,7 @@ public class AlbumsServiceImpl implements IAlbumsService {
|
||||
vo.setPath(album.getUri());
|
||||
}
|
||||
vo.setUri(UrlUtils.toAbsoluteUrl(album.getUri()));
|
||||
vo.setSize(ToolsUtils.storageUnit(album.getSize()));
|
||||
vo.setSize(ToolUtils.storageUnit(album.getSize()));
|
||||
vo.setCreateTime(TimeUtils.timestampToDate(album.getCreateTime()));
|
||||
vo.setUpdateTime(TimeUtils.timestampToDate(album.getUpdateTime()));
|
||||
list.add(vo);
|
||||
@@ -234,7 +234,7 @@ public class AlbumsServiceImpl implements IAlbumsService {
|
||||
}
|
||||
|
||||
JSONArray jsonArray = JSONArray.parseArray(JSONArray.toJSONString(lists));
|
||||
return ArrayUtils.listToTree(jsonArray, "id", "pid", "children");
|
||||
return ListUtils.listToTree(jsonArray, "id", "pid", "children");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -48,7 +48,7 @@ public class ChannelOaMenusServiceImpl implements IChannelOaMenusService {
|
||||
|
||||
List<Map<String, String>> params = new LinkedList<>();
|
||||
for (Object o : objs) {
|
||||
params.add(ToolsUtils.objectToMap(o));
|
||||
params.add(MapUtils.objectToMap(o));
|
||||
}
|
||||
|
||||
List<WxMenuButton> menuButtons = new LinkedList<>();
|
||||
@@ -79,7 +79,7 @@ public class ChannelOaMenusServiceImpl implements IChannelOaMenusService {
|
||||
// 子级菜单
|
||||
if (Integer.parseInt(item.get("menuType")) == 2) {
|
||||
Assert.notNull(item.get("subButtons"), "子级菜单不能为空");
|
||||
List<Map<String, String>> subButtons = ArrayUtils.stringToListAsMapStr(item.get("subButtons"));
|
||||
List<Map<String, String>> subButtons = ListUtils.stringToListAsMapStr(item.get("subButtons"));
|
||||
|
||||
if (subButtons.size() > 5) {
|
||||
throw new OperateException("子级菜单超出限制(最多5个)");
|
||||
|
||||
@@ -54,7 +54,7 @@ public class DecorateTabbarServiceImpl implements IDecorateTabbarService {
|
||||
String tabbar = ConfigUtils.get("tabbar", "style", "{}");
|
||||
|
||||
DecorateTabbarVo response = new DecorateTabbarVo();
|
||||
response.setStyle(ToolsUtils.jsonToMap(tabbar));
|
||||
response.setStyle(MapUtils.jsonToMap(tabbar));
|
||||
response.setList(tabList);
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public class IndexServiceImpl implements IIndexService {
|
||||
map.put("webFavicon", UrlUtils.toAbsoluteUrl(website.getOrDefault("favicon", "")));
|
||||
map.put("webBackdrop", UrlUtils.toAbsoluteUrl(website.getOrDefault("backdrop", "")));
|
||||
map.put("ossDomain", UrlUtils.domain());
|
||||
map.put("copyright", ArrayUtils.stringToListAsMapStr(copyright));
|
||||
map.put("copyright", ListUtils.stringToListAsMapStr(copyright));
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.alibaba.fastjson2.JSON;
|
||||
import com.mdd.admin.service.ISettingCopyrightService;
|
||||
import com.mdd.admin.validate.setting.SettingCopyrightValidate;
|
||||
import com.mdd.admin.vo.setting.SettingCopyrightVo;
|
||||
import com.mdd.common.util.ArrayUtils;
|
||||
import com.mdd.common.util.ListUtils;
|
||||
import com.mdd.common.util.ConfigUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -25,7 +25,7 @@ public class SettingCopyrightServiceImpl implements ISettingCopyrightService {
|
||||
@Override
|
||||
public List<SettingCopyrightVo> detail() {
|
||||
String config = ConfigUtils.get("website", "copyright", "[]");
|
||||
List<Map<String, String>> copyright = ArrayUtils.stringToListAsMapStr(config);
|
||||
List<Map<String, String>> copyright = ListUtils.stringToListAsMapStr(config);
|
||||
|
||||
List<SettingCopyrightVo> list = new LinkedList<>();
|
||||
for (Map<String, String> map : copyright) {
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.mdd.admin.service.impl;
|
||||
import com.mdd.admin.service.ISettingLoginService;
|
||||
import com.mdd.admin.validate.setting.SettingLoginValidate;
|
||||
import com.mdd.admin.vo.setting.SettingLoginVo;
|
||||
import com.mdd.common.util.ArrayUtils;
|
||||
import com.mdd.common.util.ListUtils;
|
||||
import com.mdd.common.util.ConfigUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -26,11 +26,11 @@ public class SettingLoginServiceImpl implements ISettingLoginService {
|
||||
Map<String, String> config = ConfigUtils.get("login");
|
||||
|
||||
SettingLoginVo vo = new SettingLoginVo();
|
||||
vo.setLoginWay(ArrayUtils.stringToListAsInt(config.getOrDefault("loginWay", ""), ","));
|
||||
vo.setLoginWay(ListUtils.stringToListAsInt(config.getOrDefault("loginWay", ""), ","));
|
||||
vo.setForceBindMobile(Integer.parseInt(config.getOrDefault("forceBindMobile", "0")));
|
||||
vo.setOpenAgreement(Integer.parseInt(config.getOrDefault("openAgreement", "0")));
|
||||
vo.setOpenOtherAuth(Integer.parseInt(config.getOrDefault("openOtherAuth", "0")));
|
||||
vo.setAutoLoginAuth(ArrayUtils.stringToListAsInt(config.getOrDefault("autoLoginAuth", ""), ","));
|
||||
vo.setAutoLoginAuth(ListUtils.stringToListAsInt(config.getOrDefault("autoLoginAuth", ""), ","));
|
||||
return vo;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,9 +7,9 @@ import com.mdd.admin.vo.setting.SettingNoticeDetailVo;
|
||||
import com.mdd.admin.vo.setting.SettingNoticeListedVo;
|
||||
import com.mdd.common.entity.notice.NoticeSetting;
|
||||
import com.mdd.common.mapper.notice.NoticeSettingMapper;
|
||||
import com.mdd.common.util.MapUtils;
|
||||
import com.mdd.common.util.StringUtils;
|
||||
import com.mdd.common.util.TimeUtils;
|
||||
import com.mdd.common.util.ToolsUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -47,10 +47,10 @@ public class SettingNoticeServiceImpl implements ISettingNoticeService {
|
||||
SettingNoticeListedVo vo = new SettingNoticeListedVo();
|
||||
BeanUtils.copyProperties(n, vo);
|
||||
|
||||
Map<String, String> systemMap = ToolsUtils.jsonToMap(n.getSystemNotice());
|
||||
Map<String, String> smsMap = ToolsUtils.jsonToMap(n.getSmsNotice());
|
||||
Map<String, String> oaMap = ToolsUtils.jsonToMap(n.getOaNotice());
|
||||
Map<String, String> mnpMap = ToolsUtils.jsonToMap(n.getMnpNotice());
|
||||
Map<String, String> systemMap = MapUtils.jsonToMap(n.getSystemNotice());
|
||||
Map<String, String> smsMap = MapUtils.jsonToMap(n.getSmsNotice());
|
||||
Map<String, String> oaMap = MapUtils.jsonToMap(n.getOaNotice());
|
||||
Map<String, String> mnpMap = MapUtils.jsonToMap(n.getMnpNotice());
|
||||
|
||||
vo.setType(n.getType()==1?"业务通知":"验证码");
|
||||
vo.setSystemStatus(Integer.parseInt(systemMap.getOrDefault("status", "0")));
|
||||
@@ -86,10 +86,10 @@ public class SettingNoticeServiceImpl implements ISettingNoticeService {
|
||||
.eq("is_delete", 0)
|
||||
.last("limit 1"));
|
||||
|
||||
Map<String, Object> systemMap = ToolsUtils.jsonToMapAsObj(noticeSetting.getSystemNotice());
|
||||
Map<String, Object> oaMap = ToolsUtils.jsonToMapAsObj(noticeSetting.getOaNotice());
|
||||
Map<String, Object> mnpMap = ToolsUtils.jsonToMapAsObj(noticeSetting.getMnpNotice());
|
||||
Map<String, Object> smsMap = ToolsUtils.jsonToMapAsObj(noticeSetting.getSmsNotice());
|
||||
Map<String, Object> systemMap = MapUtils.jsonToMapAsObj(noticeSetting.getSystemNotice());
|
||||
Map<String, Object> oaMap = MapUtils.jsonToMapAsObj(noticeSetting.getOaNotice());
|
||||
Map<String, Object> mnpMap = MapUtils.jsonToMapAsObj(noticeSetting.getMnpNotice());
|
||||
Map<String, Object> smsMap = MapUtils.jsonToMapAsObj(noticeSetting.getSmsNotice());
|
||||
|
||||
smsMap.put("tips", JSON.parseArray(smsMap.get("tips").toString()));
|
||||
|
||||
@@ -117,8 +117,8 @@ public class SettingNoticeServiceImpl implements ISettingNoticeService {
|
||||
.eq("is_delete", 0)
|
||||
.last("limit 1"));
|
||||
|
||||
Map<String, String> systemParam = ToolsUtils.objectToMap(params.get("systemNotice"));
|
||||
Map<String, String> systemMap = ToolsUtils.jsonToMap(noticeSetting.getSystemNotice());
|
||||
Map<String, String> systemParam = MapUtils.objectToMap(params.get("systemNotice"));
|
||||
Map<String, String> systemMap = MapUtils.jsonToMap(noticeSetting.getSystemNotice());
|
||||
if (StringUtils.isNotEmpty(systemMap)) {
|
||||
systemMap.put("title", systemParam.getOrDefault("title", ""));
|
||||
systemMap.put("content", systemParam.getOrDefault("content", ""));
|
||||
@@ -126,8 +126,8 @@ public class SettingNoticeServiceImpl implements ISettingNoticeService {
|
||||
systemMap.put("status", systemParam.getOrDefault("status", "0"));
|
||||
}
|
||||
|
||||
Map<String, String> smsParam = ToolsUtils.objectToMap(params.get("smsNotice"));
|
||||
Map<String, String> smsMap = ToolsUtils.jsonToMap(noticeSetting.getSmsNotice());
|
||||
Map<String, String> smsParam = MapUtils.objectToMap(params.get("smsNotice"));
|
||||
Map<String, String> smsMap = MapUtils.jsonToMap(noticeSetting.getSmsNotice());
|
||||
if (StringUtils.isNotEmpty(smsMap)) {
|
||||
smsMap.put("templateId", smsParam.getOrDefault("templateId", ""));
|
||||
smsMap.put("content", smsParam.getOrDefault("content", ""));
|
||||
@@ -135,8 +135,8 @@ public class SettingNoticeServiceImpl implements ISettingNoticeService {
|
||||
smsMap.put("status", smsParam.getOrDefault("status", "0"));
|
||||
}
|
||||
|
||||
Map<String, String> oaParam = ToolsUtils.objectToMap(params.get("oaNotice"));
|
||||
Map<String, String> oaMap = ToolsUtils.jsonToMap(noticeSetting.getOaNotice());
|
||||
Map<String, String> oaParam = MapUtils.objectToMap(params.get("oaNotice"));
|
||||
Map<String, String> oaMap = MapUtils.jsonToMap(noticeSetting.getOaNotice());
|
||||
if (StringUtils.isNotEmpty(oaMap)) {
|
||||
oaMap.put("name", oaParam.getOrDefault("name", ""));
|
||||
oaMap.put("first", oaParam.getOrDefault("first", ""));
|
||||
@@ -148,8 +148,8 @@ public class SettingNoticeServiceImpl implements ISettingNoticeService {
|
||||
oaMap.put("status", oaParam.getOrDefault("status", "0"));
|
||||
}
|
||||
|
||||
Map<String, String> mnpParam = ToolsUtils.objectToMap(params.get("mnpNotice"));
|
||||
Map<String, String> mnpMap = ToolsUtils.jsonToMap(noticeSetting.getMnpNotice());
|
||||
Map<String, String> mnpParam = MapUtils.objectToMap(params.get("mnpNotice"));
|
||||
Map<String, String> mnpMap = MapUtils.jsonToMap(noticeSetting.getMnpNotice());
|
||||
if (StringUtils.isNotEmpty(mnpParam)) {
|
||||
mnpMap.put("templateId", mnpParam.get("templateId"));
|
||||
mnpMap.put("templateSn", mnpParam.get("templateSn"));
|
||||
|
||||
@@ -6,7 +6,7 @@ import com.mdd.admin.validate.setting.SettingProtocolValidate;
|
||||
import com.mdd.admin.vo.setting.SettingProtocolDetailVo;
|
||||
import com.mdd.admin.vo.setting.SettingProtocolObjectVo;
|
||||
import com.mdd.common.util.ConfigUtils;
|
||||
import com.mdd.common.util.ToolsUtils;
|
||||
import com.mdd.common.util.MapUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -27,8 +27,8 @@ public class SettingProtocolServiceImpl implements ISettingProtocolService {
|
||||
public SettingProtocolDetailVo detail() {
|
||||
String service = ConfigUtils.get("protocol", "service", "{\"name\":\"\",\"content\":\"\"}");
|
||||
String privacy = ConfigUtils.get("protocol", "privacy", "{\"name\":\"\",\"content\":\"\"}");
|
||||
Map<String, String> serviceMap = ToolsUtils.jsonToMap(service);
|
||||
Map<String, String> privacyMap = ToolsUtils.jsonToMap(privacy);
|
||||
Map<String, String> serviceMap = MapUtils.jsonToMap(service);
|
||||
Map<String, String> privacyMap = MapUtils.jsonToMap(privacy);
|
||||
|
||||
SettingProtocolObjectVo serviceObj = new SettingProtocolObjectVo();
|
||||
serviceObj.setName(serviceMap.getOrDefault("name", ""));
|
||||
|
||||
@@ -92,7 +92,7 @@ public class SystemAuthAdminServiceImpl implements ISystemAuthAdminService {
|
||||
vo.setRole("系统管理员");
|
||||
} else {
|
||||
List<String> role = new LinkedList<>();
|
||||
List<Integer> roleIds = ArrayUtils.stringToListAsInt(vo.getRole(), ",");
|
||||
List<Integer> roleIds = ListUtils.stringToListAsInt(vo.getRole(), ",");
|
||||
if (!roleIds.isEmpty()) {
|
||||
List<SystemAuthRole> roleList = systemAuthRoleMapper.selectList(new QueryWrapper<SystemAuthRole>()
|
||||
.select("id,name")
|
||||
@@ -101,14 +101,14 @@ public class SystemAuthAdminServiceImpl implements ISystemAuthAdminService {
|
||||
role.add(d.getName());
|
||||
}
|
||||
}
|
||||
vo.setRole(ArrayUtils.listToStringByStr(role, "/"));
|
||||
vo.setRole(ListUtils.listToStringByStr(role, "/"));
|
||||
}
|
||||
|
||||
if (StringUtils.isNull(vo.getDept()) || vo.getDept().equals("")) {
|
||||
vo.setDept("");
|
||||
} else {
|
||||
List<String> dept = new LinkedList<>();
|
||||
List<Integer> deptIds = ArrayUtils.stringToListAsInt(vo.getDept(), ",");
|
||||
List<Integer> deptIds = ListUtils.stringToListAsInt(vo.getDept(), ",");
|
||||
if (!deptIds.isEmpty()) {
|
||||
List<SystemAuthDept> deptList = systemAuthDeptMapper.selectList(new QueryWrapper<SystemAuthDept>()
|
||||
.select("id,name")
|
||||
@@ -118,7 +118,7 @@ public class SystemAuthAdminServiceImpl implements ISystemAuthAdminService {
|
||||
dept.add(d.getName());
|
||||
}
|
||||
}
|
||||
vo.setDept(ArrayUtils.listToStringByStr(dept, "/"));
|
||||
vo.setDept(ListUtils.listToStringByStr(dept, "/"));
|
||||
}
|
||||
|
||||
vo.setAvatar(UrlUtils.toAbsoluteUrl(vo.getAvatar()));
|
||||
@@ -160,7 +160,7 @@ public class SystemAuthAdminServiceImpl implements ISystemAuthAdminService {
|
||||
// 角色权限
|
||||
List<String> auths = new LinkedList<>();
|
||||
if (adminId > 1) {
|
||||
List<Integer> roleIds = ArrayUtils.stringToListAsInt(sysAdmin.getRoleIds(), ",");
|
||||
List<Integer> roleIds = ListUtils.stringToListAsInt(sysAdmin.getRoleIds(), ",");
|
||||
List<Integer> menuIds = iSystemAuthPermService.selectMenuIdsByRoleId(roleIds);
|
||||
if (menuIds.size() > 0) {
|
||||
List<SystemAuthMenu> systemAuthMenus = systemAuthMenuMapper.selectList(new QueryWrapper<SystemAuthMenu>()
|
||||
@@ -215,9 +215,9 @@ public class SystemAuthAdminServiceImpl implements ISystemAuthAdminService {
|
||||
|
||||
SystemAuthAdminDetailVo vo = new SystemAuthAdminDetailVo();
|
||||
BeanUtils.copyProperties(sysAdmin, vo);
|
||||
vo.setRoleIds(ArrayUtils.stringToListAsInt(sysAdmin.getRoleIds(), ","));
|
||||
vo.setDeptIds(ArrayUtils.stringToListAsInt(sysAdmin.getDeptIds(), ","));
|
||||
vo.setPostIds(ArrayUtils.stringToListAsInt(sysAdmin.getPostIds(), ","));
|
||||
vo.setRoleIds(ListUtils.stringToListAsInt(sysAdmin.getRoleIds(), ","));
|
||||
vo.setDeptIds(ListUtils.stringToListAsInt(sysAdmin.getDeptIds(), ","));
|
||||
vo.setPostIds(ListUtils.stringToListAsInt(sysAdmin.getPostIds(), ","));
|
||||
vo.setAvatar(UrlUtils.toAbsoluteUrl(sysAdmin.getAvatar()));
|
||||
vo.setCreateTime(TimeUtils.timestampToDate(sysAdmin.getCreateTime()));
|
||||
vo.setUpdateTime(TimeUtils.timestampToDate(sysAdmin.getUpdateTime()));
|
||||
@@ -246,17 +246,17 @@ public class SystemAuthAdminServiceImpl implements ISystemAuthAdminService {
|
||||
.eq("nickname", createValidate.getNickname())
|
||||
.last("limit 1")), "昵称已存在换一个吧!");
|
||||
|
||||
String salt = ToolsUtils.randomString(5);
|
||||
String pwd = ToolsUtils.makeMd5(createValidate.getPassword().trim() + salt);
|
||||
String salt = ToolUtils.randomString(5);
|
||||
String pwd = ToolUtils.makeMd5(createValidate.getPassword().trim() + salt);
|
||||
|
||||
String createAvatar = createValidate.getAvatar();
|
||||
String defaultAvatar = "/api/static/backend_avatar.png";
|
||||
String avatar = StringUtils.isNotEmpty(createValidate.getAvatar()) ? UrlUtils.toRelativeUrl(createAvatar) : defaultAvatar;
|
||||
|
||||
SystemAuthAdmin model = new SystemAuthAdmin();
|
||||
model.setRoleIds(ArrayUtils.listToStringByInt(createValidate.getRoleIds(), ","));
|
||||
model.setDeptIds(ArrayUtils.listToStringByInt(createValidate.getDeptIds(), ","));
|
||||
model.setPostIds(ArrayUtils.listToStringByInt(createValidate.getPostIds(), ","));
|
||||
model.setRoleIds(ListUtils.listToStringByInt(createValidate.getRoleIds(), ","));
|
||||
model.setDeptIds(ListUtils.listToStringByInt(createValidate.getDeptIds(), ","));
|
||||
model.setPostIds(ListUtils.listToStringByInt(createValidate.getPostIds(), ","));
|
||||
model.setUsername(createValidate.getUsername());
|
||||
model.setNickname(createValidate.getNickname());
|
||||
model.setAvatar(avatar);
|
||||
@@ -306,9 +306,9 @@ public class SystemAuthAdminServiceImpl implements ISystemAuthAdminService {
|
||||
|
||||
SystemAuthAdmin model = new SystemAuthAdmin();
|
||||
model.setId(updateValidate.getId());
|
||||
model.setRoleIds(ArrayUtils.listToStringByInt(updateValidate.getRoleIds(), ","));
|
||||
model.setDeptIds(ArrayUtils.listToStringByInt(updateValidate.getDeptIds(), ","));
|
||||
model.setPostIds(ArrayUtils.listToStringByInt(updateValidate.getPostIds(), ","));
|
||||
model.setRoleIds(ListUtils.listToStringByInt(updateValidate.getRoleIds(), ","));
|
||||
model.setDeptIds(ListUtils.listToStringByInt(updateValidate.getDeptIds(), ","));
|
||||
model.setPostIds(ListUtils.listToStringByInt(updateValidate.getPostIds(), ","));
|
||||
model.setNickname(updateValidate.getNickname());
|
||||
model.setAvatar(UrlUtils.toRelativeUrl(updateValidate.getAvatar()));
|
||||
model.setSort(updateValidate.getSort());
|
||||
@@ -321,8 +321,8 @@ public class SystemAuthAdminServiceImpl implements ISystemAuthAdminService {
|
||||
}
|
||||
|
||||
if (StringUtils.isNotNull(updateValidate.getPassword()) && StringUtils.isNotEmpty(updateValidate.getPassword())) {
|
||||
String salt = ToolsUtils.randomString(5);
|
||||
String pwd = ToolsUtils.makeMd5( updateValidate.getPassword().trim() + salt);
|
||||
String salt = ToolUtils.randomString(5);
|
||||
String pwd = ToolUtils.makeMd5( updateValidate.getPassword().trim() + salt);
|
||||
model.setPassword(pwd);
|
||||
model.setSalt(salt);
|
||||
}
|
||||
@@ -358,10 +358,10 @@ public class SystemAuthAdminServiceImpl implements ISystemAuthAdminService {
|
||||
model.setUpdateTime(System.currentTimeMillis() / 1000);
|
||||
|
||||
if (StringUtils.isNotNull(upInfoValidate.getPassword()) && StringUtils.isNotEmpty(upInfoValidate.getPassword())) {
|
||||
String currPassword = ToolsUtils.makeMd5(upInfoValidate.getCurrPassword() + model.getSalt());
|
||||
String currPassword = ToolUtils.makeMd5(upInfoValidate.getCurrPassword() + model.getSalt());
|
||||
Assert.isFalse(!currPassword.equals(model.getPassword()), "当前密码不正确!");
|
||||
String salt = ToolsUtils.randomString(5);
|
||||
String pwd = ToolsUtils.makeMd5( upInfoValidate.getPassword().trim() + salt);
|
||||
String salt = ToolUtils.randomString(5);
|
||||
String pwd = ToolUtils.makeMd5( upInfoValidate.getPassword().trim() + salt);
|
||||
model.setPassword(pwd);
|
||||
model.setSalt(salt);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import com.mdd.common.entity.system.SystemAuthAdmin;
|
||||
import com.mdd.common.entity.system.SystemAuthDept;
|
||||
import com.mdd.common.mapper.system.SystemAuthAdminMapper;
|
||||
import com.mdd.common.mapper.system.SystemAuthDeptMapper;
|
||||
import com.mdd.common.util.ArrayUtils;
|
||||
import com.mdd.common.util.ListUtils;
|
||||
import com.mdd.common.util.TimeUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -92,7 +92,7 @@ class SystemAuthDeptServiceImpl implements ISystemAuthDeptService {
|
||||
}
|
||||
|
||||
JSONArray jsonArray = JSONArray.parseArray(JSONArray.toJSONString(list));
|
||||
return ArrayUtils.listToTree(jsonArray, "id", "pid", "children");
|
||||
return ListUtils.listToTree(jsonArray, "id", "pid", "children");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,7 +11,7 @@ import com.mdd.admin.validate.system.SystemMenuUpdateValidate;
|
||||
import com.mdd.admin.vo.system.SystemAuthMenuVo;
|
||||
import com.mdd.common.entity.system.SystemAuthMenu;
|
||||
import com.mdd.common.mapper.system.SystemAuthMenuMapper;
|
||||
import com.mdd.common.util.ArrayUtils;
|
||||
import com.mdd.common.util.ListUtils;
|
||||
import com.mdd.common.util.TimeUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -70,7 +70,7 @@ public class SystemAuthMenuServiceImpl implements ISystemAuthMenuService {
|
||||
}
|
||||
|
||||
JSONArray jsonArray = JSONArray.parseArray(JSONArray.toJSONString(lists));
|
||||
return ArrayUtils.listToTree(jsonArray, "id", "pid", "children");
|
||||
return ListUtils.listToTree(jsonArray, "id", "pid", "children");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,7 +98,7 @@ public class SystemAuthMenuServiceImpl implements ISystemAuthMenuService {
|
||||
}
|
||||
|
||||
JSONArray jsonArray = JSONArray.parseArray(JSONArray.toJSONString(lists));
|
||||
return ArrayUtils.listToTree(jsonArray, "id", "pid", "children");
|
||||
return ListUtils.listToTree(jsonArray, "id", "pid", "children");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.mdd.admin.service.impl;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.mdd.admin.service.ISystemAuthAdminService;
|
||||
import com.mdd.admin.cache.CaptchaCache;
|
||||
import com.mdd.admin.service.ISystemLoginService;
|
||||
import com.mdd.admin.validate.system.SystemAdminLoginsValidate;
|
||||
import com.mdd.admin.vo.system.SystemCaptchaVo;
|
||||
@@ -45,10 +45,6 @@ public class SystemLoginServiceImpl implements ISystemLoginService {
|
||||
@Resource
|
||||
SystemAuthAdminMapper systemAuthAdminMapper;
|
||||
|
||||
@Resource
|
||||
ISystemAuthAdminService iSystemAuthAdminService;
|
||||
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(SystemLoginServiceImpl.class);
|
||||
|
||||
/**
|
||||
@@ -62,15 +58,11 @@ public class SystemLoginServiceImpl implements ISystemLoginService {
|
||||
// 验证码信息
|
||||
String capStr, code;
|
||||
BufferedImage image;
|
||||
String uuid = ToolsUtils.makeUUID();
|
||||
String ip = IpUtils.getIpAddress().replaceAll("\\.", "");
|
||||
String verifyKey = YmlUtils.get("like.captcha.token") + ip + ":" + uuid;
|
||||
long expireTime = Long.parseLong(YmlUtils.get("like.captcha.expire"));
|
||||
String uuid = ToolUtils.makeUUID();
|
||||
|
||||
// 生成验证码
|
||||
capStr = code = captchaProducer.createText();
|
||||
image = captchaProducer.createImage(capStr);
|
||||
RedisUtils.set(verifyKey, code.toLowerCase(), expireTime);
|
||||
FastByteArrayOutputStream os = new FastByteArrayOutputStream();
|
||||
try {
|
||||
ImageIO.write(image, "jpg", os);
|
||||
@@ -79,6 +71,9 @@ public class SystemLoginServiceImpl implements ISystemLoginService {
|
||||
throw new OperateException(e.getMessage());
|
||||
}
|
||||
|
||||
// 缓存验证码
|
||||
CaptchaCache.set(code, uuid);
|
||||
|
||||
// 返回验证码
|
||||
String base64 = "data:image/jpeg;base64,"+ Base64Util.encode(os.toByteArray());
|
||||
SystemCaptchaVo vo = new SystemCaptchaVo();
|
||||
@@ -103,11 +98,9 @@ public class SystemLoginServiceImpl implements ISystemLoginService {
|
||||
if (StringUtils.isNotNull(captchaStatus) && captchaStatus.equals("true")) {
|
||||
Assert.notNull(loginsValidate.getCode(), "code参数缺失");
|
||||
Assert.notNull(loginsValidate.getUuid(), "uuid参数缺失");
|
||||
String ip = IpUtils.getIpAddress().replaceAll("\\.", "");
|
||||
String captchaKey = YmlUtils.get("like.captcha.token") + ip + ":" + loginsValidate.getUuid();
|
||||
Object code = RedisUtils.get(captchaKey);
|
||||
RedisUtils.del(captchaKey);
|
||||
if (StringUtils.isNull(code) || StringUtils.isEmpty(code.toString()) || !loginsValidate.getCode().equals(code.toString())) {
|
||||
|
||||
String code = CaptchaCache.get(loginsValidate.getUuid());
|
||||
if (!loginsValidate.getCode().equals(code)) {
|
||||
throw new LoginException(HttpEnum.CAPTCHA_ERROR.getCode(), HttpEnum.CAPTCHA_ERROR.getMsg());
|
||||
}
|
||||
}
|
||||
@@ -127,7 +120,7 @@ public class SystemLoginServiceImpl implements ISystemLoginService {
|
||||
}
|
||||
|
||||
String newPWd = password + sysAdmin.getSalt();
|
||||
String md5Pwd = ToolsUtils.makeMd5(newPWd);
|
||||
String md5Pwd = ToolUtils.makeMd5(newPWd);
|
||||
if (!md5Pwd.equals(sysAdmin.getPassword())) {
|
||||
this.recordLoginLog(sysAdmin.getId(), loginsValidate.getUsername(), HttpEnum.LOGIN_ACCOUNT_ERROR.getMsg());
|
||||
throw new LoginException(HttpEnum.LOGIN_ACCOUNT_ERROR.getCode(), HttpEnum.LOGIN_ACCOUNT_ERROR.getMsg());
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.mdd.common.plugin.notice.engine;
|
||||
|
||||
import com.mdd.common.config.GlobalConfig;
|
||||
import com.mdd.common.entity.notice.NoticeRecord;
|
||||
import com.mdd.common.enums.NoticeEnum;
|
||||
import com.mdd.common.exception.OperateException;
|
||||
@@ -9,7 +8,6 @@ import com.mdd.common.plugin.notice.vo.NoticeSmsVo;
|
||||
import com.mdd.common.plugin.notice.template.SmsTemplate;
|
||||
import com.mdd.common.plugin.sms.SmsDriver;
|
||||
import com.mdd.common.util.ConfigUtils;
|
||||
import com.mdd.common.util.RedisUtils;
|
||||
import com.mdd.common.util.SpringUtils;
|
||||
import com.mdd.common.util.StringUtils;
|
||||
|
||||
@@ -80,12 +78,6 @@ public class SmsNoticeHandle {
|
||||
noticeRecord.setUpdateTime(System.currentTimeMillis() / 1000);
|
||||
noticeRecordMapper.updateById(noticeRecord);
|
||||
}
|
||||
|
||||
// 通知类型: [1=业务, 2=验证码]
|
||||
if (smsTemplate.getType().equals(2) && StringUtils.isNotNull(params.get("code"))) {
|
||||
String code = params.get("code").toLowerCase();
|
||||
RedisUtils.set(GlobalConfig.redisSmsCode+scene+":"+mobile, code, 900);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.mdd.common.plugin.notice.template;
|
||||
|
||||
import com.mdd.common.util.ToolsUtils;
|
||||
import com.mdd.common.util.MapUtils;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -27,7 +27,7 @@ public class SmsTemplate {
|
||||
* 设置参数
|
||||
*/
|
||||
public void setParams(String smsNotice) {
|
||||
Map<String, String> config = ToolsUtils.jsonToMap(smsNotice);
|
||||
Map<String, String> config = MapUtils.jsonToMap(smsNotice);
|
||||
this.setTemplateId(config.getOrDefault("templateId", ""));
|
||||
this.setContent(config.getOrDefault("content", ""));
|
||||
this.setStatus(Integer.parseInt(config.getOrDefault("status", "0")));
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.mdd.common.plugin.sms.engine;
|
||||
|
||||
import com.mdd.common.util.ToolsUtils;
|
||||
import com.mdd.common.util.ToolUtils;
|
||||
|
||||
import javax.net.ssl.*;
|
||||
import java.io.*;
|
||||
@@ -241,7 +241,7 @@ public class HuaweiSms {
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
|
||||
String time = sdf.format(new Date()); //Created
|
||||
String nonce = ToolsUtils.makeUUID().replace("-", "");
|
||||
String nonce = ToolUtils.makeUUID().replace("-", "");
|
||||
|
||||
MessageDigest md;
|
||||
byte[] passwordDigest = null;
|
||||
|
||||
@@ -105,7 +105,7 @@ public class ConfigUtils {
|
||||
return new LinkedHashMap<>();
|
||||
}
|
||||
|
||||
return ToolsUtils.jsonToMap(config.getValue());
|
||||
return MapUtils.jsonToMap(config.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,9 +9,9 @@ import java.lang.reflect.Type;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 数组工具类
|
||||
* 列表工具类
|
||||
*/
|
||||
public class ArrayUtils {
|
||||
public class ListUtils {
|
||||
|
||||
/**
|
||||
* JSONArray转树形结构
|
||||
@@ -0,0 +1,82 @@
|
||||
package com.mdd.common.util;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Map工具类
|
||||
*/
|
||||
public class MapUtils {
|
||||
|
||||
/**
|
||||
* JSON转 Map<String, String>
|
||||
*
|
||||
* @author fzr
|
||||
* @param json 对象
|
||||
* @return Map<String, String>
|
||||
*/
|
||||
public static Map<String, String> jsonToMap(String json){
|
||||
Type type = new TypeToken<Map<String, String>>() {}.getType();
|
||||
return JSON.parseObject(json, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* JSON转 Map<String, Object>
|
||||
*
|
||||
* @author fzr
|
||||
* @param json 对象
|
||||
* @return Map<String, Object>
|
||||
*/
|
||||
public static Map<String, Object> jsonToMapAsObj(String json){
|
||||
Type type = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
return JSON.parseObject(json, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* JSON转Map<String, String>
|
||||
*
|
||||
* @author fzr
|
||||
* @param object 对象
|
||||
* @return Map<String, String>
|
||||
*/
|
||||
public static Map<String, String> objectToMap(Object object){
|
||||
Type type = new TypeToken<Map<String, String>>() {}.getType();
|
||||
return JSON.parseObject(JSONObject.toJSONString(object), type);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 对象类型Map合并
|
||||
*
|
||||
* @author fzr
|
||||
* @param map 对象
|
||||
* @return Map<String, Object>
|
||||
*/
|
||||
public static Map<String, Object> mergeMapByObj(Map<String, Object> map, Map<String, Object> map1){
|
||||
HashMap<String, Object> map2 = new HashMap<>();
|
||||
map2.putAll(map);
|
||||
map2.putAll(map1);
|
||||
return map2;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 字符串类型Map合并
|
||||
*
|
||||
* @author fzr
|
||||
* @param map 对象
|
||||
* @return Map<String, String>
|
||||
*/
|
||||
public static Map<String, String> mergeMapByStr(Map<String, String> map, Map<String, String> map1){
|
||||
HashMap<String, String> map2 = new HashMap<>();
|
||||
map2.putAll(map);
|
||||
map2.putAll(map1);
|
||||
return map2;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,6 +13,9 @@ import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Redis工具
|
||||
*/
|
||||
@Component
|
||||
public class RedisUtils {
|
||||
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
package com.mdd.common.util;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.mdd.common.config.GlobalConfig;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -16,7 +12,7 @@ import java.util.*;
|
||||
/**
|
||||
* 常用工具集合
|
||||
*/
|
||||
public class ToolsUtils {
|
||||
public class ToolUtils {
|
||||
|
||||
/**
|
||||
* 制作UUID
|
||||
@@ -58,10 +54,10 @@ public class ToolsUtils {
|
||||
*/
|
||||
public static String makeToken() {
|
||||
long millisecond = System.currentTimeMillis();
|
||||
String randStr = ToolsUtils.randomString(8);
|
||||
String randStr = ToolUtils.randomString(8);
|
||||
String secret = GlobalConfig.secret;
|
||||
String token = ToolsUtils.makeMd5(ToolsUtils.makeUUID() + millisecond + randStr);
|
||||
return ToolsUtils.makeMd5(token + secret) + ToolsUtils.randomString(6);
|
||||
String token = ToolUtils.makeMd5(ToolUtils.makeUUID() + millisecond + randStr);
|
||||
return ToolUtils.makeMd5(token + secret) + ToolUtils.randomString(6);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -137,7 +133,7 @@ public class ToolsUtils {
|
||||
* @param urlString (文件网址)
|
||||
* @param savePath (保存路径,如: /www/uploads)
|
||||
* @param filename (保存名称,如: aa.png)
|
||||
* @throws IOException 异常
|
||||
* @throws IOException IO异常
|
||||
*/
|
||||
public static void download(String urlString, String savePath, String filename) throws IOException {
|
||||
URL url = new URL(urlString);
|
||||
@@ -161,68 +157,4 @@ public class ToolsUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* JSON转 Map<String, String>
|
||||
*
|
||||
* @author fzr
|
||||
* @param json 对象
|
||||
* @return Map<String, String>
|
||||
*/
|
||||
public static Map<String, String> jsonToMap(String json){
|
||||
Type type = new TypeToken<Map<String, String>>() {}.getType();
|
||||
return JSON.parseObject(json, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* JSON转 Map<String, Object>
|
||||
*
|
||||
* @author fzr
|
||||
* @param json 对象
|
||||
* @return Map<String, String>
|
||||
*/
|
||||
public static Map<String, Object> jsonToMapAsObj(String json){
|
||||
Type type = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
return JSON.parseObject(json, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* JSON转Map<String, String>
|
||||
*
|
||||
* @author fzr
|
||||
* @param object 对象
|
||||
* @return Map<String, String>
|
||||
*/
|
||||
public static Map<String, String> objectToMap(Object object){
|
||||
Type type = new TypeToken<Map<String, String>>() {}.getType();
|
||||
return JSON.parseObject(JSONObject.toJSONString(object), type);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对象类型Map合并
|
||||
*
|
||||
* @author fzr
|
||||
* @param map 对象
|
||||
* @return Object
|
||||
*/
|
||||
public static Map<String, Object> mergeMapByObj(Map<String, Object> map, Map<String, Object> map1){
|
||||
HashMap<String, Object> map2 = new HashMap<>();
|
||||
map2.putAll(map);
|
||||
map2.putAll(map1);
|
||||
return map2;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串类型Map合并
|
||||
*
|
||||
* @author fzr
|
||||
* @param map 对象
|
||||
* @return Object
|
||||
*/
|
||||
public static Map<String, String> mergeMapByStr(Map<String, String> map, Map<String, String> map1){
|
||||
HashMap<String, String> map2 = new HashMap<>();
|
||||
map2.putAll(map);
|
||||
map2.putAll(map1);
|
||||
return map2;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,11 +17,23 @@
|
||||
|
||||
<!-- 项目管理 -->
|
||||
<dependencies>
|
||||
<!-- 公共依赖 -->
|
||||
<!-- 全局工具 -->
|
||||
<dependency>
|
||||
<groupId>org.mdd</groupId>
|
||||
<artifactId>like-common</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SaToken -->
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SaToken-Redis -->
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-dao-redis-jackson</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<!-- 插件管理 -->
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
package com.mdd.front;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.mdd.common.aop.NotLogin;
|
||||
import com.mdd.common.core.AjaxResult;
|
||||
import com.mdd.common.entity.user.User;
|
||||
import com.mdd.common.enums.HttpEnum;
|
||||
import com.mdd.common.exception.LoginException;
|
||||
import com.mdd.common.mapper.user.UserMapper;
|
||||
import com.mdd.common.util.RedisUtils;
|
||||
import com.mdd.common.util.StringUtils;
|
||||
import com.mdd.common.util.YmlUtils;
|
||||
import com.mdd.front.config.FrontConfig;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
@@ -18,8 +19,7 @@ import org.springframework.web.servlet.HandlerInterceptor;
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* 拦截器
|
||||
@@ -30,85 +30,49 @@ public class LikeFrontInterceptor implements HandlerInterceptor {
|
||||
@Resource
|
||||
UserMapper userMapper;
|
||||
|
||||
/**
|
||||
* 前置处理器
|
||||
*
|
||||
* @param request 请求
|
||||
* @param response 响应
|
||||
* @param handler 处理
|
||||
* @return boolean
|
||||
* @throws Exception 异常
|
||||
*/
|
||||
@Override
|
||||
public boolean preHandle(@NonNull HttpServletRequest request,
|
||||
@NonNull HttpServletResponse response,
|
||||
@NonNull Object handler) throws Exception {
|
||||
|
||||
// 判断请求接口
|
||||
response.setContentType("application/json;charset=utf-8");
|
||||
if (!(handler instanceof HandlerMethod)) {
|
||||
return HandlerInterceptor.super.preHandle(request, response, handler);
|
||||
}
|
||||
|
||||
// 免登录接口
|
||||
String token = request.getHeader("token");
|
||||
token = FrontConfig.frontendTokenKey + token;
|
||||
List<String> notLoginUri = Arrays.asList(FrontConfig.notLoginUri);
|
||||
if (notLoginUri.contains(request.getRequestURI())) {
|
||||
if (StringUtils.isNotEmpty(token)) {
|
||||
Object uid = RedisUtils.get(token);
|
||||
if (uid != null) {
|
||||
Integer userId = Integer.parseInt(uid.toString());
|
||||
LikeFrontThreadLocal.put("userId", userId);
|
||||
}
|
||||
}
|
||||
return HandlerInterceptor.super.preHandle(request, response, handler);
|
||||
}
|
||||
|
||||
// Token是否为空
|
||||
if (com.baomidou.mybatisplus.core.toolkit.StringUtils.isBlank(token)) {
|
||||
AjaxResult<Object> result = AjaxResult.failed(HttpEnum.TOKEN_EMPTY.getCode(), HttpEnum.TOKEN_EMPTY.getMsg());
|
||||
// 登录权限校验
|
||||
try {
|
||||
Method method = this.obtainAop(handler);
|
||||
this.checkLogin(method);
|
||||
} catch (LoginException e) {
|
||||
AjaxResult<Object> result = AjaxResult.failed(e.getCode(), e.getMsg());
|
||||
response.getWriter().print(JSON.toJSONString(result));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Token是否过期
|
||||
if (!RedisUtils.exists(token)) {
|
||||
AjaxResult<Object> result = AjaxResult.failed(HttpEnum.TOKEN_INVALID.getCode(), HttpEnum.TOKEN_INVALID.getMsg());
|
||||
response.getWriter().print(JSON.toJSONString(result));
|
||||
return false;
|
||||
}
|
||||
|
||||
// 用户信息缓存
|
||||
Object uid = RedisUtils.get(token);
|
||||
Integer userId = Integer.parseInt(uid.toString());
|
||||
User user = userMapper.selectOne(new QueryWrapper<User>()
|
||||
.select("id,sn,username,nickname,mobile,is_disable,is_delete")
|
||||
.eq("id", userId)
|
||||
.last("limit 1"));
|
||||
|
||||
// 校验用户被删除
|
||||
if (user.getIsDelete().equals(1)) {
|
||||
AjaxResult<Object> result = AjaxResult.failed(HttpEnum.TOKEN_INVALID.getCode(), HttpEnum.TOKEN_INVALID.getMsg());
|
||||
response.getWriter().print(JSON.toJSONString(result));
|
||||
return false;
|
||||
}
|
||||
|
||||
// 校验用户被禁用
|
||||
if (user.getIsDisable().equals(1)) {
|
||||
AjaxResult<Object> result = AjaxResult.failed(HttpEnum.LOGIN_DISABLE_ERROR.getCode(), HttpEnum.LOGIN_DISABLE_ERROR.getMsg());
|
||||
response.getWriter().print(JSON.toJSONString(result));
|
||||
return false;
|
||||
}
|
||||
|
||||
// 令牌自动续签
|
||||
int tokenRenewTime = Integer.parseInt(YmlUtils.get("like.token-renew-time"));
|
||||
if (RedisUtils.ttl(token) < tokenRenewTime) {
|
||||
long tokenValidTime = Long.parseLong(YmlUtils.get("like.token-valid-time"));
|
||||
RedisUtils.expire(token, tokenValidTime);
|
||||
}
|
||||
|
||||
// 写入本地线程
|
||||
LikeFrontThreadLocal.put("userId", user.getId());
|
||||
LikeFrontThreadLocal.put("userSn", user.getSn());
|
||||
LikeFrontThreadLocal.put("username", user.getUsername());
|
||||
LikeFrontThreadLocal.put("nickname", user.getNickname());
|
||||
LikeFrontThreadLocal.put("mobile", user.getMobile());
|
||||
|
||||
// 验证通过继续操作
|
||||
return HandlerInterceptor.super.preHandle(request, response, handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* 后置处理器
|
||||
*
|
||||
* @param request 请求
|
||||
* @param response 响应
|
||||
* @param handler 处理
|
||||
* @param ex 异常
|
||||
* @throws Exception 异常
|
||||
*/
|
||||
@Override
|
||||
public void afterCompletion(@NonNull HttpServletRequest request,
|
||||
@NonNull HttpServletResponse response,
|
||||
@@ -117,4 +81,91 @@ public class LikeFrontInterceptor implements HandlerInterceptor {
|
||||
HandlerInterceptor.super.afterCompletion(request, response, handler, ex);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取注解
|
||||
*
|
||||
* @param handler 处理器
|
||||
* @return Method
|
||||
* @throws Exception 异常
|
||||
*/
|
||||
private Method obtainAop(@NotNull Object handler) throws Exception {
|
||||
String[] objArr = handler.toString().split("#");
|
||||
String methodStr = objArr[1].split("\\(")[0];
|
||||
String classStr = objArr[0];
|
||||
Class<?> clazz = Class.forName(classStr);
|
||||
|
||||
Method[] methods = clazz.getDeclaredMethods();
|
||||
for (Method method : methods) {
|
||||
if (method.getName().equals(methodStr)) {
|
||||
return method;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录验证
|
||||
*
|
||||
* @param method 方法类
|
||||
* @author fzr
|
||||
*/
|
||||
private void checkLogin(Method method) {
|
||||
for (int i=0; i<=0; i++) {
|
||||
// 免登校验
|
||||
Object id = StpUtil.getLoginId();
|
||||
if (StringUtils.isNotNull(method) && method.isAnnotationPresent(NotLogin.class)) {
|
||||
if (StringUtils.isNotNull(id)) {
|
||||
Integer userId = Integer.parseInt(id.toString());
|
||||
LikeFrontThreadLocal.put("userId", userId);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// 令牌校验
|
||||
String token = StpUtil.getTokenValue();
|
||||
if (StringUtils.isNull(token) || StringUtils.isBlank(token)) {
|
||||
Integer errCode = HttpEnum.TOKEN_EMPTY.getCode();
|
||||
String errMsg = HttpEnum.TOKEN_EMPTY.getMsg();
|
||||
throw new LoginException(errCode, errMsg);
|
||||
}
|
||||
|
||||
// 登录校验
|
||||
if (StringUtils.isNull(id)) {
|
||||
Integer errCode = HttpEnum.TOKEN_INVALID.getCode();
|
||||
String errMsg = HttpEnum.TOKEN_INVALID.getMsg();
|
||||
throw new LoginException(errCode, errMsg);
|
||||
}
|
||||
|
||||
// 用户信息缓存
|
||||
Integer userId = Integer.parseInt(id.toString());
|
||||
User user = userMapper.selectOne(new QueryWrapper<User>()
|
||||
.select("id,sn,username,nickname,mobile,is_disable")
|
||||
.eq("id", userId)
|
||||
.eq("is_delete", 0)
|
||||
.last("limit 1"));
|
||||
|
||||
// 删除校验
|
||||
if (StringUtils.isNull(user)) {
|
||||
Integer errCode = HttpEnum.TOKEN_INVALID.getCode();
|
||||
String errMsg = HttpEnum.TOKEN_INVALID.getMsg();
|
||||
throw new LoginException(errCode, errMsg);
|
||||
}
|
||||
|
||||
// 禁用校验
|
||||
if (user.getIsDisable().equals(1)) {
|
||||
Integer errCode = HttpEnum.LOGIN_DISABLE_ERROR.getCode();
|
||||
String errMsg = HttpEnum.LOGIN_DISABLE_ERROR.getMsg();
|
||||
throw new LoginException(errCode, errMsg);
|
||||
}
|
||||
|
||||
// 写入线程
|
||||
LikeFrontThreadLocal.put("userId", user.getId());
|
||||
LikeFrontThreadLocal.put("userSn", user.getSn());
|
||||
LikeFrontThreadLocal.put("username", user.getUsername());
|
||||
LikeFrontThreadLocal.put("nickname", user.getNickname());
|
||||
LikeFrontThreadLocal.put("mobile", user.getMobile());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
27
server/like-front/src/main/java/com/mdd/front/cache/ScanLoginCache.java
vendored
Normal file
27
server/like-front/src/main/java/com/mdd/front/cache/ScanLoginCache.java
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
package com.mdd.front.cache;
|
||||
|
||||
import com.mdd.common.util.RedisUtils;
|
||||
import com.mdd.common.util.StringUtils;
|
||||
|
||||
/**
|
||||
* 微信扫码登录缓存
|
||||
*/
|
||||
public class ScanLoginCache {
|
||||
|
||||
private static final String KEY = "wechat:scan:login:";
|
||||
|
||||
public static String get(String sessionId) {
|
||||
Object o = RedisUtils.get(KEY+sessionId);
|
||||
if (StringUtils.isNull(o)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
RedisUtils.del(KEY+sessionId);
|
||||
return o.toString();
|
||||
}
|
||||
|
||||
public static void set(String sessionId, String state) {
|
||||
RedisUtils.set(KEY+sessionId, state, 600);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
package com.mdd.front.config;
|
||||
|
||||
/**
|
||||
* 前台公共配置
|
||||
*/
|
||||
public class FrontConfig {
|
||||
|
||||
// 登录缓存键
|
||||
public static final String frontendTokenKey = "frontend:token:";
|
||||
|
||||
// 免登录验证
|
||||
public static String[] notLoginUri = new String[]{
|
||||
"/api/index",
|
||||
"/api/config",
|
||||
"/api/policy",
|
||||
"/api/search",
|
||||
"/api/hotSearch",
|
||||
"/api/decorate",
|
||||
"/api/sms/send",
|
||||
"/api/upload/image",
|
||||
|
||||
"/api/login/check",
|
||||
"/api/login/codeUrl",
|
||||
"/api/login/oaLogin",
|
||||
"/api/login/register",
|
||||
"/api/login/forgotPassword",
|
||||
|
||||
"/api/article/category",
|
||||
"/api/article/detail",
|
||||
"/api/article/list",
|
||||
"/api/pc/getConfig",
|
||||
"/api/pc/index",
|
||||
"/api/pc/articleCenter",
|
||||
"/api/pc/articleDetail",
|
||||
"/api/login/getScanCode",
|
||||
"/api/login/scanLogin",
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.mdd.front.controller;
|
||||
|
||||
import com.mdd.common.aop.NotLogin;
|
||||
import com.mdd.common.core.AjaxResult;
|
||||
import com.mdd.common.core.PageResult;
|
||||
import com.mdd.common.validator.annotation.IDMust;
|
||||
@@ -16,6 +17,7 @@ import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -34,6 +36,7 @@ public class ArticleController {
|
||||
* @author fzr
|
||||
* @return AjaxResult<List<ArticleCateVo>>
|
||||
*/
|
||||
@NotLogin
|
||||
@GetMapping("/category")
|
||||
public AjaxResult<List<ArticleCateVo>> category() {
|
||||
List<ArticleCateVo> list = iArticleService.category();
|
||||
@@ -46,6 +49,7 @@ public class ArticleController {
|
||||
* @author fzr
|
||||
* @return AjaxResult<PageResult<ArticleListVo>>
|
||||
*/
|
||||
@NotLogin
|
||||
@GetMapping("/list")
|
||||
public AjaxResult<PageResult<ArticleListedVo>> list(@Validated PageValidate pageValidate,
|
||||
@Validated ArticleSearchValidate searchValidate) {
|
||||
@@ -60,6 +64,7 @@ public class ArticleController {
|
||||
* @author fzr
|
||||
* @return AjaxResult<ArticleDetailVo>
|
||||
*/
|
||||
@NotLogin
|
||||
@GetMapping("/detail")
|
||||
public AjaxResult<ArticleDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
|
||||
Integer userId = LikeFrontThreadLocal.getUserId();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.mdd.front.controller;
|
||||
|
||||
import com.mdd.common.aop.NotLogin;
|
||||
import com.mdd.common.core.AjaxResult;
|
||||
import com.mdd.common.core.PageResult;
|
||||
import com.mdd.common.validator.annotation.IDMust;
|
||||
@@ -32,6 +33,7 @@ public class IndexController {
|
||||
* @author fzr
|
||||
* @return AjaxResult<Map<String, Object>>
|
||||
*/
|
||||
@NotLogin
|
||||
@GetMapping("/index")
|
||||
public AjaxResult<Map<String, Object>> index() {
|
||||
Map<String, Object> detail = iIndexService.index();
|
||||
@@ -45,6 +47,7 @@ public class IndexController {
|
||||
* @param id 主键
|
||||
* @return AjaxResult<Map<String, Object>>
|
||||
*/
|
||||
@NotLogin
|
||||
@GetMapping("/decorate")
|
||||
public AjaxResult<Map<String, Object>> decorate(@Validated @IDMust() @RequestParam("id") Integer id) {
|
||||
Map<String, Object> detail = iIndexService.decorate(id);
|
||||
@@ -57,6 +60,7 @@ public class IndexController {
|
||||
* @author fzr
|
||||
* @return AjaxResult<Map<String, Object>>
|
||||
*/
|
||||
@NotLogin
|
||||
@GetMapping("/config")
|
||||
public AjaxResult<Map<String, Object>> config() {
|
||||
Map<String, Object> map = iIndexService.config();
|
||||
@@ -70,6 +74,7 @@ public class IndexController {
|
||||
* @param type 类型 service=服务协议,privacy=隐私协议
|
||||
* @return AjaxResult<Map<String, String>>
|
||||
*/
|
||||
@NotLogin
|
||||
@GetMapping("/policy")
|
||||
public AjaxResult<Map<String, String>> policy(@RequestParam String type) {
|
||||
Map<String, String> map = iIndexService.policy(type);
|
||||
@@ -82,6 +87,7 @@ public class IndexController {
|
||||
* @author fzr
|
||||
* @return AjaxResult<List<String>>
|
||||
*/
|
||||
@NotLogin
|
||||
@GetMapping("/hotSearch")
|
||||
public AjaxResult<List<String>> hotSearch() {
|
||||
List<String> list = iIndexService.hotSearch();
|
||||
@@ -96,6 +102,7 @@ public class IndexController {
|
||||
* @param params 搜素参数
|
||||
* @return AjaxResult<PageResult<ArticleListVo>>
|
||||
*/
|
||||
@NotLogin
|
||||
@GetMapping("/search")
|
||||
public AjaxResult<PageResult<ArticleListedVo>> search(@Validated PageValidate pageValidate,
|
||||
@RequestParam Map<String, String> params) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.mdd.front.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
||||
import com.mdd.common.aop.NotLogin;
|
||||
import com.mdd.common.core.AjaxResult;
|
||||
import com.mdd.common.enums.ClientEnum;
|
||||
import com.mdd.common.util.StringUtils;
|
||||
@@ -37,6 +38,7 @@ public class LoginController {
|
||||
* @param registerValidate 参数
|
||||
* @return AjaxResult<Object>
|
||||
*/
|
||||
@NotLogin
|
||||
@PostMapping("/register")
|
||||
public AjaxResult<Object> register(@Validated @RequestBody RegisterValidate registerValidate) {
|
||||
iLoginService.register(registerValidate);
|
||||
@@ -50,6 +52,7 @@ public class LoginController {
|
||||
* @param params 参数
|
||||
* @return AjaxResult<LoginTokenVo>
|
||||
*/
|
||||
@NotLogin
|
||||
@PostMapping("/check")
|
||||
public AjaxResult<LoginTokenVo> check(@RequestBody Map<String, String> params) {
|
||||
Assert.notNull(params.get("scene"), "scene参数缺失!");
|
||||
@@ -81,6 +84,7 @@ public class LoginController {
|
||||
* @param oaLoginValidate 参数
|
||||
* @return AjaxResult<LoginTokenVo>
|
||||
*/
|
||||
@NotLogin
|
||||
@PostMapping("/oaLogin")
|
||||
public AjaxResult<LoginTokenVo> oaLogin(@Validated @RequestBody OaLoginValidate oaLoginValidate) {
|
||||
String code = oaLoginValidate.getCode();
|
||||
@@ -98,6 +102,7 @@ public class LoginController {
|
||||
* @param url 连接
|
||||
* @return AjaxResult<LoginCodesVo>
|
||||
*/
|
||||
@NotLogin
|
||||
@GetMapping("/codeUrl")
|
||||
public AjaxResult<LoginUrlsVo> codeUrl(@RequestParam String url) {
|
||||
Assert.notNull(url, "url参数不能为空");
|
||||
@@ -114,6 +119,7 @@ public class LoginController {
|
||||
* @param forgetPwdValidate 参数
|
||||
* @return AjaxResult<Object>
|
||||
*/
|
||||
@NotLogin
|
||||
@PostMapping("/forgotPassword")
|
||||
public AjaxResult<Object> forgotPassword(@Validated @RequestBody ForgetPwdValidate forgetPwdValidate) {
|
||||
iLoginService.forgotPassword(forgetPwdValidate);
|
||||
@@ -127,6 +133,7 @@ public class LoginController {
|
||||
* @param session session
|
||||
* @return AjaxResult<LoginUrlsVo>
|
||||
*/
|
||||
@NotLogin
|
||||
@GetMapping("/getScanCode")
|
||||
public AjaxResult<LoginUrlsVo> getScanCode(@RequestParam String url, HttpSession session) {
|
||||
String qrcodeUrl = iLoginService.getScanCode(url, session);
|
||||
@@ -142,6 +149,7 @@ public class LoginController {
|
||||
* @param scanLoginValidate 参数
|
||||
* @return AjaxResult<Object>
|
||||
*/
|
||||
@NotLogin
|
||||
@PostMapping("/scanLogin")
|
||||
public AjaxResult<Object> scanLogin(@Validated @RequestBody ScanLoginValidate scanLoginValidate, HttpSession session) {
|
||||
LoginTokenVo vo = iLoginService.scanLogin(scanLoginValidate, session);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.mdd.front.controller;
|
||||
|
||||
import com.mdd.common.aop.NotLogin;
|
||||
import com.mdd.common.core.AjaxResult;
|
||||
import com.mdd.common.validator.annotation.IDMust;
|
||||
import com.mdd.front.LikeFrontThreadLocal;
|
||||
@@ -32,6 +33,7 @@ public class PcController {
|
||||
* @author cjh
|
||||
* @return AjaxResult<Map<String, Object>>
|
||||
*/
|
||||
@NotLogin
|
||||
@GetMapping("/index")
|
||||
public AjaxResult<Map<String,Object>> index() {
|
||||
Map<String, Object> index = iPcService.index();
|
||||
@@ -43,6 +45,7 @@ public class PcController {
|
||||
* @author cjh
|
||||
* @return AjaxResult<Map<String, Object>>
|
||||
*/
|
||||
@NotLogin
|
||||
@GetMapping("/getConfig")
|
||||
public AjaxResult<Map<String, Object>> getConfig() {
|
||||
Map<String, Object> config = iPcService.getConfig();
|
||||
@@ -55,6 +58,7 @@ public class PcController {
|
||||
* @author fzr
|
||||
* @return AjaxResult<List<PcArticleCenterVo>>
|
||||
*/
|
||||
@NotLogin
|
||||
@GetMapping("/articleCenter")
|
||||
public AjaxResult<List<PcArticleCenterVo>> articleCenter() {
|
||||
List<PcArticleCenterVo> list = iPcService.articleCenter();
|
||||
@@ -68,6 +72,7 @@ public class PcController {
|
||||
* @param id 文章主键
|
||||
* @return AjaxResult<PcArticleDetailVo>
|
||||
*/
|
||||
@NotLogin
|
||||
@GetMapping("/articleDetail")
|
||||
public AjaxResult<PcArticleDetailVo> articleDetail(@Validated @IDMust() @RequestParam("id") Integer id) {
|
||||
Integer userId = LikeFrontThreadLocal.getUserId();
|
||||
|
||||
@@ -9,7 +9,7 @@ import com.mdd.common.mapper.notice.NoticeRecordMapper;
|
||||
import com.mdd.common.plugin.notice.NoticeDriver;
|
||||
import com.mdd.common.plugin.notice.vo.NoticeSmsVo;
|
||||
import com.mdd.common.util.StringUtils;
|
||||
import com.mdd.common.util.ToolsUtils;
|
||||
import com.mdd.common.util.ToolUtils;
|
||||
import com.mdd.front.validate.commons.SmsValidate;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@@ -57,7 +57,7 @@ public class SmsController {
|
||||
.setMobile(smsValidate.getMobile())
|
||||
.setExpire(900)
|
||||
.setParams(new String[] {
|
||||
"code:" + ToolsUtils.randomInt(4)
|
||||
"code:" + ToolUtils.randomInt(4)
|
||||
});
|
||||
|
||||
NoticeDriver.handle(params);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.mdd.front.controller;
|
||||
|
||||
import com.mdd.common.aop.NotLogin;
|
||||
import com.mdd.common.core.AjaxResult;
|
||||
import com.mdd.common.enums.AlbumEnum;
|
||||
import com.mdd.common.exception.OperateException;
|
||||
@@ -28,6 +29,7 @@ public class UploadController {
|
||||
* @param request 请求对象
|
||||
* @return AjaxResult<UploadFilesVo>
|
||||
*/
|
||||
@NotLogin
|
||||
@PostMapping("/image")
|
||||
public AjaxResult<UploadFilesVo> image(HttpServletRequest request) {
|
||||
MultipartFile multipartFile;
|
||||
|
||||
@@ -133,11 +133,11 @@ public class IndexServiceImpl implements IIndexService {
|
||||
// 登录配置
|
||||
Map<String, Object> loginMap = new LinkedHashMap<>();
|
||||
Map<String, String> loginConfig = ConfigUtils.get("login");
|
||||
loginMap.put("loginWay", ArrayUtils.stringToListAsInt(loginConfig.getOrDefault("loginWay", ""), ","));
|
||||
loginMap.put("loginWay", ListUtils.stringToListAsInt(loginConfig.getOrDefault("loginWay", ""), ","));
|
||||
loginMap.put("forceBindMobile", Integer.parseInt(loginConfig.getOrDefault("forceBindMobile", "0")));
|
||||
loginMap.put("openAgreement", Integer.parseInt(loginConfig.getOrDefault("openAgreement", "0")));
|
||||
loginMap.put("openOtherAuth", Integer.parseInt(loginConfig.getOrDefault("openOtherAuth", "0")));
|
||||
loginMap.put("autoLoginAuth", ArrayUtils.stringToListAsInt(loginConfig.getOrDefault("autoLoginAuth", ""), ","));
|
||||
loginMap.put("autoLoginAuth", ListUtils.stringToListAsInt(loginConfig.getOrDefault("autoLoginAuth", ""), ","));
|
||||
|
||||
// 网址信息
|
||||
Map<String, Object> websiteMap = new LinkedHashMap<>();
|
||||
@@ -156,7 +156,7 @@ public class IndexServiceImpl implements IIndexService {
|
||||
// 响应数据
|
||||
response.put("version", GlobalConfig.version);
|
||||
response.put("domain", UrlUtils.domain());
|
||||
response.put("style", ToolsUtils.jsonToMap(tabbarStyle));
|
||||
response.put("style", MapUtils.jsonToMap(tabbarStyle));
|
||||
response.put("tabbar", tabs);
|
||||
response.put("login", loginMap);
|
||||
response.put("website", websiteMap);
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.mdd.front.service.impl;
|
||||
|
||||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
||||
import com.mdd.common.entity.user.User;
|
||||
@@ -13,6 +14,7 @@ import com.mdd.common.mapper.user.UserAuthMapper;
|
||||
import com.mdd.common.mapper.user.UserMapper;
|
||||
import com.mdd.common.plugin.notice.NoticeCheck;
|
||||
import com.mdd.common.util.*;
|
||||
import com.mdd.front.cache.ScanLoginCache;
|
||||
import com.mdd.front.config.FrontConfig;
|
||||
import com.mdd.front.service.ILoginService;
|
||||
import com.mdd.front.validate.login.RegisterValidate;
|
||||
@@ -64,8 +66,8 @@ public class LoginServiceImpl implements ILoginService {
|
||||
Assert.isNull(model, "账号已存在,换一个吧!");
|
||||
|
||||
Integer sn = this.randMakeSn();
|
||||
String salt = ToolsUtils.randomString(5);
|
||||
String pwd = ToolsUtils.makeMd5(registerValidate.getPassword()+salt);
|
||||
String salt = ToolUtils.randomString(5);
|
||||
String pwd = ToolUtils.makeMd5(registerValidate.getPassword()+salt);
|
||||
|
||||
User user = new User();
|
||||
user.setSn(sn);
|
||||
@@ -101,14 +103,9 @@ public class LoginServiceImpl implements ILoginService {
|
||||
.last("limit 1"));
|
||||
|
||||
Assert.notNull(user, "账号不存在!");
|
||||
String pwd = ToolsUtils.makeMd5(password+user.getSalt());
|
||||
String pwd = ToolUtils.makeMd5(password+user.getSalt());
|
||||
Assert.isFalse(!pwd.equals(user.getPassword()), "账号或密码错误!");
|
||||
Assert.isFalse(user.getIsDisable() != 0, "账号已被禁用!");
|
||||
|
||||
// 更新登录信息
|
||||
user.setLastLoginIp(IpUtils.getHostIp());
|
||||
user.setLastLoginTime(System.currentTimeMillis() / 1000);
|
||||
userMapper.updateById(user);
|
||||
Assert.isFalse(!user.getIsDisable().equals(0), "账号已被禁用!");
|
||||
|
||||
return this.makeLoginToken(user.getId(), user.getMobile());
|
||||
}
|
||||
@@ -143,11 +140,6 @@ public class LoginServiceImpl implements ILoginService {
|
||||
Assert.notNull(user, "账号不存在!");
|
||||
Assert.isFalse(user.getIsDisable() != 0, "账号已禁用!");
|
||||
|
||||
// 更新登录信息
|
||||
user.setLastLoginIp(IpUtils.getHostIp());
|
||||
user.setLastLoginTime(System.currentTimeMillis() / 1000);
|
||||
userMapper.updateById(user);
|
||||
|
||||
return this.makeLoginToken(user.getId(), user.getMobile());
|
||||
}
|
||||
|
||||
@@ -237,8 +229,8 @@ public class LoginServiceImpl implements ILoginService {
|
||||
// 验证账号
|
||||
Assert.notNull(user, "账号不存在!");
|
||||
|
||||
String salt = ToolsUtils.randomString(5);
|
||||
String pwd = ToolsUtils.makeMd5(password.trim()+salt);
|
||||
String salt = ToolUtils.randomString(5);
|
||||
String pwd = ToolUtils.makeMd5(password.trim()+salt);
|
||||
|
||||
// 更新密码
|
||||
user.setPassword(pwd);
|
||||
@@ -277,9 +269,10 @@ public class LoginServiceImpl implements ILoginService {
|
||||
}
|
||||
|
||||
// 防止csrf攻击
|
||||
String state = ToolsUtils.makeUUID().replaceAll("-", "");
|
||||
RedisUtils.set("wechat-open-state-"+session.getId(), state, 600);
|
||||
//生成qrcodeUrl
|
||||
String state = ToolUtils.makeUUID().replaceAll("-", "");
|
||||
ScanLoginCache.set(session.getId(), state);
|
||||
|
||||
//生成QrcodeUrl
|
||||
return String.format(baseUrl, appId, redirectUrl, state);
|
||||
}
|
||||
|
||||
@@ -288,11 +281,12 @@ public class LoginServiceImpl implements ILoginService {
|
||||
*
|
||||
* @author fzr
|
||||
* @param scanLoginValidate 参数
|
||||
* @param session 当前会话
|
||||
*/
|
||||
@Override
|
||||
public LoginTokenVo scanLogin(ScanLoginValidate scanLoginValidate, HttpSession session) {
|
||||
Object o = RedisUtils.get("wechat-open-state-"+session.getId());
|
||||
if (StringUtils.isNull(o) || !o.toString().equals(scanLoginValidate.getState())) {
|
||||
// 验证唯一标识是否过期
|
||||
if (ScanLoginCache.get(session.getId()).equals(scanLoginValidate.getState())) {
|
||||
throw new OperateException("二维码已失效或不存在,请重新操作");
|
||||
}
|
||||
|
||||
@@ -312,7 +306,7 @@ public class LoginServiceImpl implements ILoginService {
|
||||
try {
|
||||
String accessTokenUrl = String.format(baseAccessTokenUrl, appId, appSecret, code);
|
||||
String result = HttpUtils.sendGet(accessTokenUrl);
|
||||
resultMap = ToolsUtils.jsonToMap(result);
|
||||
resultMap = MapUtils.jsonToMap(result);
|
||||
} catch (Exception e) {
|
||||
throw new OperateException("获取access_token失败:"+e.getMessage());
|
||||
}
|
||||
@@ -325,7 +319,7 @@ public class LoginServiceImpl implements ILoginService {
|
||||
Map<String, String> userinfoMap;
|
||||
try {
|
||||
String resultUserInfo = HttpUtils.sendGet(userInfoUrl);
|
||||
userinfoMap = ToolsUtils.jsonToMap(resultUserInfo);
|
||||
userinfoMap = MapUtils.jsonToMap(resultUserInfo);
|
||||
} catch (Exception e) {
|
||||
throw new OperateException("获取用户信息失败:"+e.getMessage());
|
||||
}
|
||||
@@ -333,7 +327,6 @@ public class LoginServiceImpl implements ILoginService {
|
||||
String openId = userinfoMap.get("openid");
|
||||
String uniId = userinfoMap.get("unionid");
|
||||
String unionId = uniId == null ? "0" : uniId;
|
||||
RedisUtils.del("wechat-open-state-"+session.getId());
|
||||
return this.userService(openId, unionId, ClientEnum.PC.getCode());
|
||||
}
|
||||
|
||||
@@ -346,16 +339,20 @@ public class LoginServiceImpl implements ILoginService {
|
||||
* @return LoginTokenVo
|
||||
*/
|
||||
private LoginTokenVo makeLoginToken(Integer userId, String mobile) {
|
||||
mobile = StringUtils.isNull(mobile) ? "" : mobile;
|
||||
// 实现账号登录
|
||||
StpUtil.login(userId);
|
||||
|
||||
String token = ToolsUtils.makeToken();
|
||||
int tokenValidTime = Integer.parseInt(YmlUtils.get("like.token-valid-time"));
|
||||
RedisUtils.set(FrontConfig.frontendTokenKey+token, userId, tokenValidTime);
|
||||
// 更新登录信息
|
||||
User user = new User();
|
||||
user.setLastLoginIp(IpUtils.getHostIp());
|
||||
user.setLastLoginTime(System.currentTimeMillis() / 1000);
|
||||
userMapper.update(user, new QueryWrapper<User>().eq("id", userId));
|
||||
|
||||
// 返回登录信息
|
||||
LoginTokenVo vo = new LoginTokenVo();
|
||||
vo.setId(userId);
|
||||
vo.setIsBindMobile(!mobile.equals(""));
|
||||
vo.setToken(token);
|
||||
vo.setIsBindMobile(!StringUtils.isEmpty(mobile));
|
||||
vo.setToken(StpUtil.getTokenValue());
|
||||
return vo;
|
||||
}
|
||||
|
||||
@@ -433,11 +430,6 @@ public class LoginServiceImpl implements ILoginService {
|
||||
auth.setUnionid(unionId);
|
||||
userAuthMapper.updateById(userAuth);
|
||||
}
|
||||
|
||||
// 更新登录信息
|
||||
user.setLastLoginIp(IpUtils.getHostIp());
|
||||
user.setLastLoginTime(System.currentTimeMillis() / 1000);
|
||||
userMapper.updateById(user);
|
||||
}
|
||||
|
||||
return this.makeLoginToken(userId, user.getMobile());
|
||||
@@ -452,9 +444,9 @@ public class LoginServiceImpl implements ILoginService {
|
||||
private Integer randMakeSn() {
|
||||
Integer sn;
|
||||
while (true) {
|
||||
sn = Integer.parseInt(ToolsUtils.randomInt(8));
|
||||
sn = Integer.parseInt(ToolUtils.randomInt(8));
|
||||
User snModel = userMapper.selectOne(new QueryWrapper<User>()
|
||||
.select("id,sn,username")
|
||||
.select("id,sn")
|
||||
.eq("sn", sn)
|
||||
.last("limit 1"));
|
||||
if (snModel == null) {
|
||||
|
||||
@@ -133,17 +133,17 @@ public class PcServiceImpI implements IPcService {
|
||||
// 登录配置
|
||||
Map<String, Object> loginMap = new LinkedHashMap<>();
|
||||
Map<String, String> loginConfig = ConfigUtils.get("login");
|
||||
loginMap.put("loginWay", ArrayUtils.stringToListAsInt(loginConfig.getOrDefault("loginWay", ""), ","));
|
||||
loginMap.put("loginWay", ListUtils.stringToListAsInt(loginConfig.getOrDefault("loginWay", ""), ","));
|
||||
loginMap.put("forceBindMobile", Integer.parseInt(loginConfig.getOrDefault("forceBindMobile", "0")));
|
||||
loginMap.put("openOtherAuth", Integer.parseInt(loginConfig.getOrDefault("openOtherAuth", "0")));
|
||||
loginMap.put("openAgreement", Integer.parseInt(loginConfig.getOrDefault("openAgreement", "0")));
|
||||
loginMap.put("autoLoginAuth", ArrayUtils.stringToListAsInt(loginConfig.getOrDefault("autoLoginAuth", ""), ","));
|
||||
loginMap.put("autoLoginAuth", ListUtils.stringToListAsInt(loginConfig.getOrDefault("autoLoginAuth", ""), ","));
|
||||
|
||||
// 网址信息
|
||||
Map<String, Object> websiteMap = new LinkedHashMap<>();
|
||||
Map<String, String> websiteConfig = ConfigUtils.get("website");
|
||||
String copyright = websiteConfig.getOrDefault("copyright", "[]");
|
||||
List<Map<String, String>> copyrightMap = ArrayUtils.stringToListAsMapStr(copyright);
|
||||
List<Map<String, String>> copyrightMap = ListUtils.stringToListAsMapStr(copyright);
|
||||
|
||||
websiteMap.put("shopName", websiteConfig.getOrDefault("shopName", "LikeAdmin"));
|
||||
websiteMap.put("shopLogo", UrlUtils.toAbsoluteUrl(websiteConfig.getOrDefault("shopLogo", "")));
|
||||
|
||||
@@ -184,14 +184,14 @@ public class UserServiceImpl implements IUserService {
|
||||
|
||||
if (!user.getPassword().equals("")) {
|
||||
Assert.notNull(oldPassword, "oldPassword参数缺失");
|
||||
String oldPwd = ToolsUtils.makeMd5(oldPassword.trim() + user.getSalt());
|
||||
String oldPwd = ToolUtils.makeMd5(oldPassword.trim() + user.getSalt());
|
||||
if (!oldPwd.equals(user.getPassword())) {
|
||||
throw new OperateException("原密码不正确!");
|
||||
}
|
||||
}
|
||||
|
||||
String salt = ToolsUtils.randomString(5);
|
||||
String pwd = ToolsUtils.makeMd5(password.trim()+salt);
|
||||
String salt = ToolUtils.randomString(5);
|
||||
String pwd = ToolUtils.makeMd5(password.trim()+salt);
|
||||
|
||||
User u = new User();
|
||||
u.setId(userId);
|
||||
|
||||
@@ -65,4 +65,15 @@ mybatis-plus:
|
||||
db-config:
|
||||
table-prefix: la_
|
||||
configuration-properties:
|
||||
prefix: la_
|
||||
prefix: la_
|
||||
|
||||
# Sa-token配置
|
||||
sa-token:
|
||||
token-name: token # token的名称
|
||||
timeout: 2592000 # token有效期单位s(默认30天,-1代表永不过期)
|
||||
activity-timeout: -1 # token临时有效期(指定时间无操作掉线)
|
||||
is-concurrent: true # 是否允许同一账号并发登录
|
||||
is-share: false # 多人同登账号共用token
|
||||
token-style: random-64 # token生成的风格
|
||||
is-print: false # 打印版本字符画
|
||||
is-log: false # 是否输出操作日志
|
||||
Reference in New Issue
Block a user