php not seatting cookie naeanwaaefnasefnasefnf
This commit is contained in:
parent
8577b0aca9
commit
3ecac98d44
|
|
@ -19,6 +19,23 @@ class Controller extends BaseController
|
||||||
{
|
{
|
||||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||||
|
|
||||||
|
public function fetchUser() {
|
||||||
|
$POST;
|
||||||
|
|
||||||
|
if (!isset($_POST['token'])) {return Response()->json(false);}
|
||||||
|
|
||||||
|
$POST = $_POST['token'];
|
||||||
|
$user = User::where('token', $POST)->first();
|
||||||
|
|
||||||
|
if (!$user) {return Response()->json(false);}
|
||||||
|
|
||||||
|
$array = $user->toArray();
|
||||||
|
|
||||||
|
if (!$user) {return Response()->json(false);}
|
||||||
|
|
||||||
|
return Response()->json(["data"=>$array]);
|
||||||
|
}
|
||||||
|
|
||||||
public function login(Request $request) {
|
public function login(Request $request) {
|
||||||
|
|
||||||
$data = Request::all();
|
$data = Request::all();
|
||||||
|
|
@ -46,6 +63,8 @@ class Controller extends BaseController
|
||||||
|
|
||||||
Request::session()->regenerate();
|
Request::session()->regenerate();
|
||||||
|
|
||||||
|
setcookie('gtok', $user->token, time()+(345600*30), "/");
|
||||||
|
|
||||||
Auth::login($user);
|
Auth::login($user);
|
||||||
|
|
||||||
return Response()->json('good');
|
return Response()->json('good');
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,42 @@ import { useEffect } from 'react';
|
||||||
|
|
||||||
export var user;
|
export var user;
|
||||||
|
|
||||||
|
/* Cookie functions stolen from https://www.w3schools.com/js/js_cookies.asp | couldn't be asked tbh. */
|
||||||
|
|
||||||
|
export function setCookie(cname, cvalue, exdays) {
|
||||||
|
const d = new Date();
|
||||||
|
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
|
||||||
|
let expires = "expires="+d.toUTCString();
|
||||||
|
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getCookie(cname) {
|
||||||
|
let name = cname + "=";
|
||||||
|
let ca = document.cookie.split(';');
|
||||||
|
for(let i = 0; i < ca.length; i++) {
|
||||||
|
let c = ca[i];
|
||||||
|
while (c.charAt(0) == ' ') {
|
||||||
|
c = c.substring(1);
|
||||||
|
}
|
||||||
|
if (c.indexOf(name) == 0) {
|
||||||
|
return c.substring(name.length, c.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
export function checkCookie() {
|
||||||
|
let user = getCookie("username");
|
||||||
|
if (user != "") {
|
||||||
|
alert("Welcome again " + user);
|
||||||
|
} else {
|
||||||
|
user = prompt("Please enter your name:", "");
|
||||||
|
if (user != "" && user != null) {
|
||||||
|
setCookie("username", user, 365);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function useOnClickOutside(refs, handler) {
|
export function useOnClickOutside(refs, handler) {
|
||||||
useEffect(
|
useEffect(
|
||||||
() => {
|
() => {
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ import { About } from '../Pages/Legal/About.js';
|
||||||
import { Copyright } from '../Pages/Legal/Copyright.js';
|
import { Copyright } from '../Pages/Legal/Copyright.js';
|
||||||
import { Privacy } from '../Pages/Legal/Privacy.js';
|
import { Privacy } from '../Pages/Legal/Privacy.js';
|
||||||
import { Terms } from '../Pages/Legal/Terms.js';
|
import { Terms } from '../Pages/Legal/Terms.js';
|
||||||
|
import { getCookie } from '../helpers/utils.js';
|
||||||
|
|
||||||
axios.defaults.withCredentials = true
|
axios.defaults.withCredentials = true
|
||||||
|
|
||||||
|
|
@ -34,8 +35,8 @@ var protocol = Config.Protocol;
|
||||||
|
|
||||||
const App = () => {
|
const App = () => {
|
||||||
|
|
||||||
const [state, setState] = useState({maintenance: false, theme: 0, banners: [], offlineFetch: false, user: []});
|
const [state, setState] = useState({maintenance: false, theme: 0, banners: [], offlineFetch: false, loading: true});
|
||||||
var finished = false;
|
const [user, setUser] = useState([]);
|
||||||
|
|
||||||
function updateBanners()
|
function updateBanners()
|
||||||
{
|
{
|
||||||
|
|
@ -50,8 +51,13 @@ const App = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetchUser() {
|
function fetchUser() {
|
||||||
axios.post(`${protocol}apis.${url}/fetch/user`).then((res)=>{
|
const body = new FormData();
|
||||||
setState({user: res.data.data}, (e)=>{console.log(state.user)});
|
body.append('token', encodeURIComponent(getCookie(`gtok`)));
|
||||||
|
axios.post(`${protocol}apis.${url}/fetch/user`, body).then((res)=>{
|
||||||
|
setUser(res.data.data);
|
||||||
|
});
|
||||||
|
return new Promise(async (resolve, reject)=>{
|
||||||
|
resolve("good");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -80,13 +86,14 @@ const App = () => {
|
||||||
updateOfflineStatus();
|
updateOfflineStatus();
|
||||||
setInterval(updateBanners, 2*60*1000 /* 2 mins */);
|
setInterval(updateBanners, 2*60*1000 /* 2 mins */);
|
||||||
setInterval(updateOfflineStatus, 10*60*1000 /* 10 mins */);
|
setInterval(updateOfflineStatus, 10*60*1000 /* 10 mins */);
|
||||||
|
setState({loading: true});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
document.documentElement.classList.add(state.theme == 0 ? 'gtoria-light' : 'gtoria-dark');
|
document.documentElement.classList.add(state.theme == 0 ? 'gtoria-light' : 'gtoria-dark');
|
||||||
document.documentElement.classList.remove(!(state.theme == 0) ? 'gtoria-light' : 'gtoria-dark');
|
document.documentElement.classList.remove(!(state.theme == 0) ? 'gtoria-light' : 'gtoria-dark');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
state.offlineFetched == true ?
|
!state.loading?
|
||||||
<Router>
|
<Router>
|
||||||
<Navbar maintenanceEnabled={state.maintenance} />
|
<Navbar maintenanceEnabled={state.maintenance} />
|
||||||
{state.banners && state.banners.length >= 1 ? state.banners : null}
|
{state.banners && state.banners.length >= 1 ? state.banners : null}
|
||||||
|
|
@ -109,13 +116,13 @@ const App = () => {
|
||||||
<Route exact path="/" component={Home}/>
|
<Route exact path="/" component={Home}/>
|
||||||
|
|
||||||
<Route exact path="/login">
|
<Route exact path="/login">
|
||||||
{state.user? <NotFound/> : <Auth location={location.pathname}/>}
|
<Auth location={user && user.id? null : location.pathname}/>
|
||||||
</Route>
|
</Route>
|
||||||
<Route exact path="/register">
|
<Route exact path="/register">
|
||||||
{state.user? <NotFound/> : <Auth location={location.pathname}/>}
|
<Auth location={user? null : location.pathname}/>
|
||||||
</Route>
|
</Route>
|
||||||
<Route exact path="/passwordreset">
|
<Route exact path="/passwordreset">
|
||||||
{state.user? <NotFound/> : <Auth location={location.pathname}/>}
|
<Auth location={user? null : location.pathname}/>
|
||||||
</Route>
|
</Route>
|
||||||
|
|
||||||
<Route exact path="/games" component={Games}/>
|
<Route exact path="/games" component={Games}/>
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,8 @@ class Auth extends React.Component {
|
||||||
pageContent = (<ForgotPasswordForm />);
|
pageContent = (<ForgotPasswordForm />);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
pageLabel = (<><i className={`"fas fa-question-circle"`}></i> YOU'RE LOGGED IN!</>);
|
||||||
|
pageContent = (<div><div>Sorry, this page is for unauthenticated members only!</div></div>);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,15 +27,7 @@ Route::get('/banners/data', 'BannerController@getBanners');
|
||||||
|
|
||||||
Route::get('/games/metadata', 'GamesController@isAvailable');
|
Route::get('/games/metadata', 'GamesController@isAvailable');
|
||||||
|
|
||||||
Route::post('/fetch/user', function(){
|
Route::post('/fetch/user', 'Controller@fetchUser');
|
||||||
$cookie;
|
|
||||||
if (!isset($_COOKIE['gtok'])) {return Response()->json(false);}
|
|
||||||
$cookie = $_COOKIE['gtok'];
|
|
||||||
$user = User::where('token', $cookie)->first();
|
|
||||||
$array = $user->toArray();
|
|
||||||
if (!$user) {return Response()->json(false);}
|
|
||||||
return Response()->json(["data"=>$array]);
|
|
||||||
});
|
|
||||||
|
|
||||||
Route::post('/maintenance/bypass', 'MaintenanceController@bypass');
|
Route::post('/maintenance/bypass', 'MaintenanceController@bypass');
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue