Commit a06f95be authored by 赵啸非's avatar 赵啸非

修改登录

parent 835b926c
...@@ -346,3 +346,22 @@ CREATE TABLE `mortals_xhx_area` ( ...@@ -346,3 +346,22 @@ CREATE TABLE `mortals_xhx_area` (
`createUserName` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '创建用户名称', `createUserName` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '创建用户名称',
PRIMARY KEY (`id`) USING BTREE PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='区域信息'; ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='区域信息';
CREATE TABLE `mortals_xhx_dept` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID,主键,自增长',
`parentId` bigint(20) DEFAULT NULL COMMENT '父id',
`ancestors` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '祖级列表',
`deptName` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '部门名称',
`deptStatus` tinyint(2) NOT NULL DEFAULT '1' COMMENT '部门状态(0.停用,1.启用)',
`orderNum` int(4) NOT NULL DEFAULT '0' COMMENT '顺序',
`remark` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '备注',
`createUserId` bigint(20) NOT NULL COMMENT '创建用户',
`createTime` datetime NOT NULL COMMENT '创建时间',
`updateUserId` bigint(20) DEFAULT NULL COMMENT '更新用户',
`updateTime` datetime DEFAULT NULL COMMENT '更新时间',
PRIMARY KEY (`id`) USING BTREE,
KEY `deptStatus` (`deptStatus`) USING BTREE,
KEY `orderNum` (`orderNum`) USING BTREE,
KEY `createUserId` (`createUserId`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8 COMMENT='部门信息';
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
NODE_ENV = development NODE_ENV = development
# 地址 # 地址
VUE_APP_BASE_API =http://plm.testnew.com:8082/m VUE_APP_BASE_API =/basics_api
# websocket地址 # websocket地址
VUE_APP_WEBSOCKET_API =127.0.0.1:18222/m VUE_APP_WEBSOCKET_API =127.0.0.1:18222/m
...@@ -10,5 +10,5 @@ VUE_APP_WEBSOCKET_API =127.0.0.1:18222/m ...@@ -10,5 +10,5 @@ VUE_APP_WEBSOCKET_API =127.0.0.1:18222/m
# 门户登录地址 # 门户登录地址
VUE_APP_PORTAL_URL = /portal_home VUE_APP_PORTAL_URL = /portal_home
VUE_APP_PORTAL_PORT = 17300 VUE_APP_PORTAL_PORT = 21080
...@@ -41,6 +41,19 @@ const router = new Router({ ...@@ -41,6 +41,19 @@ const router = new Router({
//模块配置 //模块配置
...restBuilder('dept', 'dept'), ...restBuilder('dept', 'dept'),
...restBuilder('realtime/dataflow', 'realtime/dataflow'),//人员发现
...restBuilder('appointment/records', 'appointment/records'), //预约签到记录表
...restBuilder('care/records', 'care/records'),//预约关怀记录表
...restBuilder('appointment/config', 'appointment/config'), //预约签到配置
...restBuilder('appointment/config/times', 'appointment/config/times'), //预约自动签到配置时间段
...restBuilder('care/config', 'care/config'), //主动关怀配置
...restBuilder('care/config/times', 'care/config/times'), //主动关怀时间段
...restBuilder('appointment/constraint', 'appointment/constraint'), //预约自动签到服务约束
...restBuilder('care/constraint', 'care/constraint'), //主动关怀服务约束
...restBuilder('care/constraint/track', 'care/constraint/track'), //主动关怀服务追踪
...restBuilder('care/constraint/track', 'care/constraint/track'), //主动关怀服务追踪
...restBuilder('person', 'person'), //注册人员
...restBuilder('device', 'device'), //设备业务
//以下为基础路由配置 //以下为基础路由配置
......
...@@ -17,7 +17,7 @@ module.exports = { ...@@ -17,7 +17,7 @@ module.exports = {
hot: true,//自动保存 hot: true,//自动保存
proxy: { proxy: {
'/refined': { '/refined': {
target: 'http://127.0.0.1:17400', target: 'http://127.0.0.1:21080',
changeOrigin: true, changeOrigin: true,
secure: false, secure: false,
cookieDomainRewrite: 'localhost', cookieDomainRewrite: 'localhost',
......
{
"name": "study-manager-ui",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"dependencies": {
"jwt-decode": "^3.1.2"
}
},
"node_modules/jwt-decode": {
"version": "3.1.2",
"resolved": "https://registry.npmmirror.com/jwt-decode/-/jwt-decode-3.1.2.tgz",
"integrity": "sha512-UfpWE/VZn0iP50d8cz9NrZLM9lSWhcJ+0Gt/nm4by88UL+J1SiKN8/5dkjMmbEzwL2CAe+67GsegCbIKtbp75A=="
}
},
"dependencies": {
"jwt-decode": {
"version": "3.1.2",
"resolved": "https://registry.npmmirror.com/jwt-decode/-/jwt-decode-3.1.2.tgz",
"integrity": "sha512-UfpWE/VZn0iP50d8cz9NrZLM9lSWhcJ+0Gt/nm4by88UL+J1SiKN8/5dkjMmbEzwL2CAe+67GsegCbIKtbp75A=="
}
}
}
{
"dependencies": {
"jwt-decode": "^3.1.2"
}
}
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
"jwt-decode@^3.1.2":
"integrity" "sha512-UfpWE/VZn0iP50d8cz9NrZLM9lSWhcJ+0Gt/nm4by88UL+J1SiKN8/5dkjMmbEzwL2CAe+67GsegCbIKtbp75A=="
"resolved" "https://registry.npmmirror.com/jwt-decode/-/jwt-decode-3.1.2.tgz"
"version" "3.1.2"
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
</activation> </activation>
<properties> <properties>
<profiles.active>develop</profiles.active> <profiles.active>develop</profiles.active>
<profiles.platform.type>standalone</profiles.platform.type>
<profiles.server.port>21080</profiles.server.port> <profiles.server.port>21080</profiles.server.port>
<profiles.server.path>/refined</profiles.server.path> <profiles.server.path>/refined</profiles.server.path>
<profiles.nacos.server-addr>127.0.0.1:8848</profiles.nacos.server-addr> <profiles.nacos.server-addr>127.0.0.1:8848</profiles.nacos.server-addr>
...@@ -38,6 +39,7 @@ ...@@ -38,6 +39,7 @@
<id>test</id> <id>test</id>
<properties> <properties>
<profiles.active>test</profiles.active> <profiles.active>test</profiles.active>
<profiles.platform.type>cloud</profiles.platform.type>
<profiles.server.port>21080</profiles.server.port> <profiles.server.port>21080</profiles.server.port>
<profiles.server.path>/refined</profiles.server.path> <profiles.server.path>/refined</profiles.server.path>
<profiles.publish.path>/home/publish</profiles.publish.path> <profiles.publish.path>/home/publish</profiles.publish.path>
......
...@@ -27,6 +27,7 @@ import lombok.extern.slf4j.Slf4j; ...@@ -27,6 +27,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -43,6 +44,7 @@ import static com.mortals.xhx.common.key.ErrorCode.ERROR_TOKEN_EXPIRED_CONTENT; ...@@ -43,6 +44,7 @@ import static com.mortals.xhx.common.key.ErrorCode.ERROR_TOKEN_EXPIRED_CONTENT;
@RestController @RestController
@Slf4j @Slf4j
@RequestMapping("login") @RequestMapping("login")
@ConditionalOnExpression("'${platform.type:null}'=='cloud'")
public class LoginController extends BaseCRUDJsonBodyMappingController<UserService, UserEntity, Long> { public class LoginController extends BaseCRUDJsonBodyMappingController<UserService, UserEntity, Long> {
@Autowired @Autowired
......
package com.mortals.xhx.base.login.web;
import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.ap.CookieService;
import com.mortals.framework.ap.GlobalSysInfo;
import com.mortals.framework.ap.SysConstains;
import com.mortals.framework.common.Rest;
import com.mortals.framework.service.IAuthTokenService;
import com.mortals.framework.service.ICacheService;
import com.mortals.framework.service.IUser;
import com.mortals.framework.util.AESUtil;
import com.mortals.framework.util.DateUtils;
import com.mortals.framework.util.HttpUtil;
import com.mortals.framework.util.StringUtils;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.menu.model.MenuEntity;
import com.mortals.xhx.base.system.menu.service.MenuService;
import com.mortals.xhx.base.system.resource.service.ResourceService;
import com.mortals.xhx.base.system.user.model.UserEntity;
import com.mortals.xhx.base.system.user.service.UserService;
import com.mortals.xhx.base.system.valid.service.ValidCodeService;
import com.mortals.xhx.common.key.RedisKey;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Set;
import static com.mortals.xhx.common.key.ErrorCode.ERROR_TOKEN_EXPIRED;
import static com.mortals.xhx.common.key.ErrorCode.ERROR_TOKEN_EXPIRED_CONTENT;
@RestController
@Slf4j
@RequestMapping("login")
@ConditionalOnExpression("'${platform.type:standalone}'=='standalone'")
public class StandaloneLoginController extends BaseCRUDJsonBodyMappingController<UserService, UserEntity, Long> implements InitializingBean {
@Autowired
private UserService userService;
@Autowired
private ValidCodeService validCodeService;
@Autowired
private ResourceService resourceService;
@Autowired
private MenuService menuService;
@Autowired
private ICacheService cacheService;
@Autowired
private IAuthTokenService authTokenService;
@RequestMapping("login")
public String login(@RequestBody LoginForm loginForm) throws Exception {
JSONObject ret = new JSONObject();
String loginName = loginForm.getLoginName();
String password = loginForm.getPassword();
String ip = super.getRequestIP(request);
if (StringUtils.isEmpty(loginName) || StringUtils.isEmpty(password)) {
ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
ret.put(KEY_RESULT_MSG, "未获取到用户信息,请重新登录");
return ret.toJSONString();
}
UserEntity userEntity = null;
try {
loginForm.validate();
userEntity = userService.doLogin(loginName, password, ip);
userEntity.setLastLoginAddress(ip);
recordSysLog(request, userEntity, "用户登录系统成功!");
// 返回拥有的菜单数据
Set<String> urls = resourceService.findUrlSetByUserId(userEntity.getId());
List<MenuEntity> outlookBarList = menuService.findTreeMenu(userEntity, urls);
String currUserName = userEntity.getRealName();
if (currUserName == null || currUserName.trim().length() == 0) {
currUserName = "管理员";
}
JSONObject data = new JSONObject();
data.put("currUserName", currUserName);
data.put("barList", outlookBarList);
data.put("id", userEntity.getId());
data.put("userType", userEntity.getUserType());
userEntity.setLoginTime(System.currentTimeMillis());
userEntity.setToken(IdUtil.fastSimpleUUID());
userEntity.setExpireTime(DateUtils.addCurrDate(7).getTime());
userEntity.setMenuUrl(generateMenuUrlCode(urls));
String token = authTokenService.createToken(userEntity);
data.put("token", token);
//设置token 和过期时间
//data.put("expiresTime", DateUtils.addCurrDate(7).getTime());
generateMenuUrlCode(urls);
//this.generateBlackCookie(request, response, loginName, urls);
ret.put(KEY_RESULT_DATA, data);
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
ret.put(KEY_RESULT_MSG, "用户登录系统成功!");
ret.put("resources", urls);
return ret.toJSONString();
} catch (Exception e) {
log.error("login error ", e);
if (userEntity == null) {
userEntity = new UserEntity();
userEntity.setLoginName(loginName);
}
ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
ret.put(KEY_RESULT_MSG, super.convertException(e));
return ret.toJSONString();
}
}
@RequestMapping("logout")
public void logout(HttpServletRequest request, HttpServletResponse response) throws Exception {
recordSysLog(request, "退出登录");
super.removeCurrUser(request);
this.deleteBlackCookie(request, response);
}
@RequestMapping("index")
public String index() throws Exception {
JSONObject ret = new JSONObject();
IUser user = this.getCurUser();
if (user == null) {
return JSONObject.toJSONString(Rest.fail(ERROR_TOKEN_EXPIRED, ERROR_TOKEN_EXPIRED_CONTENT));
}
Set<String> urls = resourceService.findUrlSetByUserId(user.getId());
List<MenuEntity> outlookBarList = menuService.findTreeMenu(user, urls);
String currUserName = user.getRealName();
if (currUserName == null || currUserName.trim().length() == 0) {
currUserName = "管理员";
}
JSONObject data = new JSONObject();
String token = authTokenService.getToken(request);
data.put("token", token);
data.put("currUserName", currUserName);
data.put("barList", outlookBarList);
data.put("id", user.getId());
data.put("userType", user.getUserType());
ret.put(KEY_RESULT_DATA, data);
//this.generateBlackCookie(request, response, user.getLoginName(), urls);
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
ret.put(KEY_RESULT_MSG, "用户登录系统成功!");
ret.put("resources", urls);
return ret.toJSONString();
}
private void generateBlackCookie(HttpServletRequest request, HttpServletResponse response, String loginName, Set<String> urls) {
try {
String cacheKey = RedisKey.KEY_MENU_CACHE + loginName;
String securityKey = GlobalSysInfo.getPropertyValue(SysConstains.PROP_COOKIE_SECURITY_KEY);
//应为Cookie会超长,所以改为仅存储key将值放入redis
//CookieService.setCookieForAuth(request, response, securityKey, null);
StringBuilder sb = new StringBuilder();
if (urls != null && urls.size() > 0) {
for (String url : urls) {
int index = url.hashCode() & (Integer.MAX_VALUE - 1);
sb.append(index).append(",");
}
}
String menuUrl = sb.toString();
menuUrl = AESUtil.encrypt(menuUrl, securityKey);
cacheService.set(cacheKey, menuUrl, 604800);
HttpUtil.setCookieValue(request, response, SysConstains.COOKIE_MENU, cacheKey, -1);
} catch (Throwable e) {
}
}
private String generateMenuUrlCode(Set<String> urls) {
try {
String securityKey = GlobalSysInfo.getPropertyValue(SysConstains.PROP_COOKIE_SECURITY_KEY);
StringBuilder sb = new StringBuilder();
if (urls != null && urls.size() > 0) {
for (String url : urls) {
int index = url.hashCode() & (Integer.MAX_VALUE - 1);
sb.append(index).append(",");
}
}
String menuUrl = sb.toString();
return AESUtil.encrypt(menuUrl, securityKey);
} catch (Throwable e) {
log.error("编码异常", e);
return null;
}
}
@RequestMapping("validcode")
public String validCode(HttpServletRequest request, HttpServletResponse response, LoginForm loginForm) {
JSONObject ret = new JSONObject();
String loginName = loginForm.getLoginName();
String password = loginForm.getPassword();
if (StringUtils.isEmpty(loginName) || StringUtils.isEmpty(password)) {
ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
ret.put(KEY_RESULT_MSG, "登录名或密码为空");
}
UserEntity user = null;
try {
user = userService.doCheckUser(loginName, password);
if (user == null) {
ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
ret.put(KEY_RESULT_MSG, "用户名或密码不正确");
} else if (StringUtils.isEmpty(user.getMobile())) {
ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
ret.put(KEY_RESULT_MSG, "用户无正确的手机号");
} else {
String mobile = StringUtils.trim(user.getMobile());
String sessionId = request.getSession().getId();
String ip = super.getRequestIP(request);
boolean result = validCodeService.createSmsValidCode(sessionId, ip, mobile);
if (result) {
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
} else {
ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
ret.put(KEY_RESULT_MSG, "验证码发送失败,请稍后在试!");
}
}
} catch (Exception e) {
ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
ret.put(KEY_RESULT_MSG, "验证码发送失败:" + super.convertException(e));
} finally {
if (user == null) {
user = new UserEntity();
user.setLoginName(loginName);
}
recordSysLog(request, user, "用户获取短信验证码");
}
return ret.toJSONString();
}
protected void deleteBlackCookie(HttpServletRequest request, HttpServletResponse response) {
try {
CookieService.deleteCookieForAuth(request, response);
} catch (Throwable e) {
}
}
@RequestMapping("parseToken")
public IUser parseToken() throws Exception {
IUser userEntity = authTokenService.getLoginUser(request);
if (!ObjectUtils.isEmpty(userEntity)) {
authTokenService.verifyToken(userEntity);
return userEntity;
}
return null;
}
@Override
public void afterPropertiesSet() throws Exception {
log.info("初始化加载单机版登录。。。");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment