parent
3044b985b1
commit
bf8fb35c1a
|
|
@ -28,18 +28,35 @@ class Controller extends BaseController
|
||||||
public function fetchUser() {
|
public function fetchUser() {
|
||||||
$POST;
|
$POST;
|
||||||
|
|
||||||
if (!isset($_POST['token'])) {return Response()->json(false);}
|
if (!isset($_POST['decision'])) {return Response()->json(false);}
|
||||||
|
|
||||||
$POST = $_POST['token'];
|
$decision = $_POST['decision'];
|
||||||
$user = User::where('token', $POST)->first();
|
|
||||||
|
|
||||||
if (!$user) {return Response()->json(false);}
|
switch($decision) {
|
||||||
|
case "metaUser":
|
||||||
$array = $user->toArray();
|
if (!isset($_POST['token'])) {return Response()->json(false);}
|
||||||
|
$POST = $_POST['token'];
|
||||||
$staff = Staff::where('user_id', $user->id)->first();
|
$user = User::where('token', $POST)->first();
|
||||||
|
if (!$user) {return Response()->json(false);}
|
||||||
if ($staff) {$array['power'] = $staff->power_level;}
|
$array = $user->toArray();
|
||||||
|
$staff = Staff::where('user_id', $user->id)->first();
|
||||||
|
if ($staff) {$array['power'] = $staff->power_level;}
|
||||||
|
return Response()->json(["data"=>$array]);
|
||||||
|
break;
|
||||||
|
case "fetchedUser":
|
||||||
|
if (!isset($_POST['userId'])) {return Response()->json(false);}
|
||||||
|
$POST = $_POST['userId'];
|
||||||
|
$user = User::where('id', $POST)->first();
|
||||||
|
if (!$user) {return Response()->json(false);}
|
||||||
|
$array = $user->toArray();
|
||||||
|
$staff = Staff::where('user_id', $user->id)->first();
|
||||||
|
if ($staff) {$array['power'] = $staff->power_level;}
|
||||||
|
return Response()->json(["data"=>$array]);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return Response()->json(false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return Response()->json(["data"=>$array]);
|
return Response()->json(["data"=>$array]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ import Post from '../pages/Post.js';
|
||||||
import CreatePost from '../pages/CreatePost.js';
|
import CreatePost from '../pages/CreatePost.js';
|
||||||
import CreateReply from '../pages/CreateReply.js';
|
import CreateReply from '../pages/CreateReply.js';
|
||||||
import Settings from '../pages/Settings.js';
|
import Settings from '../pages/Settings.js';
|
||||||
|
import User from '../pages/User.js';
|
||||||
|
|
||||||
axios.defaults.withCredentials = true
|
axios.defaults.withCredentials = true
|
||||||
|
|
||||||
|
|
@ -61,6 +62,7 @@ const App = () => {
|
||||||
function fetchUser() {
|
function fetchUser() {
|
||||||
const body = new FormData();
|
const body = new FormData();
|
||||||
body.append('token', encodeURIComponent(getCookie(`gtok`)));
|
body.append('token', encodeURIComponent(getCookie(`gtok`)));
|
||||||
|
body.append('decision', `metaUser`);
|
||||||
axios.post(`${protocol}apis.${url}/fetch/user`, body).then((res)=>{
|
axios.post(`${protocol}apis.${url}/fetch/user`, body).then((res)=>{
|
||||||
if (res.data.data == `expired`) {setCookie(`gtok`, null, null);window.location.replace(`/login`);}
|
if (res.data.data == `expired`) {setCookie(`gtok`, null, null);window.location.replace(`/login`);}
|
||||||
setUser(res.data.data);
|
setUser(res.data.data);
|
||||||
|
|
@ -136,6 +138,10 @@ const App = () => {
|
||||||
<Route exact path="/legal/privacy-policy" component={Privacy}/>
|
<Route exact path="/legal/privacy-policy" component={Privacy}/>
|
||||||
<Route exact path="/legal/terms-of-service" component={Terms}/>
|
<Route exact path="/legal/terms-of-service" component={Terms}/>
|
||||||
{state.maintenance ? <Route path="*" component={Maintenance}/> : null}
|
{state.maintenance ? <Route path="*" component={Maintenance}/> : null}
|
||||||
|
|
||||||
|
<Route exact path="/user/:id">
|
||||||
|
<User user={user}/>
|
||||||
|
</Route>
|
||||||
|
|
||||||
<GuardedRoute exact path="/" meta={{guest: true}}>
|
<GuardedRoute exact path="/" meta={{guest: true}}>
|
||||||
<Home user={user}/>
|
<Home user={user}/>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,65 @@
|
||||||
|
// © XlXi 2021
|
||||||
|
// Graphictoria 5
|
||||||
|
|
||||||
|
import axios from 'axios';
|
||||||
|
import React, { useEffect, useState } from "react";
|
||||||
|
import { Link, useHistory, useParams } from "react-router-dom";
|
||||||
|
|
||||||
|
import Config from '../config.js';
|
||||||
|
|
||||||
|
import SetTitle from "../Helpers/Title.js";
|
||||||
|
|
||||||
|
import Loader from '../Components/Loader.js';
|
||||||
|
|
||||||
|
import { GenericErrorModal } from './Errors.js';
|
||||||
|
import { Card, CardTitle } from '../Layouts/Card.js';
|
||||||
|
|
||||||
|
var url = Config.BaseUrl.replace('http://', '');
|
||||||
|
var protocol = Config.Protocol;
|
||||||
|
|
||||||
|
const User = (props) => {
|
||||||
|
|
||||||
|
const [state, setState] = useState(true);
|
||||||
|
const [user, setUser] = useState();
|
||||||
|
const metaUser = props.user;
|
||||||
|
const userId = useParams().id;
|
||||||
|
const history = useHistory();
|
||||||
|
|
||||||
|
const fetchUser = async () => {
|
||||||
|
const body = new FormData();
|
||||||
|
body.append('userId', userId);
|
||||||
|
body.append('decision', `fetchedUser`);
|
||||||
|
axios.post(`${protocol}apis.${url}/fetch/user`, body).then(async(data)=>{
|
||||||
|
const res = data.data;
|
||||||
|
if (!res) {history.push(`/`);}
|
||||||
|
SetTitle(`${res.data.username}`);
|
||||||
|
await setUser(res.data);
|
||||||
|
return;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(async()=>{
|
||||||
|
await fetchUser();
|
||||||
|
setState(false);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
!user
|
||||||
|
?
|
||||||
|
<Loader />
|
||||||
|
:
|
||||||
|
<div className={`row`}>
|
||||||
|
<div className={`col`}>
|
||||||
|
<Card className={`justify-content-center`} padding={true}>
|
||||||
|
<CardTitle>{user.username}</CardTitle>
|
||||||
|
<p>[Avatar.]</p>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
<div className={`col justify-content-center`}>
|
||||||
|
<p>"{user.about? user.about : `${user.username} doesn't have an about section!`}" - {user.username}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default User;
|
||||||
Loading…
Reference in New Issue