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;
|
||||
|
||||
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) {
|
||||
|
||||
$data = Request::all();
|
||||
|
|
@ -46,6 +63,8 @@ class Controller extends BaseController
|
|||
|
||||
Request::session()->regenerate();
|
||||
|
||||
setcookie('gtok', $user->token, time()+(345600*30), "/");
|
||||
|
||||
Auth::login($user);
|
||||
|
||||
return Response()->json('good');
|
||||
|
|
|
|||
|
|
@ -5,6 +5,42 @@ import { useEffect } from 'react';
|
|||
|
||||
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) {
|
||||
useEffect(
|
||||
() => {
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import { About } from '../Pages/Legal/About.js';
|
|||
import { Copyright } from '../Pages/Legal/Copyright.js';
|
||||
import { Privacy } from '../Pages/Legal/Privacy.js';
|
||||
import { Terms } from '../Pages/Legal/Terms.js';
|
||||
import { getCookie } from '../helpers/utils.js';
|
||||
|
||||
axios.defaults.withCredentials = true
|
||||
|
||||
|
|
@ -34,8 +35,8 @@ var protocol = Config.Protocol;
|
|||
|
||||
const App = () => {
|
||||
|
||||
const [state, setState] = useState({maintenance: false, theme: 0, banners: [], offlineFetch: false, user: []});
|
||||
var finished = false;
|
||||
const [state, setState] = useState({maintenance: false, theme: 0, banners: [], offlineFetch: false, loading: true});
|
||||
const [user, setUser] = useState([]);
|
||||
|
||||
function updateBanners()
|
||||
{
|
||||
|
|
@ -50,9 +51,14 @@ const App = () => {
|
|||
}
|
||||
|
||||
function fetchUser() {
|
||||
axios.post(`${protocol}apis.${url}/fetch/user`).then((res)=>{
|
||||
setState({user: res.data.data}, (e)=>{console.log(state.user)});
|
||||
const body = new FormData();
|
||||
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");
|
||||
});
|
||||
}
|
||||
|
||||
function updateOfflineStatus()
|
||||
|
|
@ -80,13 +86,14 @@ const App = () => {
|
|||
updateOfflineStatus();
|
||||
setInterval(updateBanners, 2*60*1000 /* 2 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.remove(!(state.theme == 0) ? 'gtoria-light' : 'gtoria-dark');
|
||||
|
||||
return (
|
||||
state.offlineFetched == true ?
|
||||
!state.loading?
|
||||
<Router>
|
||||
<Navbar maintenanceEnabled={state.maintenance} />
|
||||
{state.banners && state.banners.length >= 1 ? state.banners : null}
|
||||
|
|
@ -109,13 +116,13 @@ const App = () => {
|
|||
<Route exact path="/" component={Home}/>
|
||||
|
||||
<Route exact path="/login">
|
||||
{state.user? <NotFound/> : <Auth location={location.pathname}/>}
|
||||
<Auth location={user && user.id? null : location.pathname}/>
|
||||
</Route>
|
||||
<Route exact path="/register">
|
||||
{state.user? <NotFound/> : <Auth location={location.pathname}/>}
|
||||
<Auth location={user? null : location.pathname}/>
|
||||
</Route>
|
||||
<Route exact path="/passwordreset">
|
||||
{state.user? <NotFound/> : <Auth location={location.pathname}/>}
|
||||
<Auth location={user? null : location.pathname}/>
|
||||
</Route>
|
||||
|
||||
<Route exact path="/games" component={Games}/>
|
||||
|
|
|
|||
|
|
@ -48,6 +48,8 @@ class Auth extends React.Component {
|
|||
pageContent = (<ForgotPasswordForm />);
|
||||
break;
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,15 +27,7 @@ Route::get('/banners/data', 'BannerController@getBanners');
|
|||
|
||||
Route::get('/games/metadata', 'GamesController@isAvailable');
|
||||
|
||||
Route::post('/fetch/user', function(){
|
||||
$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('/fetch/user', 'Controller@fetchUser');
|
||||
|
||||
Route::post('/maintenance/bypass', 'MaintenanceController@bypass');
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue