diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..31fe120
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+/src/main/resources/application.properties
+.idea
+/target/
diff --git a/GCDC-Server.iml b/GCDC-Server.iml
new file mode 100644
index 0000000..78b2cc5
--- /dev/null
+++ b/GCDC-Server.iml
@@ -0,0 +1,2 @@
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index f2d3b09..8624917 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,11 +23,20 @@
3.8.1
11
+
+ 11
+
+
+ jitpack.io
+ https://jitpack.io
+
+
+
org.springframework.boot
@@ -49,15 +58,6 @@
org.postgresql
postgresql
-
- org.springframework.security
- spring-security-core
- 5.1.6.RELEASE
-
-
- org.springframework.boot
- spring-boot-starter-security
-
org.projectlombok
lombok
@@ -67,6 +67,16 @@
discord4j-core
3.0.12
+
+ com.github.HayateLaTech
+ OAuth2Discord
+ master-SNAPSHOT
+
+
+ org.springframework.boot
+ spring-boot-configuration-processor
+ true
+
diff --git a/src/main/java/io/github/norbipeti/gcdc/controller/DCController.java b/src/main/java/io/github/norbipeti/gcdc/controller/DCController.java
new file mode 100644
index 0000000..a3c8c69
--- /dev/null
+++ b/src/main/java/io/github/norbipeti/gcdc/controller/DCController.java
@@ -0,0 +1,75 @@
+package io.github.norbipeti.gcdc.controller;
+
+import bell.oauth.discord.main.OAuthBuilder;
+import bell.oauth.discord.main.Response;
+import discord4j.core.object.entity.Message;
+import discord4j.core.object.util.Snowflake;
+import io.github.norbipeti.gcdc.model.Session;
+import io.github.norbipeti.gcdc.service.DiscordService;
+import io.github.norbipeti.gcdc.service.SessionService;
+import lombok.RequiredArgsConstructor;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.context.request.async.DeferredResult;
+import org.springframework.web.server.ResponseStatusException;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.validation.Valid;
+import java.security.Principal;
+import java.util.Collections;
+import java.util.Map;
+import java.util.UUID;
+
+@RestController
+@RequiredArgsConstructor
+public class DCController {
+ private static final Map RESULT_OK = Collections.singletonMap("response", "OK");
+ private final SessionService service;
+ private final DiscordService discordService;
+ @Value("${discord.secret}")
+ private String secret;
+ private final OAuthBuilder builder = new OAuthBuilder("680138144812892371", secret);
+
+ @GetMapping("/api/users/register")
+ public Map register(@RequestParam String state, @RequestParam String code, HttpServletRequest request) {
+ if (state == null || code == null) throw new ResponseStatusException(HttpStatus.BAD_REQUEST);
+ long channel;
+ try { channel = Long.parseLong(state); } catch (NumberFormatException e) {
+ throw new ResponseStatusException(HttpStatus.BAD_REQUEST);
+ }
+ builder.setRedirectURI(request.getRequestURL().toString());
+ if (builder.exchange(code) == Response.ERROR)
+ throw new ResponseStatusException(HttpStatus.BAD_REQUEST);
+ long user = Snowflake.of(builder.getUser().getId()).asLong();
+ service.deleteSession(user);
+ service.insertSession(new Session(UUID.randomUUID().toString(), Snowflake.of(channel), user));
+ return RESULT_OK;
+ }
+
+ @GetMapping("/api/users/get")
+ public Map getUser(@RequestParam String token) {
+ getSession(token); //Returns unauthorized if needed
+ return RESULT_OK;
+ }
+
+ @PostMapping("/api/messages/send")
+ public Map sendMessage(@RequestParam String token, @RequestParam String message) {
+ var sess = getSession(token);
+ discordService.sendMessage(sess.getChannel().asLong(), sess.getUser(), message);
+ return RESULT_OK;
+ }
+
+ @GetMapping("/api/messages/get")
+ public DeferredResult