mirror of
https://github.com/luoye663/e5.git
synced 2024-12-26 11:48:50 +00:00
增加一个简单的公告功能、获取debug admin token
增加配置: announcement=classpath:announcement.txt user.admin.debug.passwd=123456
This commit is contained in:
parent
13bd6394a6
commit
07395a2e97
@ -1,15 +1,25 @@
|
|||||||
package io.qyi.e5.controller.admin;
|
package io.qyi.e5.controller.admin;
|
||||||
|
|
||||||
|
import io.qyi.e5.config.security.UsernamePasswordAuthenticationToken;
|
||||||
import io.qyi.e5.outlook.service.IOutlookService;
|
import io.qyi.e5.outlook.service.IOutlookService;
|
||||||
import io.qyi.e5.service.task.ITask;
|
import io.qyi.e5.service.task.ITask;
|
||||||
|
import io.qyi.e5.util.EncryptUtil;
|
||||||
|
import io.qyi.e5.util.StringUtil;
|
||||||
import io.qyi.e5.util.redis.RedisUtil;
|
import io.qyi.e5.util.redis.RedisUtil;
|
||||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.security.core.authority.AuthorityUtils;
|
||||||
|
import org.springframework.util.ResourceUtils;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @program: 此类里大多都是测试
|
* @program: 此类里大多都是测试
|
||||||
* @description:
|
* @description:
|
||||||
@ -34,6 +44,15 @@ public class AdminController {
|
|||||||
@Value("user.admin.githubId")
|
@Value("user.admin.githubId")
|
||||||
String adminGithubId;
|
String adminGithubId;
|
||||||
|
|
||||||
|
@Value("${user.admin.debug.passwd}")
|
||||||
|
String userAdminDebugPasswd;
|
||||||
|
|
||||||
|
@Value("${redis.user.token}")
|
||||||
|
String token_;
|
||||||
|
|
||||||
|
@Value("${user.token.expire}")
|
||||||
|
private int tokenExpire;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 测试队列
|
* 测试队列
|
||||||
* @Author: 落叶随风
|
* @Author: 落叶随风
|
||||||
@ -73,4 +92,40 @@ public class AdminController {
|
|||||||
public String test() {
|
public String test() {
|
||||||
return "ok";
|
return "ok";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping("setAnnouncement")
|
||||||
|
public String setAnnouncement(String text) throws IOException {
|
||||||
|
File file = ResourceUtils.getFile("classpath:announcement.txt");
|
||||||
|
FileWriter writer = new FileWriter(file);
|
||||||
|
writer.write(text);
|
||||||
|
writer.close();
|
||||||
|
return "ok";
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("getDebugAdminToken")
|
||||||
|
public String getDebugAdminToken(String passwd) {
|
||||||
|
if (userAdminDebugPasswd.equals(passwd)) {
|
||||||
|
String token = EncryptUtil.getInstance().SHA1Hex(UUID.randomUUID().toString());
|
||||||
|
/*配置角色,这里只是简单的配置,实际上需要从数据库中读取角色*/
|
||||||
|
List<String> list_Authority = new ArrayList<>();
|
||||||
|
list_Authority.add("user");
|
||||||
|
list_Authority.add("admin");
|
||||||
|
String[] Authority = list_Authority.toArray(new String[list_Authority.size()]);
|
||||||
|
/*写token信息到redis*/
|
||||||
|
Map<String, Object> userInfo_redis = new HashMap<>();
|
||||||
|
userInfo_redis.put("github_name", "admin");
|
||||||
|
userInfo_redis.put("github_id", 0000);
|
||||||
|
userInfo_redis.put("avatar_url", "https://www.baidu.com");
|
||||||
|
userInfo_redis.put("authority", list_Authority);
|
||||||
|
redisUtil.hmset(token_ + token, userInfo_redis, tokenExpire);
|
||||||
|
|
||||||
|
|
||||||
|
// 创建一个已认证的token
|
||||||
|
// UsernamePasswordAuthenticationToken authenticationToken1 = new UsernamePasswordAuthenticationToken(userInfo_redis.get("github_name").toString(),
|
||||||
|
// userInfo_redis.get("github_name").toString(), (int)userInfo_redis.get("github_name"), token, "user", AuthorityUtils.createAuthorityList(Authority));
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
return "la la la";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,13 +6,17 @@ import io.qyi.e5.github.service.IGithubService;
|
|||||||
import io.qyi.e5.outlook.service.IOutlookService;
|
import io.qyi.e5.outlook.service.IOutlookService;
|
||||||
import io.qyi.e5.outlook_log.service.IOutlookLogService;
|
import io.qyi.e5.outlook_log.service.IOutlookLogService;
|
||||||
import io.qyi.e5.util.ResultUtil;
|
import io.qyi.e5.util.ResultUtil;
|
||||||
|
import io.qyi.e5.util.StringUtil;
|
||||||
import io.qyi.e5.util.redis.RedisUtil;
|
import io.qyi.e5.util.redis.RedisUtil;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
|
import org.springframework.util.ResourceUtils;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -72,4 +76,10 @@ public class WebController {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping("getAnnouncement")
|
||||||
|
public String getAnnouncement() throws IOException {
|
||||||
|
String s = StringUtil.readTxt(ResourceUtils.getFile("classpath:announcement.txt"));
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package io.qyi.e5.util;
|
package io.qyi.e5.util;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -24,4 +25,15 @@ public class StringUtil {
|
|||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String readTxt(File file) throws IOException {
|
||||||
|
String s = "";
|
||||||
|
InputStreamReader in = new InputStreamReader(new FileInputStream(file),"UTF-8");
|
||||||
|
BufferedReader br = new BufferedReader(in);
|
||||||
|
StringBuffer content = new StringBuffer();
|
||||||
|
while ((s=br.readLine())!=null){
|
||||||
|
content = content.append(s);
|
||||||
|
}
|
||||||
|
return content.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
1
src/main/resources/announcement.txt
Normal file
1
src/main/resources/announcement.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
点击小猫咪头像进行登录。
|
Loading…
Reference in New Issue
Block a user