Merge pull request #611 from coralproject/auth-flow

FE Auth Flow and fix for Safari token workaround
This commit is contained in:
Kim Gardner
2017-05-26 16:06:32 -04:00
committed by GitHub
36 changed files with 273 additions and 157 deletions
+5
View File
@@ -3,5 +3,10 @@ client/lib
**/*.html
plugins/*
!plugins/coral-plugin-facebook-auth
!plugins/coral-plugin-auth
!plugins/coral-plugin-respect
!plugins/coral-plugin-offtopic
!plugins/coral-plugin-like
!plugins/coral-plugin-mod
!plugins/coral-plugin-love
node_modules
+4
View File
@@ -11,6 +11,8 @@ const errors = require('./errors');
const {createGraphOptions} = require('./graph');
const apollo = require('graphql-server-express');
const accepts = require('accepts');
const compression = require('compression');
const cookieParser = require('cookie-parser');
const app = express();
@@ -31,6 +33,8 @@ app.set('trust proxy', 1);
app.use(helmet({
frameguard: false
}));
app.use(compression());
app.use(cookieParser());
app.use(bodyParser.json());
//==============================================================================
+1 -1
View File
@@ -8,7 +8,7 @@ import {
UPDATE_ASSETS
} from '../constants/assets';
import coralApi from '../../../coral-framework/helpers/response';
import coralApi from '../../../coral-framework/helpers/request';
/**
* Action disptacher related to assets
+23 -5
View File
@@ -1,5 +1,6 @@
import bowser from 'bowser';
import * as actions from '../constants/auth';
import coralApi from 'coral-framework/helpers/response';
import coralApi from 'coral-framework/helpers/request';
import * as Storage from 'coral-framework/helpers/storage';
import {handleAuthToken} from 'coral-framework/actions/auth';
@@ -9,16 +10,31 @@ import {handleAuthToken} from 'coral-framework/actions/auth';
export const handleLogin = (email, password, recaptchaResponse) => (dispatch) => {
dispatch({type: actions.LOGIN_REQUEST});
const params = {method: 'POST', body: {email, password}};
const params = {
method: 'POST',
body: {
email,
password
}
};
if (recaptchaResponse) {
params.headers = {'X-Recaptcha-Response': recaptchaResponse};
params.headers = {
'X-Recaptcha-Response': recaptchaResponse
};
}
return coralApi('/auth/local', params)
.then(({user, token}) => {
if (!user) {
Storage.removeItem('token');
if (!bowser.safari && !bowser.ios) {
Storage.removeItem('token');
}
return dispatch(checkLoginFailure('not logged in'));
}
dispatch(handleAuthToken(token));
dispatch(checkLoginSuccess(user));
})
@@ -83,7 +99,9 @@ export const checkLogin = () => (dispatch) => {
return coralApi('/auth')
.then(({user}) => {
if (!user) {
Storage.removeItem('token');
if (!bowser.safari && !bowser.ios) {
Storage.removeItem('token');
}
return dispatch(checkLoginFailure('not logged in'));
}
+1 -1
View File
@@ -14,7 +14,7 @@ import {
HIDE_SUSPENDUSER_DIALOG
} from '../constants/community';
import coralApi from '../../../coral-framework/helpers/response';
import coralApi from '../../../coral-framework/helpers/request';
export const fetchAccounts = (query = {}) => (dispatch) => {
+1 -1
View File
@@ -1,4 +1,4 @@
import coralApi from 'coral-framework/helpers/response';
import coralApi from 'coral-framework/helpers/request';
import * as actions from '../constants/install';
import validate from 'coral-framework/helpers/validate';
import errorMsj from 'coral-framework/helpers/error';
+1 -1
View File
@@ -1,4 +1,4 @@
import coralApi from '../../../coral-framework/helpers/response';
import coralApi from '../../../coral-framework/helpers/request';
export const SETTINGS_LOADING = 'SETTINGS_LOADING';
export const SETTINGS_RECEIVED = 'SETTINGS_RECEIVED';
+1 -1
View File
@@ -1,4 +1,4 @@
import coralApi from '../../../coral-framework/helpers/response';
import coralApi from '../../../coral-framework/helpers/request';
import * as userTypes from '../constants/users';
/**
+2 -4
View File
@@ -8,16 +8,14 @@ import './graphql';
import {addExternalConfig} from 'coral-embed-stream/src/actions/config';
import reducers from './reducers';
import localStore, {injectReducers} from 'coral-framework/services/store';
import store, {injectReducers} from 'coral-framework/services/store';
import AppRouter from './AppRouter';
import {pym} from 'coral-framework';
injectReducers(reducers);
const store = (window.opener && window.opener.coralStore) ? window.opener.coralStore : localStore;
// Don't run this in the popup.
if (store === localStore) {
if (!window.opener) {
store.dispatch(checkLogin());
pym.sendMessage('getConfig');
+1 -1
View File
@@ -1,5 +1,5 @@
import * as actions from '../constants/asset';
import coralApi from '../helpers/response';
import coralApi from '../helpers/request';
import {addNotification} from '../actions/notification';
import I18n from 'coral-framework/modules/i18n/i18n';
+40 -30
View File
@@ -1,14 +1,14 @@
import {pym} from 'coral-framework';
import * as Storage from '../helpers/storage';
import * as actions from '../constants/auth';
import coralApi, {base} from '../helpers/response';
import jwtDecode from 'jwt-decode';
import {pym} from 'coral-framework';
import bowser from 'bowser';
import * as actions from '../constants/auth';
import * as Storage from '../helpers/storage';
import coralApi, {base} from '../helpers/request';
const lang = new I18n(translations);
import translations from './../translations';
import I18n from '../../coral-framework/modules/i18n/i18n';
// Dialog Actions
export const showSignInDialog = () => (dispatch) => {
const signInPopUp = window.open(
'/embed/stream/login',
@@ -121,26 +121,31 @@ export const handleAuthToken = (token) => (dispatch) => {
// SIGN IN
//==============================================================================
export const fetchSignIn = (formData) => (dispatch) => {
dispatch(signInRequest());
return coralApi('/auth/local', {method: 'POST', body: formData})
.then(({token}) => {
dispatch(handleAuthToken(token));
dispatch(hideSignInDialog());
})
.catch((error) => {
if (error.metadata) {
export const fetchSignIn = (formData) => {
return (dispatch) => {
dispatch(signInRequest());
// the user might not have a valid email. prompt the user user re-request the confirmation email
dispatch(
signInFailure(lang.t('error.emailNotVerified', error.metadata))
);
} else {
return coralApi('/auth/local', {method: 'POST', body: formData})
.then(({token}) => {
if (!bowser.safari && !bowser.ios) {
dispatch(handleAuthToken(token));
}
dispatch(hideSignInDialog());
})
.catch((error) => {
if (error.metadata) {
// invalid credentials
dispatch(signInFailure(lang.t('error.emailPasswordError')));
}
});
// the user might not have a valid email. prompt the user user re-request the confirmation email
dispatch(
signInFailure(lang.t('error.emailNotVerified', error.metadata))
);
} else {
// invalid credentials
dispatch(signInFailure(lang.t('error.emailPasswordError')));
}
});
};
};
//==============================================================================
@@ -187,7 +192,7 @@ export const fetchSignUpFacebook = () => (dispatch) => {
);
};
export const facebookCallback = (err, data) => (dispatch, getState) => {
export const facebookCallback = (err, data) => (dispatch) => {
if (err) {
dispatch(signInFacebookFailure(err));
return;
@@ -196,10 +201,6 @@ export const facebookCallback = (err, data) => (dispatch, getState) => {
dispatch(handleAuthToken(data.token));
dispatch(signInFacebookSuccess(data.user));
dispatch(hideSignInDialog());
const {user: {canEditName, status}} = getState().auth.toJS();
if (canEditName && status !== 'BANNED') {
dispatch(showCreateUsernameDialog());
}
} catch (err) {
dispatch(signInFacebookFailure(err));
return;
@@ -269,7 +270,9 @@ export const fetchForgotPassword = (email) => (dispatch) => {
export const logout = () => (dispatch) => {
return coralApi('/auth', {method: 'DELETE'}).then(() => {
Storage.removeItem('token');
if (!bowser.safari && !bowser.ios) {
Storage.removeItem('token');
}
dispatch({type: actions.LOGOUT});
});
};
@@ -292,11 +295,18 @@ export const checkLogin = () => (dispatch) => {
coralApi('/auth')
.then((result) => {
if (!result.user) {
Storage.removeItem('token');
if (!bowser.safari && !bowser.ios) {
Storage.removeItem('token');
}
throw new Error('Not logged in');
}
dispatch(checkLoginSuccess(result.user));
// Display create username dialog if necessary.
if (result.user.canEditName && result.user.status !== 'BANNED') {
dispatch(showCreateUsernameDialog());
}
})
.catch((error) => {
console.error(error);
+1 -1
View File
@@ -1,5 +1,5 @@
import {addNotification} from '../actions/notification';
import coralApi from '../helpers/response';
import coralApi from '../helpers/request';
import * as actions from '../constants/auth';
import I18n from 'coral-framework/modules/i18n/i18n';
@@ -1,22 +1,26 @@
import bowser from 'bowser';
import * as Storage from './storage';
import merge from 'lodash/merge';
const buildOptions = (inputOptions = {}) => {
const defaultOptions = {
method: 'GET',
headers: {
Accept: 'application/json',
Authorization: `Bearer ${Storage.getItem('token')}`,
'Content-Type': 'application/json'
'Content-Type': 'application/json',
},
credentials: 'same-origin'
};
let options = Object.assign({}, defaultOptions, inputOptions);
options.headers = Object.assign(
{},
defaultOptions.headers,
inputOptions.headers
);
let options = merge({}, defaultOptions, inputOptions);
if (!bowser.safari && !bowser.ios) {
let authorization = Storage.getItem('token');
if (authorization) {
options.headers.Authorization = `Bearer ${authorization}`;
}
}
if (options.method.toLowerCase() !== 'get') {
options.body = JSON.stringify(options.body);
+6 -1
View File
@@ -1,5 +1,6 @@
import {createNetworkInterface} from 'apollo-client';
import * as Storage from '../helpers/storage';
import bowser from 'bowser';
//==============================================================================
// NETWORK INTERFACE
@@ -21,7 +22,11 @@ networkInterface.use([{
if (!req.options.headers) {
req.options.headers = {}; // Create the header object if needed.
}
req.options.headers['authorization'] = `Bearer ${Storage.getItem('token')}`;
if (!bowser.safari && !bowser.ios) {
req.options.headers['authorization'] = `Bearer ${Storage.getItem('token')}`;
}
next();
}
}]);
+3
View File
@@ -54,10 +54,13 @@
"app-module-path": "^2.2.0",
"bcrypt": "^1.0.2",
"body-parser": "^1.17.1",
"bowser": "^1.7.0",
"cli-table": "^0.3.1",
"colors": "^1.1.2",
"commander": "^2.9.0",
"compression": "^1.6.2",
"connect-redis": "^3.1.0",
"cookie-parser": "^1.4.3",
"cross-spawn": "^5.1.0",
"csurf": "^1.9.0",
"dataloader": "^1.3.0",
@@ -23,17 +23,27 @@ class ChangeUsernameContainer extends React.Component {
this.state = {
formData: {
username: props.user.username
username: (props.auth.user && props.auth.user.username) || ''
},
errors: {},
showErrors: false
};
}
handleChange = e => {
componentWillReceiveProps(next) {
if (!this.props.auth.showCreateUsernameDialog && next.auth.showCreateUsernameDialog) {
this.setState({
formData: {
username: (this.props.auth.user && this.props.auth.user.username) || '',
},
});
}
}
handleChange = (e) => {
const {name, value} = e.target;
this.setState(
state => ({
(state) => ({
...state,
formData: {
...state.formData,
@@ -47,7 +57,7 @@ class ChangeUsernameContainer extends React.Component {
};
addError = (name, error) => {
return this.setState(state => ({
return this.setState((state) => ({
errors: {
...state.errors,
[name]: error
@@ -65,26 +75,26 @@ class ChangeUsernameContainer extends React.Component {
} else {
const {[name]: prop, ...errors} = this.state.errors; // eslint-disable-line
// Removes Error
this.setState(state => ({...state, errors}));
this.setState((state) => ({...state, errors}));
}
};
isCompleted = () => {
const {formData} = this.state;
return !Object.keys(formData).filter(prop => !formData[prop].length).length;
return !Object.keys(formData).filter((prop) => !formData[prop].length).length;
};
displayErrors = (show = true) => {
this.setState({showErrors: show});
};
handleSubmitUsername = e => {
handleSubmitUsername = (e) => {
e.preventDefault();
const {errors} = this.state;
const {validForm, invalidForm} = this.props;
this.displayErrors();
if (this.isCompleted() && !Object.keys(errors).length) {
this.props.createUsername(this.props.user.id, this.state.formData);
this.props.createUsername(this.props.auth.user.id, this.state.formData);
validForm();
} else {
invalidForm(lang.t('createdisplay.checkTheForm'));
@@ -100,7 +110,7 @@ class ChangeUsernameContainer extends React.Component {
return (
<div>
<CreateUsernameDialog
open={auth.showCreateUsernameDialog && auth.user.canEditName}
open={auth.showCreateUsernameDialog}
handleClose={this.handleClose}
loggedIn={loggedIn}
handleSubmitUsername={this.handleSubmitUsername}
@@ -113,9 +123,11 @@ class ChangeUsernameContainer extends React.Component {
}
}
const mapStateToProps = ({auth, user}) => ({auth, user});
const mapStateToProps = ({auth}) => ({
auth: auth.toJS()
});
const mapDispatchToProps = dispatch =>
const mapDispatchToProps = (dispatch) =>
bindActionCreators(
{
createUsername,
@@ -69,4 +69,5 @@ export const FakeComment = ({username, created_at, body}) => (
</div>
</div>
</div>
);
);
@@ -7,7 +7,7 @@ import I18n from 'coral-framework/modules/i18n/i18n';
const lang = new I18n(translations);
class ForgotContent extends React.Component {
handleSubmit = e => {
handleSubmit = (e) => {
e.preventDefault();
this.props.fetchForgotPassword(this.emailInput.value);
};
@@ -25,7 +25,7 @@ class ForgotContent extends React.Component {
<div className={styles.textField}>
<label htmlFor="email">{lang.t('signIn.email')}</label>
<input
ref={input => (this.emailInput = input)}
ref={(input) => (this.emailInput = input)}
type="text"
style={{fontSize: 16}}
id="email"
@@ -18,7 +18,7 @@ const mapStateToProps = ({auth}) => ({
loggedIn: auth.toJS().loggedIn
});
const mapDispatchToProps = dispatch =>
const mapDispatchToProps = (dispatch) =>
bindActionCreators({showSignInDialog}, dispatch);
export default connect(mapStateToProps, mapDispatchToProps)(SignInButton);
@@ -61,7 +61,8 @@ class SignInContainer extends React.Component {
window.removeEventListener('storage', this.handleAuth);
}
handleAuth = e => {
handleAuth = (e) => {
// Listening to FB changes
// FB localStorage key is 'auth'
const authCallback = this.props.facebookCallback;
@@ -72,10 +73,10 @@ class SignInContainer extends React.Component {
}
};
handleChange = e => {
handleChange = (e) => {
const {name, value} = e.target;
this.setState(
state => ({
(state) => ({
...state,
formData: {
...state.formData,
@@ -88,12 +89,12 @@ class SignInContainer extends React.Component {
);
};
handleChangeEmail = e => {
handleChangeEmail = (e) => {
const {value} = e.target;
this.setState({emailToBeResent: value});
};
handleResendVerification = e => {
handleResendVerification = (e) => {
e.preventDefault();
this.props
.requestConfirmEmail(
@@ -102,6 +103,7 @@ class SignInContainer extends React.Component {
)
.then(() => {
setTimeout(() => {
// allow success UI to be shown for a second, and then close the modal
this.props.hideSignInDialog();
}, 2500);
@@ -109,7 +111,7 @@ class SignInContainer extends React.Component {
};
addError = (name, error) => {
return this.setState(state => ({
return this.setState((state) => ({
errors: {
...state.errors,
[name]: error
@@ -133,20 +135,20 @@ class SignInContainer extends React.Component {
} else {
const {[name]: prop, ...errors} = this.state.errors; // eslint-disable-line
// Removes Error
this.setState(state => ({...state, errors}));
this.setState((state) => ({...state, errors}));
}
};
isCompleted = () => {
const {formData} = this.state;
return !Object.keys(formData).filter(prop => !formData[prop].length).length;
return !Object.keys(formData).filter((prop) => !formData[prop].length).length;
};
displayErrors = (show = true) => {
this.setState({showErrors: show});
};
handleSignUp = e => {
handleSignUp = (e) => {
e.preventDefault();
const {errors} = this.state;
const {fetchSignUp, validForm, invalidForm} = this.props;
@@ -159,7 +161,7 @@ class SignInContainer extends React.Component {
}
};
handleSignIn = e => {
handleSignIn = (e) => {
e.preventDefault();
this.props.fetchSignIn(this.state.formData);
};
@@ -183,17 +185,16 @@ class SignInContainer extends React.Component {
}
}
const mapStateToProps = state => ({
const mapStateToProps = (state) => ({
auth: state.auth.toJS()
});
const mapDispatchToProps = dispatch =>
const mapDispatchToProps = (dispatch) =>
bindActionCreators(
{
checkLogin,
facebookCallback,
fetchSignUp,
fetchSignUp,
fetchSignIn,
fetchSignInFacebook,
fetchSignUpFacebook,
@@ -1,5 +1,5 @@
import styles from './styles.css';
import React, {PropTypes} from 'react';
import React from 'react';
import translations from '../translations';
import I18n from 'coral-framework/modules/i18n/i18n';
import {Button, TextField, Spinner, Success, Alert} from 'coral-ui';
@@ -7,12 +7,17 @@ import {Button, TextField, Spinner, Success, Alert} from 'coral-ui';
const lang = new I18n(translations);
class SignUpContent extends React.Component {
constructor() {
super();
this.state = {
successfulSignup: false
};
componentWillReceiveProps(next) {
if (
!this.props.emailVerificationEnabled &&
!this.props.auth.successSignUp &&
next.auth.successSignUp
) {
setTimeout(() => {
this.props.changeView('SIGNIN');
}, 2000);
}
}
render() {
@@ -28,19 +33,6 @@ class SignUpContent extends React.Component {
fetchSignUpFacebook
} = this.props;
const beforeSignup = !auth.isLoading && !auth.successSignUp;
const successfulSignup = !auth.isLoading && auth.successSignUp;
// the first time we render a successfulSignup, trigger a timer
if (this.successfulSignup ^ successfulSignup && !emailVerificationEnabled) {
setTimeout(() => {
changeView('SIGNIN');
}, 1000);
this.setState({
successfulSignup: true
});
}
return (
<div>
<div className={styles.header}>
@@ -50,7 +42,7 @@ class SignUpContent extends React.Component {
</div>
{auth.error && <Alert>{auth.error}</Alert>}
{beforeSignup &&
{!auth.successSignUp &&
<div>
<div className={styles.socialConnections}>
<Button cStyle="facebook" onClick={fetchSignUpFacebook} full>
@@ -123,7 +115,7 @@ class SignUpContent extends React.Component {
</div>
</form>
</div>}
{successfulSignup &&
{auth.successSignUp &&
<div>
<Success />
{emailVerificationEnabled &&
@@ -4,7 +4,7 @@ import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import translations from '../translations';
import I18n from 'coral-framework/modules/i18n/i18n';
import {showSignInDialog, logout} from 'coral-framework/actions/auth';
import {logout} from 'coral-framework/actions/auth';
const lang = new I18n(translations);
const UserBox = ({loggedIn, user, logout, onShowProfile}) => (
@@ -23,12 +23,12 @@ const UserBox = ({loggedIn, user, logout, onShowProfile}) => (
</div>
);
const mapStateToProps = ({auth, user}) => ({
const mapStateToProps = ({auth}) => ({
loggedIn: auth.toJS().loggedIn,
user: user.toJS()
user: auth.toJS().user
});
const mapDispatchToProps = dispatch =>
const mapDispatchToProps = (dispatch) =>
bindActionCreators({logout}, dispatch);
export default connect(mapStateToProps, mapDispatchToProps)(UserBox);
+2 -1
View File
@@ -8,4 +8,5 @@ export default {
stream: [UserBox, SignInButton, ChangeUserNameContainer],
login: [SignInContainer]
}
};
};
+2 -1
View File
@@ -1 +1,2 @@
module.exports = {};
module.exports = {};
@@ -1,19 +1,18 @@
import React, { Component } from 'react';
import React, {Component} from 'react';
import styles from './style.css';
import Icon from './Icon';
import { I18n } from 'coral-framework';
import {I18n} from 'coral-framework';
import cn from 'classnames';
import translations from '../translations.json';
import { getMyActionSummary, getTotalActionCount } from 'coral-framework/utils';
import {getMyActionSummary, getTotalActionCount} from 'coral-framework/utils';
const lang = new I18n(translations);
const name = 'coral-plugin-like';
class LikeButton extends Component {
handleClick = () => {
const { postLike, showSignInDialog, deleteAction } = this.props;
const { root: { me }, comment } = this.props;
const {postLike, showSignInDialog, deleteAction} = this.props;
const {root: {me}, comment} = this.props;
const myLikeActionSummary = getMyActionSummary(
'LikeActionSummary',
@@ -42,7 +41,7 @@ class LikeButton extends Component {
};
render() {
const { comment } = this.props;
const {comment} = this.props;
if (!comment) {
return null;
@@ -56,7 +55,7 @@ class LikeButton extends Component {
<button
className={cn(
styles.button,
{ [styles.liked]: myLike },
{[styles.liked]: myLike},
`${name}-button`
)}
onClick={this.handleClick}
@@ -68,7 +67,7 @@ class LikeButton extends Component {
className={cn(
styles.icon,
'material-icons',
{ [styles.liked]: myLike },
{[styles.liked]: myLike},
`${name}-icon`
)}
aria-hidden={true}
@@ -1,12 +1,12 @@
import get from 'lodash/get';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { compose, gql, graphql } from 'react-apollo';
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import {compose, gql, graphql} from 'react-apollo';
import LikeButton from '../components/LikeButton';
import withFragments from 'coral-framework/hocs/withFragments';
import { showSignInDialog } from 'coral-framework/actions/auth';
import{showSignInDialog} from 'coral-framework/actions/auth';
const isLikeAction = a => a.__typename === 'LikeActionSummary';
const isLikeAction = (a) => a.__typename === 'LikeActionSummary';
const COMMENT_FRAGMENT = gql`
fragment LikeButton_updateFragment on Comment {
@@ -32,17 +32,17 @@ const withDeleteAction = graphql(
}
`,
{
props: ({ mutate }) => ({
props: ({mutate}) => ({
deleteAction: (id, commentId) => {
return mutate({
variables: { id },
variables: {id},
optimisticResponse: {
deleteAction: {
__typename: 'DeleteActionResponse',
errors: null
}
},
update: proxy => {
update: (proxy) => {
const fragmentId = `Comment_${commentId}`;
// Read the data from our cache for this query.
@@ -93,10 +93,10 @@ const withPostLike = graphql(
}
`,
{
props: ({ mutate }) => ({
postLike: like => {
props: ({mutate}) => ({
postLike: (like) => {
return mutate({
variables: { like },
variables: {like},
optimisticResponse: {
createLike: {
__typename: 'CreateLikeResponse',
@@ -125,6 +125,7 @@ const withPostLike = graphql(
}
if (idx < 0) {
// Add initial action when it doesn't exist.
data.action_summaries.push({
__typename: 'LikeActionSummary',
@@ -153,8 +154,8 @@ const withPostLike = graphql(
}
);
const mapDispatchToProps = dispatch =>
bindActionCreators({ showSignInDialog }, dispatch);
const mapDispatchToProps = (dispatch) =>
bindActionCreators({showSignInDialog}, dispatch);
const enhance = compose(
withFragments({
@@ -14,7 +14,7 @@ class LoveButton extends React.Component {
showSignInDialog,
alreadyReacted
} = this.props;
const {root: {me}, comment} = this.props;
const {root: {me}} = this.props;
// If the current user does not exist, trigger sign in dialog.
if (!me) {
+4 -4
View File
@@ -16,8 +16,8 @@ module.exports = {
__resolveType: {
post({action_type}) {
switch (action_type) {
case 'LOVE':
return 'LoveAction';
case 'LOVE':
return 'LoveAction';
}
}
}
@@ -26,8 +26,8 @@ module.exports = {
__resolveType: {
post({action_type}) {
switch (action_type) {
case 'LOVE':
return 'LoveActionSummary';
case 'LOVE':
return 'LoveActionSummary';
}
}
}
@@ -1,8 +1,9 @@
import React from 'react';
import styles from './styles.css'
import styles from './styles.css';
export default (props) => (
<div className={styles.box}>
Comment Status: {props.comment.status}
</div>
)
);
@@ -1,6 +1,6 @@
import React from 'react';
import Box from './Box';
import {Button} from 'coral-ui'
import {Button} from 'coral-ui';
import styles from './styles.css';
export default class Footer extends React.Component {
@@ -13,9 +13,9 @@ export default class Footer extends React.Component {
}
handleClick = () => {
this.setState(state => ({
this.setState((state) => ({
show: !state.show
}))
}));
}
render() {
+1 -3
View File
@@ -1,4 +1,2 @@
const {readFileSync} = require('fs');
const path = require('path');
module.exports = {};
@@ -10,7 +10,7 @@ class OffTopicCheckbox extends React.Component {
handleChange = (e) => {
if (e.target.checked) {
this.props.addTag(this.label)
this.props.addTag(this.label);
} else {
const idx = this.props.commentBox.tags.indexOf(this.label);
this.props.removeTag(idx);
@@ -25,14 +25,13 @@ class OffTopicCheckbox extends React.Component {
Off-Topic
</label>
</div>
)
);
}
}
const mapStateToProps = ({commentBox}) => ({commentBox});
const mapDispatchToProps = dispatch =>
const mapDispatchToProps = (dispatch) =>
bindActionCreators({addTag, removeTag}, dispatch);
export default connect(mapStateToProps, mapDispatchToProps)(OffTopicCheckbox);
@@ -2,8 +2,8 @@ import React from 'react';
import styles from './styles.css';
const isOffTopic = (tags) => {
return !!tags.filter(tag => tag.name === 'OFF_TOPIC').length
}
return !!tags.filter((tag) => tag.name === 'OFF_TOPIC').length;
};
export default (props) => (
<span>
+2 -1
View File
@@ -22,9 +22,10 @@ router.get('/', (req, res, next) => {
/**
* This blacklists the token used to authenticate.
*/
router.delete('/', HandleLogout);
//==============================================================================
// =============================================================================
// PASSPORT ROUTES
//==============================================================================
+31 -1
View File
@@ -9,6 +9,7 @@ const errors = require('../errors');
const uuid = require('uuid');
const debug = require('debug')('talk:passport');
const {createClient} = require('./redis');
const bowser = require('bowser');
// Create a redis client to use for authentication.
const client = createClient();
@@ -32,6 +33,17 @@ const GenerateToken = (user) => JWT.sign({}, JWT_SECRET, {
audience: JWT_AUDIENCE
});
// SetTokenForSafari sends the token in a cookie for Safari clients.
const SetTokenForSafari = (req, res, token) => {
const browser = bowser._detect(req.headers['user-agent']);
if (browser.ios || browser.safari) {
res.cookie('authorization', token, {
httpOnly: true,
expires: new Date(Date.now() + 900000)
});
}
};
// HandleGenerateCredentials validates that an authentication scheme did indeed
// return a user, if it did, then sign and return the user and token to be used
// by the frontend to display and update the UI.
@@ -47,6 +59,8 @@ const HandleGenerateCredentials = (req, res, next) => (err, user) => {
// Generate the token to re-issue to the frontend.
const token = GenerateToken(user);
SetTokenForSafari(req, res, token);
// Send back the details!
res.json({user, token});
};
@@ -66,6 +80,8 @@ const HandleAuthPopupCallback = (req, res, next) => (err, user) => {
// Generate the token to re-issue to the frontend.
const token = GenerateToken(user);
SetTokenForSafari(req, res, token);
// We logged in the user! Let's send back the user data.
res.render('auth-callback', {auth: JSON.stringify({err: null, data: {user, token}})});
};
@@ -134,6 +150,7 @@ const HandleLogout = (req, res, next) => {
return next(err);
}
res.clearCookie('authorization');
res.status(204).end();
});
};
@@ -158,11 +175,24 @@ const CheckBlacklisted = (jwt) => new Promise((resolve, reject) => {
const JwtStrategy = require('passport-jwt').Strategy;
const ExtractJwt = require('passport-jwt').ExtractJwt;
let cookieExtractor = function(req) {
let token = null;
if (req && req.cookies) {
token = req.cookies['authorization'];
}
return token;
};
// Extract the JWT from the 'Authorization' header with the 'Bearer' scheme.
passport.use(new JwtStrategy({
// Prepare the extractor from the header.
jwtFromRequest: ExtractJwt.fromAuthHeaderWithScheme('Bearer'),
jwtFromRequest: ExtractJwt.fromExtractors([
cookieExtractor,
ExtractJwt.fromAuthHeaderWithScheme('Bearer')
]),
// Use the secret passed in which is loaded from the environment. This can be
// a certificate (loaded) or a HMAC key.
+36 -4
View File
@@ -1262,6 +1262,10 @@ boom@2.x.x:
dependencies:
hoek "2.x.x"
bowser@^1.7.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/bowser/-/bowser-1.7.0.tgz#169de4018711f994242bff9a8009e77a1f35e003"
brace-expansion@^1.0.0:
version "1.1.7"
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.7.tgz#3effc3c50e000531fb720eaff80f0ae8ef23cf59"
@@ -1395,6 +1399,10 @@ builtin-status-codes@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/builtin-status-codes/-/builtin-status-codes-3.0.0.tgz#85982878e21b98e1c66425e03d0174788f569ee8"
bytes@2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/bytes/-/bytes-2.3.0.tgz#d5b680a165b6201739acb611542aabc2d8ceb070"
bytes@2.4.0:
version "2.4.0"
resolved "https://registry.yarnpkg.com/bytes/-/bytes-2.4.0.tgz#7d97196f9d5baf7f6935e25985549edd2a6c2339"
@@ -1815,6 +1823,12 @@ component-emitter@^1.2.0:
version "1.2.1"
resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.2.1.tgz#137918d6d78283f7df7a6b7c5a63e140e69425e6"
compressible@~2.0.8:
version "2.0.10"
resolved "https://registry.yarnpkg.com/compressible/-/compressible-2.0.10.tgz#feda1c7f7617912732b29bf8cf26252a20b9eecd"
dependencies:
mime-db ">= 1.27.0 < 2"
compression-webpack-plugin@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/compression-webpack-plugin/-/compression-webpack-plugin-0.4.0.tgz#811de04215f811ea6a12d4d8aed8457d758f13ac"
@@ -1824,6 +1838,17 @@ compression-webpack-plugin@^0.4.0:
optionalDependencies:
node-zopfli "^2.0.0"
compression@^1.6.2:
version "1.6.2"
resolved "https://registry.yarnpkg.com/compression/-/compression-1.6.2.tgz#cceb121ecc9d09c52d7ad0c3350ea93ddd402bc3"
dependencies:
accepts "~1.3.3"
bytes "2.3.0"
compressible "~2.0.8"
debug "~2.2.0"
on-headers "~1.0.1"
vary "~1.1.0"
concat-map@0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
@@ -1925,6 +1950,13 @@ convert-source-map@^1.1.0:
version "1.5.0"
resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-1.5.0.tgz#9acd70851c6d5dfdd93d9282e5edf94a03ff46b5"
cookie-parser@^1.4.3:
version "1.4.3"
resolved "https://registry.yarnpkg.com/cookie-parser/-/cookie-parser-1.4.3.tgz#0fe31fa19d000b95f4aadf1f53fdc2b8a203baa5"
dependencies:
cookie "0.3.1"
cookie-signature "1.0.6"
cookie-signature@1.0.6:
version "1.0.6"
resolved "https://registry.yarnpkg.com/cookie-signature/-/cookie-signature-1.0.6.tgz#e303a882b342cc3ee8ca513a79999734dab3ae2c"
@@ -5143,14 +5175,14 @@ miller-rabin@^4.0.0:
bn.js "^4.0.0"
brorand "^1.0.1"
"mime-db@>= 1.27.0 < 2", mime-db@~1.27.0:
version "1.27.0"
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.27.0.tgz#820f572296bbd20ec25ed55e5b5de869e5436eb1"
mime-db@~1.12.0:
version "1.12.0"
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.12.0.tgz#3d0c63180f458eb10d325aaa37d7c58ae312e9d7"
mime-db@~1.27.0:
version "1.27.0"
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.27.0.tgz#820f572296bbd20ec25ed55e5b5de869e5436eb1"
mime-types@^2.1.10, mime-types@^2.1.12, mime-types@~2.1.11, mime-types@~2.1.15, mime-types@~2.1.7:
version "2.1.15"
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.15.tgz#a4ebf5064094569237b8cf70046776d09fc92aed"