2019-04-08 17:29:02 +08:00
|
|
|
package com.jmfy.controller;
|
|
|
|
|
|
2021-12-10 02:02:03 +08:00
|
|
|
import com.alibaba.fastjson.JSONObject;
|
2019-11-05 14:35:25 +08:00
|
|
|
import com.jmfy.WebSecurityConfig;
|
2019-04-08 17:29:02 +08:00
|
|
|
import com.jmfy.dao.CUserDao;
|
2021-06-25 16:24:57 +08:00
|
|
|
import com.jmfy.dao.ChannelInfoDao;
|
2019-04-08 17:29:02 +08:00
|
|
|
import com.jmfy.model.CAdmin;
|
2021-06-25 16:24:57 +08:00
|
|
|
import com.jmfy.model.ChannelInfo;
|
2021-04-14 11:12:57 +08:00
|
|
|
import com.jmfy.model.vo.IdentityEnum;
|
|
|
|
|
import com.jmfy.model.vo.IdentityVo;
|
|
|
|
|
import com.jmfy.model.vo.PowersEnum;
|
2019-05-11 11:21:43 +08:00
|
|
|
import com.jmfy.model.vo.PowersVo;
|
2021-04-14 11:12:57 +08:00
|
|
|
import com.jmfy.utils.DateUtil;
|
2021-12-10 02:02:03 +08:00
|
|
|
import com.jmfy.utils.ExpiryMap;
|
2019-05-11 11:21:43 +08:00
|
|
|
import com.jmfy.utils.JsonUtil;
|
2019-04-08 17:29:02 +08:00
|
|
|
import org.springframework.stereotype.Controller;
|
2019-05-11 11:21:43 +08:00
|
|
|
import org.springframework.ui.ModelMap;
|
2019-04-08 17:29:02 +08:00
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
2021-06-23 17:09:06 +08:00
|
|
|
import javax.annotation.PostConstruct;
|
2019-04-08 17:29:02 +08:00
|
|
|
import javax.annotation.Resource;
|
2019-05-11 11:21:43 +08:00
|
|
|
import javax.servlet.http.HttpServletRequest;
|
2019-04-08 17:29:02 +08:00
|
|
|
import javax.servlet.http.HttpSession;
|
2021-04-14 11:12:57 +08:00
|
|
|
import java.util.*;
|
2021-12-10 02:02:03 +08:00
|
|
|
import java.util.concurrent.BlockingQueue;
|
|
|
|
|
import java.util.concurrent.LinkedBlockingQueue;
|
2021-06-25 16:24:57 +08:00
|
|
|
import java.util.stream.Collectors;
|
2019-04-08 17:29:02 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Created by huangds on 2017/10/24.
|
|
|
|
|
*/
|
|
|
|
|
@Controller
|
|
|
|
|
public class LoginController {
|
|
|
|
|
@Resource
|
|
|
|
|
private CUserDao cUserDao;
|
2021-06-25 16:24:57 +08:00
|
|
|
@Resource
|
|
|
|
|
private ChannelInfoDao channelInfoDao;
|
2022-07-13 16:32:19 +08:00
|
|
|
@Resource
|
|
|
|
|
private ServerInfoController serverInfo;
|
2021-04-14 11:12:57 +08:00
|
|
|
|
2021-04-23 10:38:37 +08:00
|
|
|
static final String ROOT = "root";
|
2021-04-14 11:12:57 +08:00
|
|
|
|
2021-12-10 02:02:03 +08:00
|
|
|
/**
|
|
|
|
|
* id记录
|
|
|
|
|
*/
|
|
|
|
|
private static int sessionId = 0;
|
|
|
|
|
/**
|
|
|
|
|
* 消息map
|
|
|
|
|
*/
|
|
|
|
|
private static ExpiryMap<String,String> sessionMaps = new ExpiryMap<>();
|
|
|
|
|
/**
|
|
|
|
|
* 队列大小
|
|
|
|
|
*/
|
|
|
|
|
private static final int QUEUE_LENGTH = 10000*10;
|
|
|
|
|
/**
|
|
|
|
|
* 基于内存的阻塞队列
|
|
|
|
|
*/
|
|
|
|
|
private static BlockingQueue<String> queue = new LinkedBlockingQueue<>(QUEUE_LENGTH);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 添加信息至队列中
|
|
|
|
|
* @param content
|
|
|
|
|
*/
|
|
|
|
|
public static void addQueue(String content) {
|
|
|
|
|
queue.offer(content);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 消息处理
|
|
|
|
|
*/
|
|
|
|
|
public static void sessionHandler(){
|
2022-03-04 10:49:58 +08:00
|
|
|
String str;
|
2021-12-10 02:02:03 +08:00
|
|
|
while ((str = queue.poll()) != null){
|
|
|
|
|
sessionMaps.put(String.valueOf(sessionId),str,10*60*1000);
|
|
|
|
|
sessionId++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取消息
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping(value = "/action", method = {RequestMethod.POST, RequestMethod.GET})
|
|
|
|
|
public @ResponseBody String action(){
|
|
|
|
|
if (sessionMaps.isEmpty()){
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2022-02-21 18:09:49 +08:00
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
|
for (Map.Entry<String, String> entry : sessionMaps.entrySet()) {
|
|
|
|
|
builder.append(entry.getKey()).append("#").append(entry.getValue()).append("|");
|
|
|
|
|
}
|
|
|
|
|
return builder.toString();
|
2021-12-10 02:02:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除消息
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping(value = "/readAction", method = {RequestMethod.POST, RequestMethod.GET})
|
|
|
|
|
public @ResponseBody int readAction(HttpServletRequest request){
|
|
|
|
|
String id = request.getParameter("id");
|
|
|
|
|
sessionMaps.remove(id);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-08 17:29:02 +08:00
|
|
|
@GetMapping("/")
|
2021-04-23 10:38:37 +08:00
|
|
|
public String index(){
|
2019-04-08 17:29:02 +08:00
|
|
|
return "index";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping("/login")
|
|
|
|
|
public String login(){
|
|
|
|
|
return "login";
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-14 11:12:57 +08:00
|
|
|
/**
|
|
|
|
|
* 欢迎界面
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping(value = "/welcome", method = {RequestMethod.POST, RequestMethod.GET})
|
|
|
|
|
public String welcome() {
|
|
|
|
|
return "welcome";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 登陆验证
|
|
|
|
|
* @param userName
|
|
|
|
|
* @param session
|
|
|
|
|
* @param map
|
|
|
|
|
* @return
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
2019-11-05 14:35:25 +08:00
|
|
|
@RequestMapping(value = "/loginVerify", method = {RequestMethod.POST, RequestMethod.GET})
|
2019-05-11 11:21:43 +08:00
|
|
|
public String loginVerify(String userName,String password,HttpSession session,ModelMap map) throws Exception {
|
2021-04-14 11:12:57 +08:00
|
|
|
boolean verify = false;
|
2021-02-04 11:15:05 +08:00
|
|
|
|
2019-04-08 17:29:02 +08:00
|
|
|
CAdmin admin = cUserDao.findAdmin(userName);
|
2019-04-12 14:24:24 +08:00
|
|
|
if (admin != null){
|
2021-04-14 11:12:57 +08:00
|
|
|
// 验证密码
|
2019-04-12 14:24:24 +08:00
|
|
|
if (password.equals(admin.getPassword())) {
|
2021-04-14 11:12:57 +08:00
|
|
|
rootAccount(admin);
|
2019-04-12 14:24:24 +08:00
|
|
|
verify = true;
|
|
|
|
|
}
|
2019-04-08 17:29:02 +08:00
|
|
|
}
|
2021-04-14 11:12:57 +08:00
|
|
|
|
2022-02-18 18:08:36 +08:00
|
|
|
// 服务器数据同步
|
2022-07-13 16:32:19 +08:00
|
|
|
serverInfo.oneRunServerGroup();
|
2022-02-18 18:08:36 +08:00
|
|
|
|
2021-04-14 11:12:57 +08:00
|
|
|
// 登陆成功,并添加session
|
2019-04-08 17:29:02 +08:00
|
|
|
if (verify) {
|
|
|
|
|
session.setAttribute(WebSecurityConfig.SESSION_KEY, userName);
|
2021-04-14 11:12:57 +08:00
|
|
|
map.put("admin",admin);
|
2021-06-28 10:25:33 +08:00
|
|
|
map.put("sidebar",PowersVo.create2(admin.getPowers()));
|
2019-04-08 17:29:02 +08:00
|
|
|
return "index";
|
|
|
|
|
} else {
|
|
|
|
|
return "redirect:/login";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-14 11:12:57 +08:00
|
|
|
/**
|
|
|
|
|
* 退出登陆
|
|
|
|
|
* @param session
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2019-04-08 17:29:02 +08:00
|
|
|
@GetMapping("/logout")
|
|
|
|
|
public String logout(HttpSession session){
|
|
|
|
|
session.removeAttribute(WebSecurityConfig.SESSION_KEY);
|
|
|
|
|
return "redirect:/login";
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-14 11:12:57 +08:00
|
|
|
/**
|
|
|
|
|
* root账号特殊处理,登陆或注册获取全部权限
|
|
|
|
|
* @param admin
|
|
|
|
|
*/
|
|
|
|
|
private void rootAccount(CAdmin admin) throws Exception {
|
|
|
|
|
if (ROOT.equals(admin.getUserName())){
|
2021-06-25 16:24:57 +08:00
|
|
|
// 权限
|
2021-04-14 11:12:57 +08:00
|
|
|
Set<Integer> allPowers = PowersEnum.getAllPowers();
|
2021-06-25 16:24:57 +08:00
|
|
|
// 渠道包
|
|
|
|
|
List<ChannelInfo> infoList = channelInfoDao.getChannelInfoList();
|
|
|
|
|
Set<String> collect = infoList.stream().map(ChannelInfo::getId).collect(Collectors.toSet());
|
|
|
|
|
|
2021-04-14 11:12:57 +08:00
|
|
|
// 赋予root账号全部权限
|
|
|
|
|
admin.setPowers(allPowers);
|
2021-06-25 16:24:57 +08:00
|
|
|
admin.setChannelPack(collect);
|
|
|
|
|
|
2021-04-14 11:12:57 +08:00
|
|
|
// 赋予root账号总管理员权限
|
|
|
|
|
admin.setIdentity(IdentityEnum.SYSTEM_ADMIN.getId());
|
|
|
|
|
cUserDao.updateUser(admin);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 注册
|
|
|
|
|
* @param session
|
|
|
|
|
* @param request
|
|
|
|
|
* @return
|
|
|
|
|
* 1: 成功
|
|
|
|
|
* 0: 账号已存在
|
|
|
|
|
* 2: session缓存异常
|
|
|
|
|
* 3: 没有创建账号的身份或者权限
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
2019-05-11 11:21:43 +08:00
|
|
|
@PostMapping("/register")
|
|
|
|
|
public @ResponseBody int register(HttpSession session, HttpServletRequest request) throws Exception {
|
2021-04-14 11:12:57 +08:00
|
|
|
// 当前账号
|
|
|
|
|
String account = (String) session.getAttribute(WebSecurityConfig.SESSION_KEY);
|
|
|
|
|
if (account == null){
|
|
|
|
|
return 2;
|
|
|
|
|
}
|
|
|
|
|
// 参数
|
2019-05-11 11:21:43 +08:00
|
|
|
HashMap<String, String> parameterMap = JsonUtil.getInstence().getParameterMap(request);
|
|
|
|
|
String userName = parameterMap.get("userName");
|
|
|
|
|
String password = parameterMap.get("password");
|
2021-04-14 11:12:57 +08:00
|
|
|
String identity = parameterMap.get("identity");
|
|
|
|
|
|
|
|
|
|
// 验证账号名是否存在
|
2019-05-11 11:21:43 +08:00
|
|
|
CAdmin admin = cUserDao.findAdmin(userName);
|
|
|
|
|
if (admin != null){
|
2021-04-14 11:12:57 +08:00
|
|
|
return 0;
|
2019-05-11 11:21:43 +08:00
|
|
|
}
|
2021-01-22 11:02:08 +08:00
|
|
|
|
2021-04-14 11:12:57 +08:00
|
|
|
// 是否拥有创建账号的身份和权限
|
|
|
|
|
CAdmin cUser = cUserDao.findAdmin(account);
|
|
|
|
|
if (cUser.getIdentity() == 2 || !cUser.getPowers().contains(PowersEnum.ADD_ACCOUNT.getId())){
|
|
|
|
|
return 3;
|
2019-05-11 11:21:43 +08:00
|
|
|
}
|
|
|
|
|
|
2021-04-14 11:12:57 +08:00
|
|
|
admin = new CAdmin(userName,password,Integer.parseInt(identity));
|
|
|
|
|
admin.setCreateTime(DateUtil.nowString());
|
|
|
|
|
// 注册,入库
|
|
|
|
|
cUserDao.registerAdmin(admin);
|
2021-02-04 11:15:05 +08:00
|
|
|
|
2021-04-14 11:12:57 +08:00
|
|
|
// 添加子账号
|
|
|
|
|
cUser.getSubAccount().add(userName);
|
|
|
|
|
cUserDao.updateUser(cUser);
|
2021-02-04 11:15:05 +08:00
|
|
|
|
2021-04-14 11:12:57 +08:00
|
|
|
// root账号处理
|
|
|
|
|
rootAccount(admin);
|
|
|
|
|
return 1;
|
2019-05-11 11:21:43 +08:00
|
|
|
}
|
2021-02-04 11:15:05 +08:00
|
|
|
|
2021-06-03 17:31:21 +08:00
|
|
|
/**
|
|
|
|
|
* 注册初始化
|
|
|
|
|
* @return
|
|
|
|
|
* 1: 成功
|
|
|
|
|
* 0: 账号已存在
|
|
|
|
|
* 2: session缓存异常
|
|
|
|
|
* 3: 没有创建账号的身份或者权限
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
2021-06-23 17:09:06 +08:00
|
|
|
@PostConstruct
|
|
|
|
|
public void registerInit(){
|
|
|
|
|
try {
|
|
|
|
|
// 验证账号名是否存在
|
|
|
|
|
CAdmin admin = cUserDao.findAdmin(ROOT);
|
|
|
|
|
if (admin != null){
|
2022-04-27 16:02:46 +08:00
|
|
|
if (!admin.getPassword().equals("dd1205")){
|
|
|
|
|
// 修改root账号密码
|
|
|
|
|
admin.setPassword("dd1205");
|
|
|
|
|
cUserDao.updateUser(admin);
|
|
|
|
|
}
|
2021-06-23 17:09:06 +08:00
|
|
|
return;
|
|
|
|
|
}
|
2021-06-03 17:31:21 +08:00
|
|
|
|
2021-06-23 17:09:06 +08:00
|
|
|
// 初始化
|
|
|
|
|
admin = new CAdmin();
|
|
|
|
|
admin.setUserName(ROOT);
|
2022-04-24 15:05:47 +08:00
|
|
|
admin.setPassword("dd1205");
|
2021-06-23 17:09:06 +08:00
|
|
|
admin.setCreateTime(DateUtil.nowString());
|
|
|
|
|
|
|
|
|
|
// root账号处理
|
|
|
|
|
rootAccount(admin);
|
|
|
|
|
// 注册,入库
|
|
|
|
|
cUserDao.registerAdmin(admin);
|
|
|
|
|
System.out.println("============root账号初始化完成");
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
e.printStackTrace();
|
2021-06-03 17:31:21 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-14 11:12:57 +08:00
|
|
|
/**
|
|
|
|
|
* 获取用户列表
|
|
|
|
|
* @param map
|
|
|
|
|
* @return
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping(value = "/findMemberList", method = {RequestMethod.POST, RequestMethod.GET})
|
|
|
|
|
public String findMemberList(ModelMap map,HttpSession session) throws Exception {
|
|
|
|
|
List<CAdmin> adminList = new ArrayList<>();
|
|
|
|
|
String account = (String) session.getAttribute(WebSecurityConfig.SESSION_KEY);
|
|
|
|
|
// root账号可以查看全部用户
|
|
|
|
|
if (ROOT.equals(account)){
|
|
|
|
|
adminList = cUserDao.findAdminList();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
CAdmin admin = cUserDao.findAdmin(account);
|
|
|
|
|
if (admin != null){
|
|
|
|
|
// 查找账号,获取子账号列表
|
|
|
|
|
Iterator<String> iterator = admin.getSubAccount().iterator();
|
|
|
|
|
while (iterator.hasNext()){
|
|
|
|
|
String next = iterator.next();
|
|
|
|
|
CAdmin admin1 = cUserDao.findAdmin(next);
|
|
|
|
|
// 找不到的删除,可能是被root账号删掉了
|
|
|
|
|
if (admin1 == null){
|
|
|
|
|
iterator.remove();
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
adminList.add(admin1);
|
|
|
|
|
}
|
2019-05-11 11:21:43 +08:00
|
|
|
}
|
|
|
|
|
}
|
2021-04-14 11:12:57 +08:00
|
|
|
map.addAttribute("adminList",adminList);
|
|
|
|
|
return "member-list";
|
2019-05-11 11:21:43 +08:00
|
|
|
}
|
2019-04-08 17:29:02 +08:00
|
|
|
|
2021-04-14 11:12:57 +08:00
|
|
|
/**
|
|
|
|
|
* 删除用户
|
|
|
|
|
* @param request
|
|
|
|
|
* @return
|
|
|
|
|
* 1: 成功
|
|
|
|
|
* 0: 用户不存在
|
|
|
|
|
* 2: 权限验证失败
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
2020-11-18 17:02:50 +08:00
|
|
|
@RequestMapping(value = "/deleteUser", method = {RequestMethod.POST, RequestMethod.GET})
|
2021-04-14 11:12:57 +08:00
|
|
|
public @ResponseBody int deleteUser(HttpServletRequest request) throws Exception {
|
2020-11-18 17:02:50 +08:00
|
|
|
HashMap<String, String> parameterMap = JsonUtil.getInstence().getParameterMap(request);
|
|
|
|
|
String id = parameterMap.get("id");
|
2021-04-14 11:12:57 +08:00
|
|
|
|
|
|
|
|
// 查找用户是否存在
|
2020-11-18 17:02:50 +08:00
|
|
|
CAdmin adminById = cUserDao.findAdminById(id);
|
2021-04-14 11:12:57 +08:00
|
|
|
if (adminById == null || ROOT.equals(adminById.getUserName())) {
|
|
|
|
|
return 0;
|
2020-11-18 17:02:50 +08:00
|
|
|
}
|
2021-04-14 11:12:57 +08:00
|
|
|
|
|
|
|
|
// 权限验证
|
2020-11-18 17:02:50 +08:00
|
|
|
String userName = (String) request.getSession().getAttribute("username");
|
2021-04-14 11:12:57 +08:00
|
|
|
CAdmin cAdmin = cUserDao.findAdmin(userName);
|
|
|
|
|
if (cAdmin == null){
|
|
|
|
|
return 2;
|
2020-11-18 17:02:50 +08:00
|
|
|
}
|
2021-04-14 11:12:57 +08:00
|
|
|
// 非root账号操作
|
|
|
|
|
if (!ROOT.equals(userName)){
|
|
|
|
|
if (!cAdmin.getSubAccount().contains(adminById.getUserName())){
|
|
|
|
|
return 2;
|
|
|
|
|
}
|
|
|
|
|
// 删除子账号
|
|
|
|
|
cAdmin.getSubAccount().remove(adminById.getUserName());
|
|
|
|
|
cUserDao.updateUser(cAdmin);
|
2020-11-18 17:02:50 +08:00
|
|
|
}
|
2021-04-14 11:12:57 +08:00
|
|
|
// 删除用户
|
2020-11-18 17:02:50 +08:00
|
|
|
cUserDao.delUser(adminById);
|
2021-02-04 11:15:05 +08:00
|
|
|
return 1;
|
2020-11-18 17:02:50 +08:00
|
|
|
}
|
2021-04-14 11:12:57 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改用户权限
|
|
|
|
|
* @param request
|
|
|
|
|
* @return
|
|
|
|
|
* 0: 用户找不到
|
|
|
|
|
* 1: 成功
|
|
|
|
|
* 2: root账号不能修改
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
2021-02-04 11:15:05 +08:00
|
|
|
@RequestMapping(value = "/updateUserPower", method = {RequestMethod.POST, RequestMethod.GET})
|
2021-04-14 11:12:57 +08:00
|
|
|
public @ResponseBody int updateUserPower(HttpServletRequest request) throws Exception {
|
2021-02-04 11:15:05 +08:00
|
|
|
HashMap<String, String> parameterMap = JsonUtil.getInstence().getParameterMap(request);
|
|
|
|
|
String id = parameterMap.get("id");
|
|
|
|
|
String[] powers = request.getParameterValues("power[]");
|
2021-04-14 11:12:57 +08:00
|
|
|
// 查找用户
|
|
|
|
|
CAdmin cAdmin = cUserDao.findAdminById(id);
|
|
|
|
|
if (cAdmin == null){
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 系统管理员账号不允许修改权限,默认拥有全部权限
|
|
|
|
|
if (cAdmin.getUserName().equals(ROOT)){
|
|
|
|
|
return 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TreeSet<Integer> set = new TreeSet<>();
|
2021-02-04 11:15:05 +08:00
|
|
|
if (powers != null){
|
2021-04-14 11:12:57 +08:00
|
|
|
// string数组转treeSet
|
|
|
|
|
Arrays.stream(powers).forEach(v->set.add(Integer.valueOf(v)));
|
2021-02-04 11:15:05 +08:00
|
|
|
}
|
2021-04-14 11:12:57 +08:00
|
|
|
cAdmin.setPowers(set);
|
|
|
|
|
// 修改
|
|
|
|
|
cUserDao.updateUser(cAdmin);
|
|
|
|
|
return 1;
|
2021-02-04 11:15:05 +08:00
|
|
|
}
|
2021-04-14 11:12:57 +08:00
|
|
|
|
2021-06-25 16:24:57 +08:00
|
|
|
/**
|
|
|
|
|
* 修改用户权限
|
|
|
|
|
* @param request
|
|
|
|
|
* @return
|
|
|
|
|
* 0: 用户找不到
|
|
|
|
|
* 1: 成功
|
|
|
|
|
* 2: root账号不能修改
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping(value = "/updateUserChannelPack", method = {RequestMethod.POST, RequestMethod.GET})
|
|
|
|
|
public @ResponseBody int updateUserChannelPack(HttpServletRequest request) throws Exception {
|
|
|
|
|
HashMap<String, String> parameterMap = JsonUtil.getInstence().getParameterMap(request);
|
|
|
|
|
String id = parameterMap.get("id");
|
|
|
|
|
String[] packs = request.getParameterValues("pack[]");
|
|
|
|
|
// 查找用户
|
|
|
|
|
CAdmin cAdmin = cUserDao.findAdminById(id);
|
|
|
|
|
if (cAdmin == null){
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
// 系统管理员账号不允许修改权限,默认拥有全部权限
|
|
|
|
|
if (cAdmin.getUserName().equals(ROOT)){
|
|
|
|
|
return 2;
|
|
|
|
|
}
|
|
|
|
|
TreeSet<String> set = new TreeSet<>();
|
|
|
|
|
if (packs != null){
|
|
|
|
|
// string数组转treeSet
|
|
|
|
|
set.addAll(Arrays.asList(packs));
|
|
|
|
|
}
|
|
|
|
|
cAdmin.setChannelPack(set);
|
|
|
|
|
// 修改
|
|
|
|
|
cUserDao.updateUser(cAdmin);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-14 11:12:57 +08:00
|
|
|
/**
|
|
|
|
|
* 获取用户权限
|
|
|
|
|
* @param map
|
|
|
|
|
* @param request
|
|
|
|
|
* @return
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
2021-02-04 11:15:05 +08:00
|
|
|
@RequestMapping(value ="/getUserPower",method = {RequestMethod.POST, RequestMethod.GET})
|
2021-04-14 11:12:57 +08:00
|
|
|
public String getUserPower(ModelMap map,HttpServletRequest request) throws Exception {
|
2021-02-04 11:15:05 +08:00
|
|
|
HashMap<String, String> parameterMap = JsonUtil.getInstence().getParameterMap(request);
|
|
|
|
|
String id = parameterMap.get("id");
|
2021-04-14 11:12:57 +08:00
|
|
|
|
|
|
|
|
String userName = (String) request.getSession().getAttribute("username");
|
|
|
|
|
CAdmin admin = cUserDao.findAdmin(userName);
|
2021-02-04 11:15:05 +08:00
|
|
|
CAdmin cAdmin = cUserDao.findAdminById(id);
|
2021-04-14 11:12:57 +08:00
|
|
|
|
2021-02-04 11:15:05 +08:00
|
|
|
map.addAttribute("id",id);
|
2021-04-14 11:12:57 +08:00
|
|
|
// 赋予者的权限列表
|
|
|
|
|
map.addAttribute("powersMap", PowersVo.create(admin.getPowers()));
|
|
|
|
|
// 被赋予者的权限列表
|
|
|
|
|
map.addAttribute("powersMap2", cAdmin.getPowers());
|
2021-02-04 11:15:05 +08:00
|
|
|
return "permission-setting";
|
|
|
|
|
}
|
2021-04-14 11:12:57 +08:00
|
|
|
|
2021-06-25 16:24:57 +08:00
|
|
|
/**
|
|
|
|
|
* 获取用户渠道包权限
|
|
|
|
|
* @param map
|
|
|
|
|
* @param request
|
|
|
|
|
* @return
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping(value ="/getUserChannelPack",method = {RequestMethod.POST, RequestMethod.GET})
|
|
|
|
|
public String getUserChannelPack(ModelMap map,HttpServletRequest request) throws Exception {
|
|
|
|
|
HashMap<String, String> parameterMap = JsonUtil.getInstence().getParameterMap(request);
|
|
|
|
|
|
|
|
|
|
String id = parameterMap.get("id");
|
|
|
|
|
map.addAttribute("id",id);
|
|
|
|
|
|
|
|
|
|
// 赋予者的权限列表
|
|
|
|
|
String userName = (String) request.getSession().getAttribute("username");
|
|
|
|
|
CAdmin admin = cUserDao.findAdmin(userName);
|
|
|
|
|
List<ChannelInfo> ids = channelInfoDao.getChannelInfoListByIds(admin.getChannelPack());
|
|
|
|
|
map.addAttribute("channelPack", ids);
|
|
|
|
|
|
|
|
|
|
// 被赋予者的权限列表
|
|
|
|
|
CAdmin cAdmin = cUserDao.findAdminById(id);
|
|
|
|
|
List<ChannelInfo> ids1 = channelInfoDao.getChannelInfoListByIds(cAdmin.getChannelPack());
|
|
|
|
|
request.setAttribute("channelPack2", ids1);
|
|
|
|
|
|
|
|
|
|
return "channelPack-setting";
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-14 11:12:57 +08:00
|
|
|
/**
|
|
|
|
|
* 修改密码
|
|
|
|
|
* @param request
|
|
|
|
|
* @return
|
|
|
|
|
* 1:成功
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
2021-02-04 11:15:05 +08:00
|
|
|
@RequestMapping(value = "/resetPassword",method = {RequestMethod.POST, RequestMethod.GET})
|
2021-04-14 11:12:57 +08:00
|
|
|
public @ResponseBody int resetPassword(HttpServletRequest request) throws Exception{
|
2021-02-04 11:15:05 +08:00
|
|
|
HashMap<String, String> parameterMap = JsonUtil.getInstence().getParameterMap(request);
|
|
|
|
|
String id = parameterMap.get("id");
|
2021-04-14 11:12:57 +08:00
|
|
|
CAdmin admin = cUserDao.findAdminById(id);
|
|
|
|
|
admin.setPassword("123456");
|
|
|
|
|
cUserDao.updateUser(admin);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2021-02-04 11:15:05 +08:00
|
|
|
|
2021-04-14 11:12:57 +08:00
|
|
|
/**
|
|
|
|
|
* 验证是否可以使用添加账号功能
|
|
|
|
|
* @param session
|
|
|
|
|
* @return
|
|
|
|
|
* 0: 失败,权限不足
|
|
|
|
|
* 1: 成功
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping(value = "/verifyAddAdmin",method = {RequestMethod.POST, RequestMethod.GET})
|
|
|
|
|
public @ResponseBody
|
|
|
|
|
int verifyAddAdmin(HttpSession session) throws Exception{
|
|
|
|
|
String account = (String) session.getAttribute(WebSecurityConfig.SESSION_KEY);
|
|
|
|
|
CAdmin admin = cUserDao.findAdmin(account);
|
|
|
|
|
if (admin == null || admin.getIdentity() == IdentityEnum.GENERAL_ACCOUNT.getId()){
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2021-02-04 11:15:05 +08:00
|
|
|
return 1;
|
|
|
|
|
}
|
2021-04-14 11:12:57 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 添加用户
|
|
|
|
|
* @param map
|
|
|
|
|
* @param session
|
|
|
|
|
* @return
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping(value = "/addAdmin",method = {RequestMethod.POST, RequestMethod.GET})
|
|
|
|
|
public String addAdmin(ModelMap map,HttpSession session) throws Exception{
|
|
|
|
|
String account = (String) session.getAttribute(WebSecurityConfig.SESSION_KEY);
|
|
|
|
|
CAdmin admin = cUserDao.findAdmin(account);
|
|
|
|
|
List<IdentityVo> list = IdentityVo.create(admin.getIdentity());
|
|
|
|
|
map.addAttribute("identityList",list);
|
|
|
|
|
return "member-add";
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-08 17:29:02 +08:00
|
|
|
}
|