From 4b6e56249298086483c71c7321150dd8c45b6609 Mon Sep 17 00:00:00 2001 From: Belen Curcio Date: Mon, 15 May 2017 23:22:36 -0300 Subject: [PATCH 1/9] Missing "" to send strings instead of objects --- views/auth-callback.ejs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/auth-callback.ejs b/views/auth-callback.ejs index a97884ae2..22103226d 100644 --- a/views/auth-callback.ejs +++ b/views/auth-callback.ejs @@ -5,7 +5,7 @@ <%/* set the auth data in localStorage, this will ensure that only javascript on the same domain can access the data, they can listen for updates by attaching to localStorage event changes */%> - localStorage.setItem('auth', <%- auth %>); + localStorage.setItem('auth', '<%- auth %>'); setTimeout(function() { window.close(); }, 50); From 1eada688febaaec79082064b9a13c1a59d127ec8 Mon Sep 17 00:00:00 2001 From: Belen Curcio Date: Mon, 15 May 2017 23:23:22 -0300 Subject: [PATCH 2/9] Prettier --- client/coral-framework/actions/auth.js | 84 ++++++++++++----------- client/coral-framework/helpers/storage.js | 8 +-- 2 files changed, 47 insertions(+), 45 deletions(-) diff --git a/client/coral-framework/actions/auth.js b/client/coral-framework/actions/auth.js index b53badf99..b78f32b2d 100644 --- a/client/coral-framework/actions/auth.js +++ b/client/coral-framework/actions/auth.js @@ -9,7 +9,7 @@ import translations from './../translations'; import I18n from '../../coral-framework/modules/i18n/i18n'; // Dialog Actions -export const showSignInDialog = () => (dispatch) => { +export const showSignInDialog = () => dispatch => { const signInPopUp = window.open( '/embed/stream/login', 'Login', @@ -32,7 +32,7 @@ export const showSignInDialog = () => (dispatch) => { dispatch({type: actions.SHOW_SIGNIN_DIALOG}); }; -export const hideSignInDialog = () => (dispatch) => { +export const hideSignInDialog = () => dispatch => { dispatch({type: actions.HIDE_SIGNIN_DIALOG}); window.close(); }; @@ -51,7 +51,7 @@ const createUsernameSuccess = () => ({ type: actions.CREATE_USERNAME_SUCCESS }); -const createUsernameFailure = (error) => ({ +const createUsernameFailure = error => ({ type: actions.CREATE_USERNAME_FAILURE, error }); @@ -61,7 +61,7 @@ export const updateUsername = ({username}) => ({ username }); -export const createUsername = (userId, formData) => (dispatch) => { +export const createUsername = (userId, formData) => dispatch => { dispatch(createUsernameRequest()); coralApi('/account/username', {method: 'PUT', body: formData}) .then(() => { @@ -69,26 +69,26 @@ export const createUsername = (userId, formData) => (dispatch) => { dispatch(hideCreateUsernameDialog()); dispatch(updateUsername(formData)); }) - .catch((error) => { + .catch(error => { dispatch(createUsernameFailure(lang.t(`error.${error.translation_key}`))); }); }; -export const changeView = (view) => (dispatch) => { +export const changeView = view => dispatch => { dispatch({ type: actions.CHANGE_VIEW, view }); switch (view) { - case 'SIGNUP': - window.resizeTo(500, 800); - break; - case 'FORGOT': - window.resizeTo(500, 400); - break; - default: - window.resizeTo(500, 550); + case 'SIGNUP': + window.resizeTo(500, 800); + break; + case 'FORGOT': + window.resizeTo(500, 400); + break; + default: + window.resizeTo(500, 550); } }; @@ -102,7 +102,7 @@ const signInRequest = () => ({ type: actions.FETCH_SIGNIN_REQUEST }); -const signInFailure = (error) => ({ +const signInFailure = error => ({ type: actions.FETCH_SIGNIN_FAILURE, error }); @@ -111,7 +111,7 @@ const signInFailure = (error) => ({ // AUTH TOKEN //============================================================================== -export const handleAuthToken = (token) => (dispatch) => { +export const handleAuthToken = token => dispatch => { Storage.setItem('exp', jwtDecode(token).exp); Storage.setItem('token', token); dispatch({type: 'HANDLE_AUTH_TOKEN'}); @@ -121,22 +121,20 @@ export const handleAuthToken = (token) => (dispatch) => { // SIGN IN //============================================================================== -export const fetchSignIn = (formData) => (dispatch) => { +export const fetchSignIn = formData => dispatch => { dispatch(signInRequest()); return coralApi('/auth/local', {method: 'POST', body: formData}) .then(({token}) => { dispatch(handleAuthToken(token)); dispatch(hideSignInDialog()); }) - .catch((error) => { + .catch(error => { if (error.metadata) { - // 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'))); } @@ -150,16 +148,18 @@ export const fetchSignIn = (formData) => (dispatch) => { const signInFacebookRequest = () => ({ type: actions.FETCH_SIGNIN_FACEBOOK_REQUEST }); -const signInFacebookSuccess = (user) => ({ + +const signInFacebookSuccess = user => ({ type: actions.FETCH_SIGNIN_FACEBOOK_SUCCESS, user }); -const signInFacebookFailure = (error) => ({ + +const signInFacebookFailure = error => ({ type: actions.FETCH_SIGNIN_FACEBOOK_FAILURE, error }); -export const fetchSignInFacebook = () => (dispatch) => { +export const fetchSignInFacebook = () => dispatch => { dispatch(signInFacebookRequest()); window.open( `${base}/auth/facebook`, @@ -176,7 +176,7 @@ const signUpFacebookRequest = () => ({ type: actions.FETCH_SIGNUP_FACEBOOK_REQUEST }); -export const fetchSignUpFacebook = () => (dispatch) => { +export const fetchSignUpFacebook = () => dispatch => { dispatch(signUpFacebookRequest()); window.open( `${base}/auth/facebook`, @@ -185,13 +185,16 @@ export const fetchSignUpFacebook = () => (dispatch) => { ); }; -export const facebookCallback = (err, data) => (dispatch) => { +export const facebookCallback = (err, data) => dispatch => { + console.log('asd') + debugger if (err) { dispatch(signInFacebookFailure(err)); return; } try { const user = JSON.parse(data); + console.log(user); dispatch(signInFacebookSuccess(user)); dispatch(hideSignInDialog()); dispatch(showCreateUsernameDialog()); @@ -207,10 +210,10 @@ export const facebookCallback = (err, data) => (dispatch) => { //============================================================================== const signUpRequest = () => ({type: actions.FETCH_SIGNUP_REQUEST}); -const signUpSuccess = (user) => ({type: actions.FETCH_SIGNUP_SUCCESS, user}); -const signUpFailure = (error) => ({type: actions.FETCH_SIGNUP_FAILURE, error}); +const signUpSuccess = user => ({type: actions.FETCH_SIGNUP_SUCCESS, user}); +const signUpFailure = error => ({type: actions.FETCH_SIGNUP_FAILURE, error}); -export const fetchSignUp = (formData, redirectUri) => (dispatch) => { +export const fetchSignUp = (formData, redirectUri) => dispatch => { dispatch(signUpRequest()); coralApi('/users', { @@ -221,7 +224,7 @@ export const fetchSignUp = (formData, redirectUri) => (dispatch) => { .then(({user}) => { dispatch(signUpSuccess(user)); }) - .catch((error) => { + .catch(error => { let errorMessage = lang.t(`error.${error.message}`); // if there is no translation defined, just show the error string @@ -248,7 +251,7 @@ const forgotPasswordFailure = () => ({ type: actions.FETCH_FORGOT_PASSWORD_FAILURE }); -export const fetchForgotPassword = (email) => (dispatch) => { +export const fetchForgotPassword = email => dispatch => { dispatch(forgotPasswordRequest(email)); const redirectUri = pym.parentUrl || location.href; coralApi('/account/password/reset', { @@ -256,14 +259,14 @@ export const fetchForgotPassword = (email) => (dispatch) => { body: {email, loc: redirectUri} }) .then(() => dispatch(forgotPasswordSuccess())) - .catch((error) => dispatch(forgotPasswordFailure(error))); + .catch(error => dispatch(forgotPasswordFailure(error))); }; //============================================================================== // LOGOUT //============================================================================== -export const logout = () => (dispatch) => { +export const logout = () => dispatch => { return coralApi('/auth', {method: 'DELETE'}).then(() => { dispatch({type: actions.LOGOUT}); Storage.removeItem('token'); @@ -275,7 +278,7 @@ export const logout = () => (dispatch) => { //============================================================================== const checkLoginRequest = () => ({type: actions.CHECK_LOGIN_REQUEST}); -const checkLoginFailure = (error) => ({type: actions.CHECK_LOGIN_FAILURE, error}); +const checkLoginFailure = error => ({type: actions.CHECK_LOGIN_FAILURE, error}); const checkLoginSuccess = (user, isAdmin) => ({ type: actions.CHECK_LOGIN_SUCCESS, @@ -283,26 +286,26 @@ const checkLoginSuccess = (user, isAdmin) => ({ isAdmin }); -export const checkLogin = () => (dispatch) => { +export const checkLogin = () => dispatch => { dispatch(checkLoginRequest()); coralApi('/auth') - .then((result) => { + .then(result => { if (!result.user) { Storage.removeItem('token'); throw new Error('Not logged in'); } - const isAdmin = !!result.user.roles.filter((i) => i === 'ADMIN').length; + const isAdmin = !!result.user.roles.filter(i => i === 'ADMIN').length; dispatch(checkLoginSuccess(result.user, isAdmin)); }) - .catch((error) => { + .catch(error => { console.error(error); dispatch(checkLoginFailure(`${error.translation_key}`)); }); }; export const validForm = () => ({type: actions.VALID_FORM}); -export const invalidForm = (error) => ({type: actions.INVALID_FORM, error}); +export const invalidForm = error => ({type: actions.INVALID_FORM, error}); //============================================================================== // VERIFY EMAIL @@ -320,7 +323,7 @@ const verifyEmailFailure = () => ({ type: actions.VERIFY_EMAIL_FAILURE }); -export const requestConfirmEmail = (email, redirectUri) => (dispatch) => { +export const requestConfirmEmail = (email, redirectUri) => dispatch => { dispatch(verifyEmailRequest()); return coralApi('/users/resend-verify', { method: 'POST', @@ -330,8 +333,7 @@ export const requestConfirmEmail = (email, redirectUri) => (dispatch) => { .then(() => { dispatch(verifyEmailSuccess()); }) - .catch((err) => { - + .catch(err => { // email might have already been verifyed dispatch(verifyEmailFailure(err)); }); diff --git a/client/coral-framework/helpers/storage.js b/client/coral-framework/helpers/storage.js index fa20fa168..d6bb280c2 100644 --- a/client/coral-framework/helpers/storage.js +++ b/client/coral-framework/helpers/storage.js @@ -87,7 +87,7 @@ export function clear() { } // Enable this to debug WEB Storage events -// window.addEventListener('storage', function(e) { -// const msg = `${e.key} " was changed in page ${e.url} from ${e.oldValue} to ${e.newValue}`; -// console.log(msg); -// }); +window.addEventListener('storage', function(e) { + const msg = `${e.key} " was changed in page ${e.url} from ${e.oldValue} to ${e.newValue}`; + console.log(msg); +}); From d3252b8c87d092f1d124fe31e7b13d1b17cebaaa Mon Sep 17 00:00:00 2001 From: Belen Curcio Date: Mon, 15 May 2017 23:47:29 -0300 Subject: [PATCH 3/9] Done :) --- client/coral-framework/actions/auth.js | 86 +++++++++---------- client/coral-framework/helpers/storage.js | 9 +- .../containers/SignInContainer.js | 70 ++++++++++----- 3 files changed, 95 insertions(+), 70 deletions(-) diff --git a/client/coral-framework/actions/auth.js b/client/coral-framework/actions/auth.js index b78f32b2d..03ab61c76 100644 --- a/client/coral-framework/actions/auth.js +++ b/client/coral-framework/actions/auth.js @@ -9,7 +9,7 @@ import translations from './../translations'; import I18n from '../../coral-framework/modules/i18n/i18n'; // Dialog Actions -export const showSignInDialog = () => dispatch => { +export const showSignInDialog = () => (dispatch) => { const signInPopUp = window.open( '/embed/stream/login', 'Login', @@ -32,7 +32,7 @@ export const showSignInDialog = () => dispatch => { dispatch({type: actions.SHOW_SIGNIN_DIALOG}); }; -export const hideSignInDialog = () => dispatch => { +export const hideSignInDialog = () => (dispatch) => { dispatch({type: actions.HIDE_SIGNIN_DIALOG}); window.close(); }; @@ -51,7 +51,7 @@ const createUsernameSuccess = () => ({ type: actions.CREATE_USERNAME_SUCCESS }); -const createUsernameFailure = error => ({ +const createUsernameFailure = (error) => ({ type: actions.CREATE_USERNAME_FAILURE, error }); @@ -61,7 +61,7 @@ export const updateUsername = ({username}) => ({ username }); -export const createUsername = (userId, formData) => dispatch => { +export const createUsername = (userId, formData) => (dispatch) => { dispatch(createUsernameRequest()); coralApi('/account/username', {method: 'PUT', body: formData}) .then(() => { @@ -69,26 +69,26 @@ export const createUsername = (userId, formData) => dispatch => { dispatch(hideCreateUsernameDialog()); dispatch(updateUsername(formData)); }) - .catch(error => { + .catch((error) => { dispatch(createUsernameFailure(lang.t(`error.${error.translation_key}`))); }); }; -export const changeView = view => dispatch => { +export const changeView = (view) => (dispatch) => { dispatch({ type: actions.CHANGE_VIEW, view }); switch (view) { - case 'SIGNUP': - window.resizeTo(500, 800); - break; - case 'FORGOT': - window.resizeTo(500, 400); - break; - default: - window.resizeTo(500, 550); + case 'SIGNUP': + window.resizeTo(500, 800); + break; + case 'FORGOT': + window.resizeTo(500, 400); + break; + default: + window.resizeTo(500, 550); } }; @@ -102,7 +102,7 @@ const signInRequest = () => ({ type: actions.FETCH_SIGNIN_REQUEST }); -const signInFailure = error => ({ +const signInFailure = (error) => ({ type: actions.FETCH_SIGNIN_FAILURE, error }); @@ -111,7 +111,7 @@ const signInFailure = error => ({ // AUTH TOKEN //============================================================================== -export const handleAuthToken = token => dispatch => { +export const handleAuthToken = (token) => (dispatch) => { Storage.setItem('exp', jwtDecode(token).exp); Storage.setItem('token', token); dispatch({type: 'HANDLE_AUTH_TOKEN'}); @@ -121,20 +121,22 @@ export const handleAuthToken = token => dispatch => { // SIGN IN //============================================================================== -export const fetchSignIn = formData => dispatch => { +export const fetchSignIn = (formData) => (dispatch) => { dispatch(signInRequest()); return coralApi('/auth/local', {method: 'POST', body: formData}) .then(({token}) => { dispatch(handleAuthToken(token)); dispatch(hideSignInDialog()); }) - .catch(error => { + .catch((error) => { if (error.metadata) { + // 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'))); } @@ -149,17 +151,17 @@ const signInFacebookRequest = () => ({ type: actions.FETCH_SIGNIN_FACEBOOK_REQUEST }); -const signInFacebookSuccess = user => ({ +const signInFacebookSuccess = (user) => ({ type: actions.FETCH_SIGNIN_FACEBOOK_SUCCESS, user }); -const signInFacebookFailure = error => ({ +const signInFacebookFailure = (error) => ({ type: actions.FETCH_SIGNIN_FACEBOOK_FAILURE, error }); -export const fetchSignInFacebook = () => dispatch => { +export const fetchSignInFacebook = () => (dispatch) => { dispatch(signInFacebookRequest()); window.open( `${base}/auth/facebook`, @@ -176,7 +178,7 @@ const signUpFacebookRequest = () => ({ type: actions.FETCH_SIGNUP_FACEBOOK_REQUEST }); -export const fetchSignUpFacebook = () => dispatch => { +export const fetchSignUpFacebook = () => (dispatch) => { dispatch(signUpFacebookRequest()); window.open( `${base}/auth/facebook`, @@ -185,17 +187,14 @@ export const fetchSignUpFacebook = () => dispatch => { ); }; -export const facebookCallback = (err, data) => dispatch => { - console.log('asd') - debugger +export const facebookCallback = (err, data) => (dispatch) => { if (err) { dispatch(signInFacebookFailure(err)); return; } try { - const user = JSON.parse(data); - console.log(user); - dispatch(signInFacebookSuccess(user)); + dispatch(handleAuthToken(data.token)); + dispatch(signInFacebookSuccess(data.user)); dispatch(hideSignInDialog()); dispatch(showCreateUsernameDialog()); dispatch(hideSignInDialog()); @@ -210,10 +209,10 @@ export const facebookCallback = (err, data) => dispatch => { //============================================================================== const signUpRequest = () => ({type: actions.FETCH_SIGNUP_REQUEST}); -const signUpSuccess = user => ({type: actions.FETCH_SIGNUP_SUCCESS, user}); -const signUpFailure = error => ({type: actions.FETCH_SIGNUP_FAILURE, error}); +const signUpSuccess = (user) => ({type: actions.FETCH_SIGNUP_SUCCESS, user}); +const signUpFailure = (error) => ({type: actions.FETCH_SIGNUP_FAILURE, error}); -export const fetchSignUp = (formData, redirectUri) => dispatch => { +export const fetchSignUp = (formData, redirectUri) => (dispatch) => { dispatch(signUpRequest()); coralApi('/users', { @@ -224,7 +223,7 @@ export const fetchSignUp = (formData, redirectUri) => dispatch => { .then(({user}) => { dispatch(signUpSuccess(user)); }) - .catch(error => { + .catch((error) => { let errorMessage = lang.t(`error.${error.message}`); // if there is no translation defined, just show the error string @@ -251,7 +250,7 @@ const forgotPasswordFailure = () => ({ type: actions.FETCH_FORGOT_PASSWORD_FAILURE }); -export const fetchForgotPassword = email => dispatch => { +export const fetchForgotPassword = (email) => (dispatch) => { dispatch(forgotPasswordRequest(email)); const redirectUri = pym.parentUrl || location.href; coralApi('/account/password/reset', { @@ -259,14 +258,14 @@ export const fetchForgotPassword = email => dispatch => { body: {email, loc: redirectUri} }) .then(() => dispatch(forgotPasswordSuccess())) - .catch(error => dispatch(forgotPasswordFailure(error))); + .catch((error) => dispatch(forgotPasswordFailure(error))); }; //============================================================================== // LOGOUT //============================================================================== -export const logout = () => dispatch => { +export const logout = () => (dispatch) => { return coralApi('/auth', {method: 'DELETE'}).then(() => { dispatch({type: actions.LOGOUT}); Storage.removeItem('token'); @@ -278,7 +277,7 @@ export const logout = () => dispatch => { //============================================================================== const checkLoginRequest = () => ({type: actions.CHECK_LOGIN_REQUEST}); -const checkLoginFailure = error => ({type: actions.CHECK_LOGIN_FAILURE, error}); +const checkLoginFailure = (error) => ({type: actions.CHECK_LOGIN_FAILURE, error}); const checkLoginSuccess = (user, isAdmin) => ({ type: actions.CHECK_LOGIN_SUCCESS, @@ -286,26 +285,26 @@ const checkLoginSuccess = (user, isAdmin) => ({ isAdmin }); -export const checkLogin = () => dispatch => { +export const checkLogin = () => (dispatch) => { dispatch(checkLoginRequest()); coralApi('/auth') - .then(result => { + .then((result) => { if (!result.user) { Storage.removeItem('token'); throw new Error('Not logged in'); } - const isAdmin = !!result.user.roles.filter(i => i === 'ADMIN').length; + const isAdmin = !!result.user.roles.filter((i) => i === 'ADMIN').length; dispatch(checkLoginSuccess(result.user, isAdmin)); }) - .catch(error => { + .catch((error) => { console.error(error); dispatch(checkLoginFailure(`${error.translation_key}`)); }); }; export const validForm = () => ({type: actions.VALID_FORM}); -export const invalidForm = error => ({type: actions.INVALID_FORM, error}); +export const invalidForm = (error) => ({type: actions.INVALID_FORM, error}); //============================================================================== // VERIFY EMAIL @@ -323,7 +322,7 @@ const verifyEmailFailure = () => ({ type: actions.VERIFY_EMAIL_FAILURE }); -export const requestConfirmEmail = (email, redirectUri) => dispatch => { +export const requestConfirmEmail = (email, redirectUri) => (dispatch) => { dispatch(verifyEmailRequest()); return coralApi('/users/resend-verify', { method: 'POST', @@ -333,7 +332,8 @@ export const requestConfirmEmail = (email, redirectUri) => dispatch => { .then(() => { dispatch(verifyEmailSuccess()); }) - .catch(err => { + .catch((err) => { + // email might have already been verifyed dispatch(verifyEmailFailure(err)); }); diff --git a/client/coral-framework/helpers/storage.js b/client/coral-framework/helpers/storage.js index d6bb280c2..ec83c3fb3 100644 --- a/client/coral-framework/helpers/storage.js +++ b/client/coral-framework/helpers/storage.js @@ -86,8 +86,7 @@ export function clear() { } } -// Enable this to debug WEB Storage events -window.addEventListener('storage', function(e) { - const msg = `${e.key} " was changed in page ${e.url} from ${e.oldValue} to ${e.newValue}`; - console.log(msg); -}); +// window.addEventListener('storage', function(e) { +// const msg = `${e.key} " was changed in page ${e.url} from ${e.oldValue} to ${e.newValue}`; +// console.log(msg); +// }); diff --git a/client/coral-sign-in/containers/SignInContainer.js b/client/coral-sign-in/containers/SignInContainer.js index d2095b527..de1d2086e 100644 --- a/client/coral-sign-in/containers/SignInContainer.js +++ b/client/coral-sign-in/containers/SignInContainer.js @@ -39,24 +39,26 @@ class SignInContainer extends Component { constructor(props) { super(props); this.state = this.initialState; + this.addError = this.addError.bind(this); + this.handleAuth = this.handleAuth.bind(this); + this.handleSignUp = this.handleSignUp.bind(this); + this.handleSignIn = this.handleSignIn.bind(this); this.handleChange = this.handleChange.bind(this); this.handleChangeEmail = this.handleChangeEmail.bind(this); this.handleResendVerification = this.handleResendVerification.bind(this); - this.handleSignUp = this.handleSignUp.bind(this); - this.handleSignIn = this.handleSignIn.bind(this); - this.addError = this.addError.bind(this); } static propTypes = { requireEmailConfirmation: PropTypes.bool.isRequired - } + }; - componentWillMount () { + componentWillMount() { this.props.checkLogin(); } componentDidMount() { - window.authCallback = this.props.facebookCallback; + window.addEventListener('storage', this.handleAuth); + const {formData} = this.state; const errors = Object.keys(formData).reduce((map, prop) => { map[prop] = lang.t('signIn.requiredField'); @@ -65,17 +67,36 @@ class SignInContainer extends Component { this.setState({errors}); } + componentWillUnmount() { + window.removeEventListener('storage', this.handleAuth); + } + + handleAuth(e) { + + // Listening to FB changes + // FB localStorage key is 'auth' + const authCallback = this.props.facebookCallback; + + if (e.key === 'auth') { + const {err, data} = JSON.parse(e.newValue); + authCallback(err, data); + } + } + handleChange(e) { const {name, value} = e.target; - this.setState((state) => ({ - ...state, - formData: { - ...state.formData, - [name]: value + this.setState( + (state) => ({ + ...state, + formData: { + ...state.formData, + [name]: value + } + }), + () => { + this.validation(name, value); } - }), () => { - this.validation(name, value); - }); + ); } handleChangeEmail(e) { @@ -85,7 +106,11 @@ class SignInContainer extends Component { handleResendVerification(e) { e.preventDefault(); - this.props.requestConfirmEmail(this.state.emailToBeResent, pym.parentUrl || location.href) + this.props + .requestConfirmEmail( + this.state.emailToBeResent, + pym.parentUrl || location.href + ) .then(() => { setTimeout(() => { @@ -110,12 +135,15 @@ class SignInContainer extends Component { if (!value.length) { addError(name, lang.t('signIn.requiredField')); - } else if (name === 'confirmPassword' && formData.confirmPassword !== formData.password) { + } else if ( + name === 'confirmPassword' && + formData.confirmPassword !== formData.password + ) { addError('confirmPassword', lang.t('signIn.passwordsDontMatch')); } else if (!validate[name](value)) { addError(name, errorMsj[name]); } else { - const { [name]: prop, ...errors } = this.state.errors; // eslint-disable-line + const {[name]: prop, ...errors} = this.state.errors; // eslint-disable-line // Removes Error this.setState((state) => ({...state, errors})); } @@ -181,14 +209,12 @@ const mapDispatchToProps = (dispatch) => ({ fetchSignInFacebook: () => dispatch(fetchSignInFacebook()), fetchSignUpFacebook: () => dispatch(fetchSignUpFacebook()), fetchForgotPassword: (formData) => dispatch(fetchForgotPassword(formData)), - requestConfirmEmail: (email, url) => dispatch(requestConfirmEmail(email, url)), + requestConfirmEmail: (email, url) => + dispatch(requestConfirmEmail(email, url)), changeView: (view) => dispatch(changeView(view)), handleClose: () => dispatch(hideSignInDialog()), invalidForm: (error) => dispatch(invalidForm(error)), validForm: () => dispatch(validForm()) }); -export default connect( - mapStateToProps, - mapDispatchToProps -)(SignInContainer); +export default connect(mapStateToProps, mapDispatchToProps)(SignInContainer); From df843a23ddfafe416cd705de485f103a303b62f7 Mon Sep 17 00:00:00 2001 From: Belen Curcio Date: Tue, 16 May 2017 00:09:33 -0300 Subject: [PATCH 4/9] updated loc --- yarn.lock | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/yarn.lock b/yarn.lock index 3b6abc40f..20d7b20da 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4604,9 +4604,9 @@ jwt-decode@^2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/jwt-decode/-/jwt-decode-2.2.0.tgz#7d86bd56679f58ce6a84704a657dd392bba81a79" -kareem@1.4.0: - version "1.4.0" - resolved "https://registry.yarnpkg.com/kareem/-/kareem-1.4.0.tgz#640285bc0174f10d4bf2127bb30e861bc0372c1c" +kareem@1.4.1: + version "1.4.1" + resolved "https://registry.yarnpkg.com/kareem/-/kareem-1.4.1.tgz#ed76200044fa041ef32b4da8261e2553f1173531" keymaster@^1.6.2: version "1.6.2" @@ -5250,14 +5250,14 @@ mongodb@2.2.26: mongodb-core "2.1.10" readable-stream "2.2.7" -mongoose@^4.9.1: - version "4.9.6" - resolved "https://registry.yarnpkg.com/mongoose/-/mongoose-4.9.6.tgz#8485879893a33fe4b8c8b596950cfa9a8d597ec1" +mongoose@^4.9.8: + version "4.9.9" + resolved "https://registry.yarnpkg.com/mongoose/-/mongoose-4.9.9.tgz#8671fbe06c945f55fba7ad03797bc02f19516762" dependencies: async "2.1.4" bson "~1.0.4" hooks-fixed "2.0.0" - kareem "1.4.0" + kareem "1.4.1" mongodb "2.2.26" mpath "0.2.1" mpromise "0.5.5" From 81f51b69ecaaece7b87df4f4b94be1dc2c8b8a67 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Tue, 16 May 2017 17:13:19 +0700 Subject: [PATCH 5/9] Clear token before dispatching logout action --- client/coral-framework/actions/auth.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/coral-framework/actions/auth.js b/client/coral-framework/actions/auth.js index 03ab61c76..79fba460c 100644 --- a/client/coral-framework/actions/auth.js +++ b/client/coral-framework/actions/auth.js @@ -267,8 +267,8 @@ export const fetchForgotPassword = (email) => (dispatch) => { export const logout = () => (dispatch) => { return coralApi('/auth', {method: 'DELETE'}).then(() => { - dispatch({type: actions.LOGOUT}); Storage.removeItem('token'); + dispatch({type: actions.LOGOUT}); }); }; From ec19618052eb15e98aee45a1f43a83c244774129 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Tue, 16 May 2017 17:13:41 +0700 Subject: [PATCH 6/9] Readd login fixes --- client/coral-settings/containers/ProfileContainer.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/client/coral-settings/containers/ProfileContainer.js b/client/coral-settings/containers/ProfileContainer.js index 04e337b47..84c2c1642 100644 --- a/client/coral-settings/containers/ProfileContainer.js +++ b/client/coral-settings/containers/ProfileContainer.js @@ -25,6 +25,14 @@ class ProfileContainer extends Component { }; } + componentWillReceiveProps(nextProps) { + if (this.props.auth.loggedIn !== nextProps.auth.loggedIn) { + + // Refetch after login/logout. + this.props.data.refetch(); + } + } + handleTabChange = (tab) => { this.setState({ activeTab: tab @@ -39,7 +47,7 @@ class ProfileContainer extends Component { return ; } - if (data.loading) { + if (!me || data.loading) { return ; } From e1b80c33173a3f3d84a5bc9f6dc657065a48bd7a Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Tue, 16 May 2017 17:50:17 +0700 Subject: [PATCH 7/9] Only refetch for login --- client/coral-settings/containers/ProfileContainer.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/coral-settings/containers/ProfileContainer.js b/client/coral-settings/containers/ProfileContainer.js index 84c2c1642..a9355d918 100644 --- a/client/coral-settings/containers/ProfileContainer.js +++ b/client/coral-settings/containers/ProfileContainer.js @@ -26,9 +26,9 @@ class ProfileContainer extends Component { } componentWillReceiveProps(nextProps) { - if (this.props.auth.loggedIn !== nextProps.auth.loggedIn) { + if (!this.props.auth.loggedIn && nextProps.auth.loggedIn) { - // Refetch after login/logout. + // Refetch after login. this.props.data.refetch(); } } From 2ab8cc94810f6f434bbdf70ae0da08245703da20 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Tue, 16 May 2017 18:05:07 +0700 Subject: [PATCH 8/9] Allow Apollo to invalidate old user data --- client/coral-embed-stream/src/containers/Embed.js | 1 + client/coral-settings/containers/ProfileContainer.js | 1 + 2 files changed, 2 insertions(+) diff --git a/client/coral-embed-stream/src/containers/Embed.js b/client/coral-embed-stream/src/containers/Embed.js index 0ea577530..7309965a4 100644 --- a/client/coral-embed-stream/src/containers/Embed.js +++ b/client/coral-embed-stream/src/containers/Embed.js @@ -65,6 +65,7 @@ const EMBED_QUERY = gql` totalCommentCount(excludeIgnored: $excludeIgnored) } me { + id status } ...${getDefinitionName(Stream.fragments.root)} diff --git a/client/coral-settings/containers/ProfileContainer.js b/client/coral-settings/containers/ProfileContainer.js index 84c2c1642..7105f7e74 100644 --- a/client/coral-settings/containers/ProfileContainer.js +++ b/client/coral-settings/containers/ProfileContainer.js @@ -86,6 +86,7 @@ const withQuery = graphql( gql` query EmbedStreamProfileQuery { me { + id ignoredUsers { id, username, From 7d858c7b3f5ea77e7c524a137f6de09cd823b921 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Wed, 17 May 2017 01:25:06 +0700 Subject: [PATCH 9/9] Readd lastComment field to asset resolver --- graph/resolvers/asset.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/graph/resolvers/asset.js b/graph/resolvers/asset.js index 41710ba35..747e2534e 100644 --- a/graph/resolvers/asset.js +++ b/graph/resolvers/asset.js @@ -1,4 +1,11 @@ const Asset = { + lastComment({id}, _, {loaders: {Comments}}) { + return Comments.getByQuery({ + asset_id: id, + limit: 1, + parent_id: null + }).then((data) => data[0]); + }, recentComments({id}, _, {loaders: {Comments}}) { return Comments.genRecentComments.load(id); },