Add check tocken
This commit is contained in:
parent
23d098780b
commit
0010822a03
@ -12,6 +12,7 @@ import net.Broken.Tools.UserManager.UserUtils;
|
|||||||
import net.dv8tion.jda.core.Permission;
|
import net.dv8tion.jda.core.Permission;
|
||||||
import net.dv8tion.jda.core.entities.Guild;
|
import net.dv8tion.jda.core.entities.Guild;
|
||||||
import net.dv8tion.jda.core.entities.User;
|
import net.dv8tion.jda.core.entities.User;
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
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.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -137,6 +138,18 @@ public class UserManagerAPIController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@RequestMapping(value = "/checkToken", method = RequestMethod.GET)
|
||||||
|
public ResponseEntity checkToken(@CookieValue(value = "token") String token){
|
||||||
|
try{
|
||||||
|
userUtils.getUserWithApiToken(userRepository,token);
|
||||||
|
return new ResponseEntity(HttpStatus.OK);
|
||||||
|
} catch (UnknownTokenException e) {
|
||||||
|
logger.info("Token check fail");
|
||||||
|
return new ResponseEntity(HttpStatus.UNAUTHORIZED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -38,12 +38,7 @@ $(document).ready(function() {
|
|||||||
btn_disconnect = $(".nav-disconnect");
|
btn_disconnect = $(".nav-disconnect");
|
||||||
nav_name = $("#nav-name");
|
nav_name = $("#nav-name");
|
||||||
navListeners();
|
navListeners();
|
||||||
if(Cookies.get('token') === undefined){
|
|
||||||
disconnected()
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
connected();
|
|
||||||
}
|
|
||||||
|
|
||||||
checkConnection();
|
checkConnection();
|
||||||
|
|
||||||
@ -69,20 +64,16 @@ function popInSubmit(){
|
|||||||
|
|
||||||
function connected(){
|
function connected(){
|
||||||
console.log("Connected!");
|
console.log("Connected!");
|
||||||
nav_bar_account_link.html(connected_link);
|
console.log("Checking token...");
|
||||||
$('.dropdown-account').dropdown({
|
console.log(window.location.href);
|
||||||
constrainWidth: false, // Does not change width of dropdown to that of the activator
|
if(!window.location.href.includes("oauthCallback")){
|
||||||
coverTrigger: false, // Displays dropdown below the button
|
checkToken();
|
||||||
alignment: 'left', // Displays dropdown with edge aligned to the left of button
|
|
||||||
stopPropagation: false // Stops event propagation
|
|
||||||
}
|
|
||||||
);
|
|
||||||
nav_name.text(Cookies.get('name'));
|
|
||||||
if (typeof needLogin !== 'undefined') {
|
|
||||||
if (Cookies.get('guild') === undefined) {
|
|
||||||
getGuild()
|
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
console.log("Oauth page skip check token");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function disconnected() {
|
function disconnected() {
|
||||||
@ -112,7 +103,7 @@ function tryConnection() {
|
|||||||
console.log(data);
|
console.log(data);
|
||||||
Cookies.set('token',data.token, { expires: 31 });
|
Cookies.set('token',data.token, { expires: 31 });
|
||||||
Cookies.set('name', data.name, { expires: 31 });
|
Cookies.set('name', data.name, { expires: 31 });
|
||||||
debugger;
|
|
||||||
window.location.reload(true);
|
window.location.reload(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,6 +214,15 @@ function checkConnection() {
|
|||||||
url: "/api/isReady",
|
url: "/api/isReady",
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
console.log("Connection Ok");
|
console.log("Connection Ok");
|
||||||
|
console.log(Cookies.get('token'));
|
||||||
|
|
||||||
|
if(Cookies.get('token') === undefined){
|
||||||
|
disconnected()
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
connected();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}).fail(function (data) {
|
}).fail(function (data) {
|
||||||
@ -231,3 +231,43 @@ function checkConnection() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function checkToken() {
|
||||||
|
$.ajax({
|
||||||
|
type: "GET",
|
||||||
|
url: "/api/userManagement/checkToken",
|
||||||
|
success: function (data) {
|
||||||
|
console.debug("...token is valid.");
|
||||||
|
nav_bar_account_link.html(connected_link);
|
||||||
|
$('.dropdown-account').dropdown({
|
||||||
|
constrainWidth: false, // Does not change width of dropdown to that of the activator
|
||||||
|
coverTrigger: false, // Displays dropdown below the button
|
||||||
|
alignment: 'left', // Displays dropdown with edge aligned to the left of button
|
||||||
|
stopPropagation: false // Stops event propagation
|
||||||
|
}
|
||||||
|
);
|
||||||
|
nav_name.text(Cookies.get('name'));
|
||||||
|
if (typeof needLogin !== 'undefined') {
|
||||||
|
if (Cookies.get('guild') === undefined) {
|
||||||
|
getGuild()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}).fail(function (data) {
|
||||||
|
console.error("...token is invalid !");
|
||||||
|
console.log(data);
|
||||||
|
|
||||||
|
Cookies.remove('token');
|
||||||
|
Cookies.remove('name');
|
||||||
|
Cookies.remove('guild');
|
||||||
|
window.location.reload(true);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -15,6 +15,6 @@
|
|||||||
],
|
],
|
||||||
"start_url": "/",
|
"start_url": "/",
|
||||||
"display": "standalone",
|
"display": "standalone",
|
||||||
"theme_color": "#263238",
|
"theme_color": "#3e2723",
|
||||||
"background_color": "#263238"
|
"background_color": "#263238"
|
||||||
}
|
}
|
@ -11,11 +11,12 @@
|
|||||||
<!-- AND -->
|
<!-- AND -->
|
||||||
<!-- LOGIN -->
|
<!-- LOGIN -->
|
||||||
<!--__________________________________________________________-->
|
<!--__________________________________________________________-->
|
||||||
<link href="css/materialize.css" type="text/css" rel="stylesheet" media="screen,projection"/>
|
<link href="../static/css/materialize.css" type="text/css" rel="stylesheet" media="screen,projection"/>
|
||||||
|
|
||||||
<div th:fragment="header (page, guild_name, redirect_url, isAdmin)">
|
<div th:fragment="header (page, guild_name, redirect_url, isAdmin)">
|
||||||
<nav class="blue-grey darken-4 z-depth-3" role="navigation" >
|
<nav class="brown darken-4 z-depth-3" role="navigation" >
|
||||||
<div class="nav-wrapper container">
|
<div class="nav-wrapper container">
|
||||||
<a id="logo-container" href="/" class="brand-logo" style="white-space: nowrap">Claptrap Bot</a>
|
<b><a id="logo-container" href="/" class="brand-logo" style="white-space: nowrap">Claptrap Bot</a></b>
|
||||||
<ul class="right hide-on-med-and-down">
|
<ul class="right hide-on-med-and-down">
|
||||||
<li>
|
<li>
|
||||||
<a class="nav-change-guild truncate waves-effect waves-light btn-flat grey-text text-darken-1" th:text="${guild_name}" style="margin-top: 2px;margin-right: 0px;"></a>
|
<a class="nav-change-guild truncate waves-effect waves-light btn-flat grey-text text-darken-1" th:text="${guild_name}" style="margin-top: 2px;margin-right: 0px;"></a>
|
||||||
|
Loading…
Reference in New Issue
Block a user