not finished yet
note for me: get auth token system finished.
This commit is contained in:
parent
766d3a6aef
commit
8577b0aca9
|
|
@ -84,16 +84,24 @@ class RegisterController extends Controller
|
|||
$messages = $valid->messages()->get('*');
|
||||
return Response()->json(['message'=>$error, 'badInputs'=>[array_keys($messages)]]);
|
||||
}
|
||||
|
||||
$prws = array_merge(range('a', 'z'), range('A', 'Z'), range(0, 8));
|
||||
shuffle($prws);
|
||||
$sc = substr(implode($prws), 0, 56);
|
||||
|
||||
$user = new User;
|
||||
$user->username = $data['username'];
|
||||
$user->email = $data['email'];
|
||||
$user->password = Hash::make($data['password']);
|
||||
$user->token = $sc;
|
||||
$user->save();
|
||||
|
||||
Auth::login($user);
|
||||
Request::session()->regenerate();
|
||||
|
||||
Auth::login($user);
|
||||
|
||||
setcookie('gtok', $sc, time()+(345600*30), "/");
|
||||
|
||||
return Response()->json('good');
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,4 +39,5 @@ class BannerController extends Controller
|
|||
return response($content)
|
||||
->header('Content-Type', 'application/json');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,11 +19,6 @@ class Controller extends BaseController
|
|||
{
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest');
|
||||
}
|
||||
|
||||
public function login(Request $request) {
|
||||
|
||||
$data = Request::all();
|
||||
|
|
@ -42,6 +37,8 @@ class Controller extends BaseController
|
|||
if (!User::where('username', Request::input('username'))->first()) {
|
||||
return Response()->json(['message'=>"Sorry, that user wasn't found!", 'badInputs'=>['username']]);
|
||||
}
|
||||
|
||||
$user = User::where('username', Request::input('username'))->first();
|
||||
|
||||
if (!Auth::attempt(Request::only('username', 'password'))) {
|
||||
return Response()->json(['message'=>'Sorry, thats the wrong password!', 'badInputs'=>['password']]);
|
||||
|
|
@ -49,6 +46,8 @@ class Controller extends BaseController
|
|||
|
||||
Request::session()->regenerate();
|
||||
|
||||
Auth::login($user);
|
||||
|
||||
return Response()->json('good');
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ class Kernel extends HttpKernel
|
|||
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
||||
\App\Http\Middleware\TrimStrings::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
|
||||
\Illuminate\Session\Middleware\StartSession::class
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ class User extends Authenticatable
|
|||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
'token',
|
||||
'email'
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ class CreateUsersTable extends Migration
|
|||
$table->string('email');
|
||||
$table->timestamp('email_verified_at')->default(null);
|
||||
$table->string('password');
|
||||
$table->string('token');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import 'bootstrap';
|
|||
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import App from '../layouts/App.js';
|
||||
|
||||
function Main() {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ export function CreateAccount(form)
|
|||
var badInputs = [];
|
||||
|
||||
return new Promise(async (resolve, reject)=>{
|
||||
await axios.post(`${protocol}apis.${url}/account/register`, body, {headers: {'X-CSRF-TOKEN': document.querySelector(`meta[name="csrf-token"]`).content}}).then(data=>{
|
||||
await axios.post(`${protocol}apis.${url}/account/register`, body, {headers: {'X-CSRF-TOKEN': document.querySelector(`meta[name="csrf-token"]`).content, "X-Requested-With":"XMLHttpRequest"}}).then(data=>{
|
||||
const res = data.data;
|
||||
if (res.badInputs.length >= 1) {
|
||||
badInputs=res.badInputs;
|
||||
|
|
@ -35,7 +35,7 @@ export function LoginToAccount(form) {
|
|||
|
||||
return new Promise(async (resolve, reject)=>{
|
||||
|
||||
await axios.post(`${protocol}apis.${url}/account/login`, body, {headers: {'X-CSRF-TOKEN': document.querySelector(`meta[name="csrf-token"]`).content}}).then(data=>{
|
||||
await axios.post(`${protocol}apis.${url}/account/login`, body, {headers: {'X-CSRF-TOKEN': document.querySelector(`meta[name="csrf-token"]`).content, "X-Requested-With":"XMLHttpRequest"}}).then(data=>{
|
||||
const res = data.data;
|
||||
if (res.badInputs.length >= 1) {
|
||||
badInputs=res.badInputs;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,9 @@
|
|||
|
||||
import { useEffect } from 'react';
|
||||
|
||||
function useOnClickOutside(refs, handler) {
|
||||
export var user;
|
||||
|
||||
export function useOnClickOutside(refs, handler) {
|
||||
useEffect(
|
||||
() => {
|
||||
const listener = (event) => {
|
||||
|
|
@ -36,7 +38,3 @@ function useOnClickOutside(refs, handler) {
|
|||
[refs, handler]
|
||||
);
|
||||
}
|
||||
|
||||
export {
|
||||
useOnClickOutside
|
||||
};
|
||||
|
|
@ -34,7 +34,8 @@ var protocol = Config.Protocol;
|
|||
|
||||
const App = () => {
|
||||
|
||||
const [state, setState] = useState({maintenance: false, theme: 0, banners: [], offlineFetch: false});
|
||||
const [state, setState] = useState({maintenance: false, theme: 0, banners: [], offlineFetch: false, user: []});
|
||||
var finished = false;
|
||||
|
||||
function updateBanners()
|
||||
{
|
||||
|
|
@ -47,6 +48,12 @@ const App = () => {
|
|||
setState({banners: result});
|
||||
});
|
||||
}
|
||||
|
||||
function fetchUser() {
|
||||
axios.post(`${protocol}apis.${url}/fetch/user`).then((res)=>{
|
||||
setState({user: res.data.data}, (e)=>{console.log(state.user)});
|
||||
});
|
||||
}
|
||||
|
||||
function updateOfflineStatus()
|
||||
{
|
||||
|
|
@ -67,13 +74,12 @@ const App = () => {
|
|||
});
|
||||
}
|
||||
|
||||
useEffect(()=>{
|
||||
|
||||
useEffect(async ()=>{
|
||||
await fetchUser();
|
||||
updateBanners();
|
||||
updateOfflineStatus();
|
||||
setInterval(updateBanners, 2*60*1000 /* 2 mins */);
|
||||
setInterval(updateOfflineStatus, 10*60*1000 /* 10 mins */);
|
||||
console.log(state);
|
||||
}, []);
|
||||
|
||||
document.documentElement.classList.add(state.theme == 0 ? 'gtoria-light' : 'gtoria-dark');
|
||||
|
|
@ -103,13 +109,13 @@ const App = () => {
|
|||
<Route exact path="/" component={Home}/>
|
||||
|
||||
<Route exact path="/login">
|
||||
<Auth location={location.pathname}/>
|
||||
{state.user? <NotFound/> : <Auth location={location.pathname}/>}
|
||||
</Route>
|
||||
<Route exact path="/register">
|
||||
<Auth location={location.pathname}/>
|
||||
{state.user? <NotFound/> : <Auth location={location.pathname}/>}
|
||||
</Route>
|
||||
<Route exact path="/passwordreset">
|
||||
<Auth location={location.pathname}/>
|
||||
{state.user? <NotFound/> : <Auth location={location.pathname}/>}
|
||||
</Route>
|
||||
|
||||
<Route exact path="/games" component={Games}/>
|
||||
|
|
|
|||
|
|
@ -21,9 +21,10 @@ const LoginForm = (props) => {
|
|||
if (res != `good`) {
|
||||
setValidity({error: true, message:res.message, inputs: res.inputs});
|
||||
setTimeout(()=>{setValidity({...validity, error: false, inputs: res.inputs});}, 4000);
|
||||
}else{
|
||||
window.history.pushState(`/home`);
|
||||
return;
|
||||
}
|
||||
window.history.pushState(`/home`);
|
||||
return;
|
||||
}).catch(error=>console.log(error));
|
||||
setWaitingForSubmission(false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,9 +45,10 @@ const RegisterForm = (props) => {
|
|||
if (res != `good`) {
|
||||
setValidity({error: true, message:res.message, inputs: res.inputs});
|
||||
setTimeout(()=>{setValidity({...validity, error: false, inputs: res.inputs});}, 4000);
|
||||
}else{
|
||||
window.history.pushState(`/home`);
|
||||
return;
|
||||
}
|
||||
window.history.pushState(`/home`);
|
||||
return;
|
||||
}).catch(error=>console.log(error));
|
||||
setWaitingForSubmission(false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import { Link } from "react-router-dom";
|
|||
import SetTitle from "../Helpers/Title.js";
|
||||
|
||||
import SocialCard from "../Components/Landing/SocialCard.js";
|
||||
import { user } from "../helpers/utils.js";
|
||||
|
||||
const Home = () => {
|
||||
useEffect(()=>{
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use App\Http\Controllers\BannerController;
|
|||
use App\Http\Controllers\GamesController;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\Auth\RegisterController;
|
||||
use App\Models\User;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
@ -26,6 +27,16 @@ 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('/maintenance/bypass', 'MaintenanceController@bypass');
|
||||
|
||||
Route::post('/account/register', 'Auth\RegisterController@create');
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ use Illuminate\Support\Facades\Route;
|
|||
|
||||
Route::get('/javascript', function(){
|
||||
return view('javascript');
|
||||
});
|
||||
})->middleware('auth');
|
||||
|
||||
Route::get('/', function(){
|
||||
return view('main');
|
||||
|
|
|
|||
Loading…
Reference in New Issue