Skip to content

Commit 1c6cfea

Browse files
committed
登录状态下绑定第三方
修改常量为大写字符
1 parent 3caca0e commit 1c6cfea

File tree

6 files changed

+64
-43
lines changed

6 files changed

+64
-43
lines changed

springboot-dubbo-web/src/main/java/com/lzq/web/controller/ExampleController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ public Map<String, Object> CreateFile(Example example, Content exampleContent, S
9999
//获取当前时间毫秒
100100
long time = System.currentTimeMillis();
101101
//创建编译后的html文件
102-
String file = ExampleUtils.filelocation + example.getUsername() + "/" + time + ".html";
102+
String file = ExampleUtils.FILE_LOCATION + example.getUsername() + "/" + time + ".html";
103103
//初始化模板
104-
File initfile = new File(ExampleUtils.InitHtml);
104+
File initfile = new File(ExampleUtils.INIT_HTML);
105105
File existfile = new File(file);
106106
try {
107107
//创建文件

springboot-dubbo-web/src/main/java/com/lzq/web/controller/IndexController.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,5 @@ public Map<String, Object> doLogin(HttpServletRequest request) {
361361
}
362362

363363

364-
@PostMapping("/updateBind")
365-
public Map<String, Object> updateBind(Account account) {
366-
Boolean aBoolean = accountService.bindGit(account);
367-
log.info(aBoolean.toString());
368-
return ResultMapUtils.ResultMap(true, 0, aBoolean);
369-
}
370364

371365
}

springboot-dubbo-web/src/main/java/com/lzq/web/utils/ExampleUtils.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,39 +24,39 @@
2424
@Component
2525
public class ExampleUtils {
2626

27-
public static String InitHtml;
27+
public static String INIT_HTML;
2828

29-
public static String filelocation;
29+
public static String FILE_LOCATION;
3030

31-
public static String chormeDriver;
31+
public static String CHORME_DRIVER;
3232

33-
public static String bucket;
33+
public static String BUCKET;
3434

35-
public static String url;
35+
public static String URL;
3636

3737
@Value("${resources.InitHtml}")
3838
public void setInitHtml(String initHtml) {
39-
InitHtml = initHtml;
39+
INIT_HTML = initHtml;
4040
}
4141

4242
@Value("${resources.route}")
4343
public void setFilelocation(String filelocation) {
44-
ExampleUtils.filelocation = filelocation;
44+
ExampleUtils.FILE_LOCATION = filelocation;
4545
}
4646

4747
@Value("${chorme.value}")
4848
public void setChormeDriver(String chormeDriver) {
49-
ExampleUtils.chormeDriver = chormeDriver;
49+
ExampleUtils.CHORME_DRIVER = chormeDriver;
5050
}
5151

5252
@Value("${qiniuyun.bucket}")
5353
public void setBucket(String bucket) {
54-
ExampleUtils.bucket = bucket;
54+
ExampleUtils.BUCKET = bucket;
5555
}
5656

5757
@Value("${qiniuyun.url}")
5858
public void setUrl(String url) {
59-
ExampleUtils.url = url;
59+
ExampleUtils.URL = url;
6060
}
6161

6262
/**
@@ -72,7 +72,7 @@ public static String screenshot(String username, String filename, String imgname
7272
//使用截屏工具进行截屏
7373
//启用chrome驱动
7474
//chrome驱动的位置
75-
System.setProperty("webdriver.chrome.driver", chormeDriver);
75+
System.setProperty("webdriver.chrome.driver", CHORME_DRIVER);
7676
System.setProperty("java.awt.headless", "true");
7777
ChromeOptions options = new ChromeOptions();
7878
options.addArguments("--headless");
@@ -100,7 +100,7 @@ public static Boolean SaveExampleContent(Example example, Content exampleContent
100100
//获取html文件路劲
101101
//实例内容和实例进行绑定
102102
exampleContent.setExampleId(example.getExampleId());
103-
String file = filelocation + example.getUsername() + "/" + example.getFileName() + ".html";
103+
String file = FILE_LOCATION + example.getUsername() + "/" + example.getFileName() + ".html";
104104
System.out.println(file);
105105
FileOutputStream fos = new FileOutputStream(new File(file));
106106
String screenshot = null;
@@ -122,7 +122,7 @@ public static Boolean SaveExampleContent(Example example, Content exampleContent
122122
screenshot = ExampleUtils.screenshot(example.getUsername(), example.getFileName(), example.getImg());
123123
}
124124
//修改图片地址
125-
example.setImg(url + screenshot);
125+
example.setImg(URL + screenshot);
126126
//更新实例
127127
bol = exampleService.update(example);
128128
//修改实例内容 当表无该数据时插入数据

springboot-dubbo-web/src/main/java/com/lzq/web/utils/QiniuyunUtils.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,23 @@
2222
@Component
2323
public class QiniuyunUtils {
2424

25-
private static String accessKey;
26-
public static String secretKey;
27-
public static String bucket;
25+
private static String ACCESSKEY;
26+
public static String SECRETKEY;
27+
public static String BUCKET;
2828

2929
@Value("${qiniuyun.accessKey}")
3030
public void setAccessKey(String accessKey) {
31-
QiniuyunUtils.accessKey = accessKey;
31+
QiniuyunUtils.ACCESSKEY = accessKey;
3232
}
3333

3434
@Value("${qiniuyun.secretKey}")
3535
public void setSecretKey(String secretKey) {
36-
QiniuyunUtils.secretKey = secretKey;
36+
QiniuyunUtils.SECRETKEY = secretKey;
3737
}
3838

3939
@Value("${qiniuyun.bucket}")
4040
public void setBucket(String bucket) {
41-
QiniuyunUtils.bucket = bucket;
41+
QiniuyunUtils.BUCKET = bucket;
4242
}
4343

4444
/**
@@ -57,9 +57,9 @@ public static String uploadFiles(byte[] bytes, String imgname) {
5757
String key = imgname;
5858
// byte[] uploadBytes = "hello qiniu cloud".getBytes("utf-8");
5959
ByteArrayInputStream byteInputStream = new ByteArrayInputStream(bytes);
60-
Auth auth = Auth.create(accessKey, secretKey);
60+
Auth auth = Auth.create(ACCESSKEY, SECRETKEY);
6161

62-
String upToken = auth.uploadToken(bucket);
62+
String upToken = auth.uploadToken(BUCKET);
6363
DefaultPutRet putRet = null;
6464
try {
6565
Response response = uploadManager.put(byteInputStream, key, upToken, null, null);
@@ -90,10 +90,10 @@ public static void deleteFiles(String imgname) {
9090
Configuration cfg = new Configuration(Region.region0());
9191
//...其他参数参考类注释
9292
String key = imgname;
93-
Auth auth = Auth.create(accessKey, secretKey);
93+
Auth auth = Auth.create(ACCESSKEY, SECRETKEY);
9494
BucketManager bucketManager = new BucketManager(auth, cfg);
9595
try {
96-
bucketManager.delete(bucket, key);
96+
bucketManager.delete(BUCKET, key);
9797
} catch (QiniuException ex) {
9898
//如果遇到异常,说明删除失败
9999
System.err.println(ex.code());

springboot-dubbo-web/src/main/java/com/lzq/web/utils/UserUtils.java

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ public static Map<String, Object> BindAccount(Account account, String headtoken,
3434
//用户保存jwt信息
3535
HashMap<String, String> jwtmap = new HashMap();
3636
//判断是否有token 有token则需要进行第三方绑定 没有则正常登录返回结果
37-
if (headtoken != null && headtoken != "") {
37+
if (StringUtils.isNotBlank(headtoken)) {
3838
//验证token
3939
DecodedJWT verify = JWTUtils.verify(headtoken);
4040
//获取token中的信息
4141
String id = verify.getClaim("githubId").asString();
4242
//判断是github登录还是gitee登录
4343
if (StringUtils.isNotBlank(id)) {
44-
if (account.getGithubId() != "" && account.getGithubId() != null) {
44+
if (StringUtils.isNotBlank(account.getGithubId())) {
4545
//该用户已经绑定了github账号
4646
return ResultMapUtils.ResultMapWithToken(true,1,account,null);
4747
}
@@ -57,12 +57,18 @@ public static Map<String, Object> BindAccount(Account account, String headtoken,
5757
}
5858
//更新数据进行账号绑定
5959
accountService.bindGit(account);
60+
//登录成功生产token
61+
jwtmap.put("username", account.getUsername());
62+
String token = JWTUtils.getToken(jwtmap);
63+
return ResultMapUtils.ResultMapWithToken(true,2,account,token);
64+
}else {
65+
//登录成功生产token
66+
jwtmap.put("username", account.getUsername());
67+
String token = JWTUtils.getToken(jwtmap);
68+
//返回信息
69+
return ResultMapUtils.ResultMapWithToken(true,0,account,token);
6070
}
61-
//登录成功生产token
62-
jwtmap.put("username", account.getUsername());
63-
String token = JWTUtils.getToken(jwtmap);
64-
//返回信息
65-
return ResultMapUtils.ResultMapWithToken(true,0,account,token);
71+
6672
}
6773

6874

@@ -79,6 +85,15 @@ public static void responseMessage(HttpServletResponse response, Map<String, Obj
7985
}
8086

8187

88+
/**
89+
* 查询第三方登录信息
90+
* @param request
91+
* @param baseOuathService
92+
* @param redisTemplate
93+
* @param accountService
94+
* @param gitType 第三方登录类型
95+
* @return
96+
*/
8297
public static Map<String, Object> callback(HttpServletRequest request, BaseOuathService baseOuathService,
8398
StringRedisTemplate redisTemplate,AccountService accountService,String gitType){
8499
String header = request.getHeader("token");
@@ -97,17 +112,27 @@ public static Map<String, Object> callback(HttpServletRequest request, BaseOuath
97112
if (gitType.equals("giteeId")){
98113
rest = accountService.queryByGitId(null, info.getId());
99114
if (StringUtils.isNotBlank(header)){
100-
rest.setGiteeId(info.getId());
101-
accountService.bindGit(rest);
115+
if (rest==null){
116+
rest.setGiteeId(info.getId());
117+
accountService.bindGit(rest);
118+
return ResultMapUtils.ResultMapWithToken(true, 1, "登陆状态下绑定第三方成功", null);
119+
}else {
120+
return ResultMapUtils.ResultMapWithToken(false,1,"登录状态下绑定第三方失败,该第三方已绑定其他账号",null);
121+
}
122+
102123
}
103124
}else if (gitType.equals("githubId")){
104125
rest = accountService.queryByGitId(info.getId(),null );
105126
if (StringUtils.isNotBlank(header)){
106-
rest.setGiteeId(info.getId());
107-
accountService.bindGit(rest);
127+
if (rest==null){
128+
rest.setGithubId(info.getId());
129+
accountService.bindGit(rest);
130+
return ResultMapUtils.ResultMapWithToken(true, 1, "登陆状态下绑定第三方成功", null);
131+
}else {
132+
return ResultMapUtils.ResultMapWithToken(false,1,"登录状态下绑定第三方失败,该第三方已绑定其他账号",null);
133+
}
108134
}
109135
}
110-
rest = accountService.queryByGitId(null, info.getId());
111136
String token;
112137
//判断改github是否进行过绑定 未绑定则进行绑定,绑定则返回用户信息
113138
if (rest != null) {

springboot-dubbo-web/src/main/java/com/lzq/web/utils/VerifyCodeUtils.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
public class VerifyCodeUtils {
66

77

8+
9+
810
public static String getCode() {
911
Random random = new Random();
1012
StringBuffer buffer = new StringBuffer();

0 commit comments

Comments
 (0)