Skip to content
Snippets Groups Projects
Commit 10090937 authored by josborg's avatar josborg
Browse files

Redireccion dinamica

parent bbd9847f
Branches
No related tags found
No related merge requests found
......@@ -10,7 +10,8 @@
</div>
</div>
<div class="col">
<label for="">Añadir redireccion al un servidor de discord: </label>
<button (click)="send()" >send()</button>
</div>
</div>
<div class="row">
......
......@@ -22,4 +22,8 @@ export class AdminComponent implements OnInit {
this.clienteApiRest.addBot();
}
send(){
this.clienteApiRest.sendRedirectUri().subscribe();
}
}
......@@ -10,13 +10,11 @@ import { Solucion } from './app.soluciones-model';
})
export class ClienteApiOrdersService {
private static BASE_URI = 'http://'+location.hostname+':'+location.port+'/api/encuestas/';
private static BASE_URI = 'http://'+location.hostname+'/api/encuestas/';
//readonly
constructor(private http: HttpClient) {
if(location.port.length == 0){
ClienteApiOrdersService.BASE_URI = 'http://'+location.hostname+'/api/encuestas/';
}else{
if(location.port.length != 0){
ClienteApiOrdersService.BASE_URI = 'http://'+location.hostname+':'+location.port+'/api/encuestas/';
}
}
......
......@@ -14,26 +14,31 @@ export class ClienteApiOAutchService {
private static readonly client_id = "920088907733930054";
private static readonly client_secret = "2sKjxaLFQwv5DIxXFVt2pNG7DTGONFWm";
private static readonly scope = "identify";
public static redirect_uri = "http://"+location.hostname+':'+location.port+"/client/auth";
public static redirect_uri = "http://"+location.hostname+"/client/auth";
public static readonly discord_login_url = "https://discord.com/oauth2/authorize?redirect_uri=" + ClienteApiOAutchService.redirect_uri + "&response_type=token&client_id=" + ClienteApiOAutchService.client_id + "&scope=" + ClienteApiOAutchService.scope;
public static readonly discord_tocken_url = "https://discord.com/api/oauth2/token";
public static readonly discord_api_url = "https://discordapp.com/api/v8";
public static readonly discord_add_bot_url = "https://discord.com/api/oauth2/authorize?client_id="+ClienteApiOAutchService.client_id+"&scope=bot&permissions=8"
public static auth_url = "http://"+location.hostname+':'+location.port+"/api/auth";
postId:any;
public static auth_url = "http://"+location.hostname+"/api/auth";
public static BASE_URI = "http://"+location.hostname+"/api/bot";
private static isSended = false;
constructor(private http: HttpClient) {
if(location.port.length == 0){
ClienteApiOAutchService.auth_url = "http://"+location.hostname+"/api/auth";
ClienteApiOAutchService.redirect_uri = "http://"+location.hostname+"/client/auth";
}else{
ClienteApiOAutchService.auth_url = "http://"+location.hostname+':'+location.port+"/api/auth";
ClienteApiOAutchService.redirect_uri = "http://"+location.hostname+':'+location.port+"/client/auth";
console.log("client")
if(location.port.length != 0){
console.log("Refactor");
ClienteApiOAutchService.auth_url = "http://"+location.hostname+":"+location.port+"/api/auth";
ClienteApiOAutchService.redirect_uri = "http://"+location.hostname+":"+location.port+"/client/auth";
ClienteApiOAutchService.BASE_URI = "http://"+location.hostname+":"+location.port+"/api/bot";
}
}
sendRedirectUri():Observable<HttpResponse<string>>{
let url = ClienteApiOAutchService.BASE_URI + "/redir";
return this.http.post(url, ClienteApiOAutchService.redirect_uri, { observe: "response", responseType: 'text'});
}
getJWT(user: User, code: String){
......
......@@ -36,7 +36,7 @@ import org.springframework.web.bind.annotation.RequestParam;
@CrossOrigin(origins = "*")
public class ControllerBot {
String token = "OTIwMDg4OTA3NzMzOTMwMDU0.YbfRkg.S2_yeVBcKV-fsCGao2hScq_0aPI";
//private String token = "OTIwMDg4OTA3NzMzOTMwMDU0.YbfRkg.S2_yeVBcKV-fsCGao2hScq_0aPI";
ControllerBot() {
......@@ -60,6 +60,18 @@ public class ControllerBot {
}
@PostMapping(value = "/redir", produces = MediaType.APPLICATION_JSON_VALUE)
public String setRedir(@RequestBody String str) {
System.out.println("/redir: "+str);
if(str.isEmpty()){
return "ERROR";
}else{
Global.redir = str;
return "OK";
}
}
@PostMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public String guildsUsuario(@RequestBody String json) {
......
package com.uva.discordbot.listener;
import java.util.List;
import javax.print.DocFlavor.STRING;
import com.uva.discordbot.util.Global;
import com.google.gson.Gson;
import com.uva.discordbot.model.Link;
......@@ -41,7 +40,8 @@ public abstract class MessageListener {
.then();
}
//&& user.getTag().equals("TAG")
if(content.length == 2 && content[0].equalsIgnoreCase("!link") && isRol(eventMessage, "Profesor")){
if(content.length == 2 && content[0].equalsIgnoreCase("!link")
&& isRol(eventMessage, "Profesor") && !Global.redir.isEmpty()){
//String obj = new RestTemplate().getForObject("http://localhost:8080/users?email=", String.class);
Link link = new Link(eventMessage.getGuild().block().getId().asLong(),content[1]);
......@@ -55,11 +55,12 @@ public abstract class MessageListener {
System.out.println(resultAsJsonStr);
return Mono.just(eventMessage)
.filter(message -> message.getAuthor().map(user -> !user.isBot()).orElse(false))
.flatMap(Message::getChannel)
.flatMap(channel -> channel
.createMessage("Participa en la prueba con codigo: " + content[1] + " --> http://localhost/client/auth/"+content[1]))
.createMessage("Participa en la prueba con codigo: " + content[1] + " --> "+Global.redir+"/"+content[1]))
.then();
}
return Mono.empty();
......
......@@ -5,4 +5,5 @@ import java.util.HashMap;
public class Global {
public static HashMap<String,ArrayList<String>> guilds = new HashMap<>();
public static String redir = "";
}
......@@ -43,7 +43,7 @@ public class BotController {
//Back POST
@PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE)
@PostMapping(consumes = MediaType.ALL_VALUE)
private String postDiscord(HttpServletRequest req, @RequestBody String body) {
System.out.println("/api/bot");
RestTemplate restTemplate = new RestTemplate();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment