last minute touches
This commit is contained in:
parent
3ad60c24b7
commit
dcc90a5896
|
|
@ -8,6 +8,7 @@ use App\Models\User;
|
|||
use Illuminate\Foundation\Auth\RegistersUsers;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Carbon;
|
||||
use Request;
|
||||
use Auth;
|
||||
|
||||
|
|
@ -90,6 +91,7 @@ class RegisterController extends Controller
|
|||
$user->email = $data['email'];
|
||||
$user->password = Hash::make($data['password']);
|
||||
$user->token = $sc;
|
||||
$user->token_expires = Carbon\Carbon::now()->addDays(2);
|
||||
$user->save();
|
||||
|
||||
Request::session()->regenerate();
|
||||
|
|
|
|||
|
|
@ -11,12 +11,15 @@ use App\Models\User;
|
|||
use App\Models\Category;
|
||||
use App\Models\Post;
|
||||
use App\Models\Reply;
|
||||
use App\Models\Staff;
|
||||
use Illuminate\Foundation\Auth\RegistersUsers;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
use Carbon;
|
||||
use Auth;
|
||||
use Request;
|
||||
use DateTime;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
|
|
@ -34,35 +37,32 @@ class Controller extends BaseController
|
|||
|
||||
$array = $user->toArray();
|
||||
|
||||
if ($user->Staff()) $array['power'] = $user->Staff()->power_level;
|
||||
$staff = Staff::where('user_id', $user->id)->first();
|
||||
|
||||
if ($staff) {$array['power'] = $staff->power_level;}
|
||||
|
||||
return Response()->json(["data"=>$array]);
|
||||
}
|
||||
|
||||
public function fetchCategoriesFP() {
|
||||
if (!isset($_COOKIE['gtok'])) {return Response()->json(["error"=>"No user."]);}
|
||||
|
||||
$POST = $_COOKIE['gtok'];
|
||||
if (!isset($_POST['token'])) {return Response()->json(["error"=>"No user."]);}
|
||||
|
||||
$POST = $_POST['token'];
|
||||
|
||||
$user = User::where('token', $POST)->first();
|
||||
|
||||
if (!$user) {return Response()->json(["error"=>"No user."]);}
|
||||
|
||||
if ($user->Staff() && $user->Staff()->power_level >= 2) {$categories = Category::get();}else{$categories = Category::where('staffOnly', '0')->get();}
|
||||
$staff = Staff::where('user_id', $user->id)->first();
|
||||
|
||||
if ($staff) {$categories = Category::get();}else{$categories = Category::where('staffOnly', '0')->get();}
|
||||
|
||||
return Response()->json(["categories"=>$categories]);
|
||||
}
|
||||
|
||||
public function fetchCategories() {
|
||||
|
||||
if (!isset($_COOKIE['gtok'])) {return Response()->json(["error"=>"No user."]);}
|
||||
|
||||
$POST = $_COOKIE['gtok'];
|
||||
|
||||
$user = User::where('token', $POST)->first();
|
||||
|
||||
if (!$user) {return Response()->json(["error"=>"No user."]);}
|
||||
|
||||
$categories = Category::orderBy('staffOnly', 'desc')->get();
|
||||
|
||||
return Response()->json(["categories"=>$categories]);
|
||||
|
|
@ -155,6 +155,14 @@ class Controller extends BaseController
|
|||
|
||||
Request::session()->regenerate();
|
||||
|
||||
$prws = array_merge(range('a', 'z'), range('A', 'Z'), range(0, 8));
|
||||
shuffle($prws);
|
||||
$sc = substr(implode($prws), 0, 56);
|
||||
|
||||
$user->token = $sc;
|
||||
$user->token_expires = Carbon\Carbon::now()->addDays(2);
|
||||
$user->save();
|
||||
|
||||
setcookie('gtok', $user->token, time()+(345600*30), "/", $_POST['host']);
|
||||
|
||||
Auth::login($user);
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use App\Models\User;
|
|||
use App\Models\Post;
|
||||
use App\Models\Reply;
|
||||
use App\Models\Category;
|
||||
use App\Models\Staff;
|
||||
use Illuminate\Foundation\Auth\RegistersUsers;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
|
@ -64,7 +65,9 @@ class HomeController extends Controller
|
|||
|
||||
$category = Category::where('id', $categoryId)->first();
|
||||
|
||||
if ($category->staffOnly == '1' && !$user->Staff()) {return Response()->json(['message'=>'You cant use that category.', 'badInputs'=>['category']]);}
|
||||
$staff = Staff::where('user_id', $user->id)->first();
|
||||
|
||||
if ($category->staffOnly == '1' && !$staff) {return Response()->json(['message'=>'You cant use that category.', 'badInputs'=>['category']]);}
|
||||
|
||||
$post = new Post;
|
||||
$post->title = $_POST['title'];
|
||||
|
|
@ -113,6 +116,8 @@ class HomeController extends Controller
|
|||
$reply->creator_id = $user->id;
|
||||
$post->replies()->save($reply);
|
||||
|
||||
$post->touch();
|
||||
|
||||
return Response()->json(['message'=>'Success!', 'badInputs'=>[], 'post_id'=>$post->id]);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ class CreateUsersTable extends Migration
|
|||
$table->timestamp('email_verified_at')->default(null);
|
||||
$table->string('password');
|
||||
$table->string('token');
|
||||
$table->timestamp('token_expires');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,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';
|
||||
import { getCookie, setCookie } from '../helpers/utils.js';
|
||||
import Dashboard from '../pages/Dashboard.js';
|
||||
import Forum from '../pages/Forum.js';
|
||||
import Post from '../pages/Post.js';
|
||||
|
|
@ -43,6 +43,7 @@ const App = () => {
|
|||
|
||||
const [state, setState] = useState({maintenance: false, theme: 0, banners: [], offlineFetch: false, loading: true});
|
||||
const [user, setUser] = useState([]);
|
||||
const [userLoad, setUserLoad] = useState(true);
|
||||
|
||||
function updateBanners()
|
||||
{
|
||||
|
|
@ -60,7 +61,9 @@ const App = () => {
|
|||
const body = new FormData();
|
||||
body.append('token', encodeURIComponent(getCookie(`gtok`)));
|
||||
axios.post(`${protocol}apis.${url}/fetch/user`, body).then((res)=>{
|
||||
if (res.data.data == `expired`) {setCookie(`gtok`, null, null);window.location.replace(`/login`);}
|
||||
setUser(res.data.data);
|
||||
setUserLoad(false);
|
||||
});
|
||||
return new Promise(async (resolve, reject)=>{
|
||||
resolve("good");
|
||||
|
|
@ -112,7 +115,7 @@ const App = () => {
|
|||
document.documentElement.classList.remove(!(state.theme == 0) ? 'gtoria-light' : 'gtoria-dark');
|
||||
|
||||
return (
|
||||
!state.loading?
|
||||
!state.loading && !userLoad?
|
||||
<Router>
|
||||
<GuardProvider guards={[authMiddleware]}>
|
||||
<Navbar maintenanceEnabled={state.maintenance} user={user} />
|
||||
|
|
|
|||
|
|
@ -27,7 +27,9 @@ const CreatePost = (props) => {
|
|||
const history = useHistory();
|
||||
|
||||
useEffect(async()=>{
|
||||
await axios.get(`${protocol}apis.${url}/fetch/categories/post`, null, {headers: {'X-CSRF-TOKEN': document.querySelector(`meta[name="csrf-token"]`).content, "X-Requested-With":"XMLHttpRequest"}}).then(data=>{
|
||||
const body = new FormData();
|
||||
body.append('token', encodeURIComponent(getCookie(`gtok`)));
|
||||
await axios.post(`${protocol}apis.${url}/fetch/categories/post`, body, {headers: {'X-CSRF-TOKEN': document.querySelector(`meta[name="csrf-token"]`).content, "X-Requested-With":"XMLHttpRequest"}}).then(data=>{
|
||||
const res = data.data;
|
||||
setCategoires({loading: false, categories: res.categories});
|
||||
}).catch(error=>{console.log(error);});
|
||||
|
|
|
|||
|
|
@ -85,7 +85,8 @@ const Post = (props) => {
|
|||
{post.replies.replies.length <= 0 && post.post.locked != 1? <p className={`w-100 text-center`}>There isn't any replies to this post yet!</p> : null}
|
||||
<div className={`flex column w-100`}>
|
||||
{post.replies.replies.map(reply=>(
|
||||
<Card>
|
||||
<div className={`mb-15`}>
|
||||
<Card>
|
||||
<div className={`flex w-100 column`}>
|
||||
<div className={`flex row fs12`}>
|
||||
<div className={`row w-fit-content`}>
|
||||
|
|
@ -105,6 +106,7 @@ const Post = (props) => {
|
|||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ Route::get('/games/metadata', 'GamesController@isAvailable');
|
|||
|
||||
Route::get('/fetch/categories', 'Controller@fetchCategories');
|
||||
|
||||
Route::get('/fetch/categories/post', 'Controller@fetchCategoriesFP');
|
||||
Route::post('/fetch/categories/post', 'Controller@fetchCategoriesFP');
|
||||
|
||||
Route::get('/fetch/category/{id}', 'Controller@fetchCategory');
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue