forked from ppfun/pixelplanet
fix error handling of passport
fix a few lsint errors
This commit is contained in:
parent
8cadbbdac1
commit
9493172034
|
@ -39,11 +39,18 @@ const Admin = () => (
|
|||
</form>
|
||||
);
|
||||
|
||||
const data = {
|
||||
title: 'PixelPlanet.fun AdminTools',
|
||||
description: 'admin access on pixelplanet',
|
||||
body: <Admin />,
|
||||
};
|
||||
const adminHtml = `<!doctype html>${ReactDOM.renderToStaticMarkup(<Html {...data} />)}`;
|
||||
const title = 'PixelPlanet.fun AdminTools';
|
||||
const description = 'admin access on pixelplanet';
|
||||
const body = <Admin />;
|
||||
|
||||
const adminHtml = `<!doctype html>${
|
||||
ReactDOM.renderToStaticMarkup(
|
||||
<Html
|
||||
title={title}
|
||||
description={description}
|
||||
body={body}
|
||||
/>,
|
||||
)
|
||||
}`;
|
||||
|
||||
export default adminHtml;
|
||||
|
|
|
@ -10,18 +10,23 @@ import Html from './Html';
|
|||
const RedirectionPage = ({ text, host }) => (
|
||||
<div>
|
||||
<h3>{text}</h3>
|
||||
<p>You will be automatically redirected after 5s</p>
|
||||
<p>You will be automatically redirected after 15s</p>
|
||||
<p>Or <a href={host}>Click here</a> to go back to pixelplanet</p>
|
||||
</div>
|
||||
);
|
||||
|
||||
export function getHtml(description, text, host) {
|
||||
const data = {
|
||||
title: 'PixelPlanet.fun Accounts',
|
||||
description,
|
||||
body: <RedirectionPage text={text} host={host} />,
|
||||
code: `window.setTimeout(function(){window.location.href="${host}";},4000)`,
|
||||
};
|
||||
const index = `<!doctype html>${ReactDOM.renderToStaticMarkup(<Html {...data} />)}`;
|
||||
function getHtml(description, text, host) {
|
||||
const title = 'PixelPlanet.fun Accounts';
|
||||
const body = <RedirectionPage text={text} host={host} />;
|
||||
// eslint-disable-next-line max-len
|
||||
const code = `window.setTimeout(function(){window.location.href="${host}";},15000)`;
|
||||
|
||||
const index = `<!doctype html>${
|
||||
ReactDOM.renderToStaticMarkup(
|
||||
<Html title={title} description={description} body={body} code={code} />,
|
||||
)
|
||||
}`;
|
||||
return index;
|
||||
}
|
||||
|
||||
export default getHtml;
|
||||
|
|
|
@ -25,7 +25,7 @@ import change_mail from './change_mail';
|
|||
import restore_password from './restore_password';
|
||||
import mclink from './mclink';
|
||||
|
||||
import { getHtml } from '../../../components/RedirectionPage';
|
||||
import getHtml from '../../../components/RedirectionPage';
|
||||
|
||||
import getMe from '../../../core/me';
|
||||
|
||||
|
@ -36,61 +36,83 @@ export default (passport) => {
|
|||
|
||||
router.get('/facebook', passport.authenticate('facebook',
|
||||
{ scope: ['email'] }));
|
||||
router.get('/facebook/return', passport.authenticate('facebook', {
|
||||
failureRedirect: '/api/auth/failure',
|
||||
failureFlash: true,
|
||||
successRedirect: '/',
|
||||
}));
|
||||
router.get('/facebook/return', (req: Request, res: Response, next) => {
|
||||
passport.authenticate('facebook', (err, user, info) => {
|
||||
if (err) return next(err);
|
||||
if (!user) return next(new Error(info.message));
|
||||
req.logIn(user, (error) => {
|
||||
if (error) return next(error);
|
||||
return res.redirect('/');
|
||||
});
|
||||
return null;
|
||||
})(req, res, next);
|
||||
});
|
||||
|
||||
router.get('/discord', passport.authenticate('discord',
|
||||
{ scope: ['identify', 'email'] }));
|
||||
router.get('/discord/return', passport.authenticate('discord', {
|
||||
failureRedirect: '/api/auth/failure',
|
||||
failureFlash: true,
|
||||
successRedirect: '/',
|
||||
}));
|
||||
router.get('/discord/return', (req: Request, res: Response, next) => {
|
||||
passport.authenticate('discord', (err, user, info) => {
|
||||
if (err) return next(err);
|
||||
if (!user) return next(new Error(info.message));
|
||||
req.logIn(user, (error) => {
|
||||
if (error) return next(error);
|
||||
return res.redirect('/');
|
||||
});
|
||||
return null;
|
||||
})(req, res, next);
|
||||
});
|
||||
|
||||
router.get('/google', passport.authenticate('google',
|
||||
{ scope: ['email', 'profile'] }));
|
||||
router.get('/google/return', passport.authenticate('google', {
|
||||
failureRedirect: '/api/auth/failure',
|
||||
failureFlash: true,
|
||||
successRedirect: '/',
|
||||
}));
|
||||
router.get('/google/return', (req: Request, res: Response, next) => {
|
||||
passport.authenticate('google', (err, user, info) => {
|
||||
if (err) return next(err);
|
||||
if (!user) return next(new Error(info.message));
|
||||
req.logIn(user, (error) => {
|
||||
if (error) return next(error);
|
||||
return res.redirect('/');
|
||||
});
|
||||
return null;
|
||||
})(req, res, next);
|
||||
});
|
||||
|
||||
router.get('/vk', passport.authenticate('vkontakte',
|
||||
{ scope: ['email'] }));
|
||||
router.get('/vk/return', passport.authenticate('vkontakte', {
|
||||
failureRedirect: '/api/auth/failure',
|
||||
failureFlash: true,
|
||||
successRedirect: '/',
|
||||
}));
|
||||
router.get('/vk/return', (req: Request, res: Response, next) => {
|
||||
passport.authenticate('vkontakte', (err, user, info) => {
|
||||
if (err) return next(err);
|
||||
if (!user) return next(new Error(info.message));
|
||||
req.logIn(user, (error) => {
|
||||
if (error) return next(error);
|
||||
return res.redirect('/');
|
||||
});
|
||||
return null;
|
||||
})(req, res, next);
|
||||
});
|
||||
|
||||
router.get('/reddit', passport.authenticate('reddit',
|
||||
{ duration: 'temporary', state: 'foo' }));
|
||||
router.get('/reddit/return', passport.authenticate('reddit', {
|
||||
failureRedirect: '/api/auth/failure',
|
||||
failureFlash: true,
|
||||
successRedirect: '/',
|
||||
}));
|
||||
router.get('/reddit/return', (req: Request, res: Response, next) => {
|
||||
passport.authenticate('reddit', (err, user, info) => {
|
||||
if (err) return next(err);
|
||||
if (!user) return next(new Error(info.message));
|
||||
req.logIn(user, (error) => {
|
||||
if (error) return next(error);
|
||||
return res.redirect('/');
|
||||
});
|
||||
return null;
|
||||
})(req, res, next);
|
||||
});
|
||||
|
||||
router.get('/failure', (req: Request, res: Response) => {
|
||||
res.set({
|
||||
'Content-Type': 'text/html',
|
||||
});
|
||||
let text = null;
|
||||
if (req.session && req.session.flash) {
|
||||
// eslint-disable-next-line prefer-destructuring
|
||||
text = req.session.flash.error[0];
|
||||
req.session.flash = {};
|
||||
router.use((err, req, res, next) => {
|
||||
if (err) {
|
||||
const host = getHostFromRequest(req);
|
||||
logger.info(`Authentification error ${err}`);
|
||||
const index = getHtml('OAuth Authentification', err.message, host);
|
||||
res.status(400).send(index);
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
if (!text) {
|
||||
// eslint-disable-next-line max-len
|
||||
text = 'LogIn failed :(, please try again later or register a new account with mail.';
|
||||
}
|
||||
const host = getHostFromRequest(req);
|
||||
const index = getHtml('OAuth Authentification', text, host);
|
||||
res.status(200).send(index);
|
||||
});
|
||||
|
||||
router.get('/verify', verify);
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
import type { Request, Response } from 'express';
|
||||
|
||||
import webSockets from '../../../socket/websockets';
|
||||
import { getHtml } from '../../../components/RedirectionPage';
|
||||
import getHtml from '../../../components/RedirectionPage';
|
||||
import { getHostFromRequest } from '../../../utils/ip';
|
||||
import mailProvider from '../../../core/mail';
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user