Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 59 additions & 23 deletions src/components/flags/FlagsApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,36 +30,60 @@ class FlagsApi extends React.Component {

async handleClick(action) {
if (action === 'api') {
const res = await axios.get(api.url+'/api/flags/test');
this.props.dispatch(
{type : 'set', payload:
{ 'text' : res.data.message,
'flags' : res.data.flags,
'ques' : res.data.ques,
'answer' : res.data.answer,
'answerCode' : res.data.answerCode,
'counter' : this.props.counter,
'lifes' : this.props.lifes,
'lifesIcon' : this.props.lifesIcon,
'timer' : this.props.timer,
'interval' : this.props.interval,
'maxTimer' : this.props.maxTimer,
'sessionTimer' : this.props.sessionTimer,
'flagi' : res.data.flags,
try {
const res = await axios.get(api.url+'/api/flags/test');
this.props.dispatch(
{type : 'set', payload:
{ 'text' : res.data.message,
'flags' : res.data.flags,
'ques' : res.data.ques,
'answer' : res.data.answer,
'answerCode' : res.data.answerCode,
'counter' : this.props.counter,
'lifes' : this.props.lifes,
'lifesIcon' : this.props.lifesIcon,
'timer' : this.props.timer,
'interval' : this.props.interval,
'maxTimer' : this.props.maxTimer,
'sessionTimer' : this.props.sessionTimer,
'flagi' : res.data.flags,
}
}
);
} catch (err) {
if (err.response && err.response.status === 401) {
this.handleUnauthorized();
return;
}
);
throw err;
}
}

if (action === 'increment') {
this.props.dispatch({type : 'add'});
}

if (action === 'protected') {
const res = await axios.get(api.url+'/api/flags/protected');
try {
const res = await axios.get(api.url+'/api/flags/protected');
} catch (err) {
if (err.response && err.response.status === 401) {
this.handleUnauthorized();
return;
}
throw err;
}
}
}

handleUnauthorized = () => {
localStorage.removeItem('accessToken');
localStorage.removeItem('refreshToken');
localStorage.removeItem('tokenExpiresAt');
this.props.dispatch({type : 'reset'});
this.props.history.push('/');
}

async answer(action) {
if (this.props.lifes == 0) { return; }
if (this.answerLocked) { return; }
Expand All @@ -74,12 +98,19 @@ class FlagsApi extends React.Component {

if (action === this.props.answer) {
this.stopTimer();
await axios.post(api.url+'/api/flags/correct/'+this.props.answerCode);
try {
await axios.post(api.url+'/api/flags/correct/'+this.props.answerCode);
} catch (err) {
if (err.response && err.response.status === 401) {
this.handleUnauthorized();
return;
}
}
this.props.dispatch({type : 'correct' })
setTimeout(() => {
this.showFlags();
}, 1500);

} else {
this.showCorrect();
if (this.props.lifes == 1) {
Expand Down Expand Up @@ -225,10 +256,15 @@ class FlagsApi extends React.Component {
}
}

submitScore(score, sessionTimer) {
const res = axios.post(api.url+'/api/flags/scores', { 'score' : score, 'sessionTimer' : sessionTimer, 'answers' : this.answers });
async submitScore(score, sessionTimer) {
try {
await axios.post(api.url+'/api/flags/scores', { 'score' : score, 'sessionTimer' : sessionTimer, 'answers' : this.answers });
this.answers = [];
console.log(res);
} catch (err) {
if (err.response && err.response.status === 401) {
this.handleUnauthorized();
}
}
}

componentDidMount() {
Expand Down
14 changes: 9 additions & 5 deletions src/components/home/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,17 @@ const Home = () => {
<span>Flags Quiz</span>
<span className="footer-divider">|</span>
<span className="footer-version">{process.env.REACT_APP_VERSION || 'dev'}</span>
</div>
<div className="footer-center">
<span>Feedback: <a href="mailto:admin@izeebot.top">admin@izeebot.top</a></span>
</div>
<div className="footer-right">
<span className="footer-divider">|</span>
<span><a href="mailto:admin@izeebot.top">admin@izeebot.top</a></span>
<span className="footer-divider">|</span>
<span>&copy; {new Date().getFullYear()}</span>
</div>
{/*<div className="footer-right">*/}
{/* <span>Feedback: <a href="mailto:admin@izeebot.top">admin@izeebot.top</a></span>*/}
{/*</div>*/}
{/*<div className="footer-right">*/}
{/* */}
{/*</div>*/}
</div>
</Container>
</footer>
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useOAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const useOAuth = () => {

// Store expiration time if provided
if (expires_in) {
const expiresAt = Date.now() + (expires_in * 1000);
const expiresAt = Date.now() + (expires_in);
localStorage.setItem('tokenExpiresAt', expiresAt.toString());
}

Expand Down