Correct oauth bug when no mutual server
This commit is contained in:
parent
4234227e6b
commit
cff1a49b40
@ -48,6 +48,13 @@ public class UserEntity {
|
|||||||
this.password = passwordEncoder.encode(UserUtils.getInstance().generateCheckToken());
|
this.password = passwordEncoder.encode(UserUtils.getInstance().generateCheckToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UserEntity(String name, String id, PasswordEncoder passwordEncoder){
|
||||||
|
this.name = name;
|
||||||
|
this.jdaId = id;
|
||||||
|
this.apiToken = UserUtils.getInstance().generateApiToken();
|
||||||
|
this.password = passwordEncoder.encode(UserUtils.getInstance().generateCheckToken());
|
||||||
|
}
|
||||||
|
|
||||||
public String getPassword() {
|
public String getPassword() {
|
||||||
return password;
|
return password;
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
package net.Broken.Tools.UserManager;
|
package net.Broken.Tools.UserManager;
|
||||||
|
|
||||||
|
import jdk.nashorn.internal.parser.JSONParser;
|
||||||
import net.Broken.DB.Entity.UserEntity;
|
import net.Broken.DB.Entity.UserEntity;
|
||||||
import net.Broken.DB.Repository.UserRepository;
|
import net.Broken.DB.Repository.UserRepository;
|
||||||
import net.Broken.MainBot;
|
import net.Broken.MainBot;
|
||||||
|
import net.dv8tion.jda.core.entities.User;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
@ -25,7 +27,7 @@ public class Oauth {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
private String getUserId(String token){
|
private JSONObject getUserId(String token){
|
||||||
StringBuffer content = new StringBuffer();
|
StringBuffer content = new StringBuffer();
|
||||||
try {
|
try {
|
||||||
String httpsURL = baseUrl+mePath;
|
String httpsURL = baseUrl+mePath;
|
||||||
@ -48,19 +50,25 @@ public class Oauth {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
JSONObject json = new JSONObject(content.toString());
|
JSONObject json = new JSONObject(content.toString());
|
||||||
|
logger.debug(json);
|
||||||
|
|
||||||
|
|
||||||
return json.getString("id");
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public UserEntity getUserEntity(String token, UserRepository userRepository, PasswordEncoder passwordEncoder){
|
public UserEntity getUserEntity(String token, UserRepository userRepository, PasswordEncoder passwordEncoder){
|
||||||
String discorId = getUserId(token);
|
JSONObject discorResponse = getUserId(token);
|
||||||
List<UserEntity> userEntitys = userRepository.findByJdaId(discorId);
|
List<UserEntity> userEntitys = userRepository.findByJdaId(discorResponse.getString("id"));
|
||||||
if(userEntitys.size() != 0){
|
if(userEntitys.size() != 0){
|
||||||
return userEntitys.get(0);
|
return userEntitys.get(0);
|
||||||
}else{
|
}else{
|
||||||
UserEntity user = new UserEntity(MainBot.jda.getUserById(discorId), passwordEncoder);
|
User jdaUser = MainBot.jda.getUserById(discorResponse.getString("id"));
|
||||||
|
UserEntity user;
|
||||||
|
if( jdaUser == null)
|
||||||
|
user = new UserEntity(discorResponse.getString("username"), discorResponse.getString("id"), passwordEncoder);
|
||||||
|
else
|
||||||
|
user = new UserEntity(MainBot.jda.getUserById(discorResponse.getString("id")), passwordEncoder);
|
||||||
user = userRepository.save(user);
|
user = userRepository.save(user);
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user