Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rebased version of feature/api-v2-auth #142

Merged
merged 57 commits into from Jul 19, 2018
Merged
Changes from 1 commit
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
23e1b35
login and set user_id from cookie
trickpattyFH20 Jun 6, 2018
8ecd35a
store cookie and user login info
trickpattyFH20 Jun 7, 2018
db13668
send login data to view
trickpattyFH20 Jun 7, 2018
1ff2067
- add CSRF cookie
trickpattyFH20 Jun 8, 2018
599e4e3
csrf token fix cookie name
trickpattyFH20 Jun 8, 2018
edf35fd
fix return fetch
trickpattyFH20 Jun 8, 2018
3151da8
err handle for missing cookie
trickpattyFH20 Jun 8, 2018
ce7210b
lint
trickpattyFH20 Jun 8, 2018
ce13c38
pull settings
trickpattyFH20 Jun 12, 2018
497549f
v2 loggout
trickpattyFH20 Jul 6, 2018
775e73f
settings conf and fix hanging promise
trickpattyFH20 Jul 10, 2018
c9750f4
pull user settings
trickpattyFH20 Jul 10, 2018
b1ef9a1
move api js from panel to background
trickpattyFH20 Jul 11, 2018
321591d
lint
trickpattyFH20 Jul 11, 2018
6cb0214
Enable log in init from the website.
jsignanini Jul 12, 2018
1ff0dee
Move auth/account domains to globals.
jsignanini Jul 12, 2018
f9cdde2
pull user settings on login and init
trickpattyFH20 Jul 12, 2018
95267b0
lint
trickpattyFH20 Jul 12, 2018
6f3a1c9
Implement logout.
jsignanini Jul 12, 2018
8925f31
Implement send verify email.
jsignanini Jul 12, 2018
ceab22a
login data success missing
trickpattyFH20 Jul 12, 2018
8bc68d9
pushUserSettings and remove unused
trickpattyFH20 Jul 12, 2018
f9ca859
Implement create account v2.
jsignanini Jul 12, 2018
f9353d8
Fix logout from platform pages not sending message to background.
jsignanini Jul 12, 2018
13cb22f
remove api from panel
trickpattyFH20 Jul 12, 2018
1586b4a
Fix missing function.
jsignanini Jul 12, 2018
20027a2
Add error handling for v2 login.
jsignanini Jul 12, 2018
01bc2f3
move userLogin fetch to background
trickpattyFH20 Jul 12, 2018
d6d1cb8
forgot password email
trickpattyFH20 Jul 13, 2018
2bcb36d
fix lgmogout
trickpattyFH20 Jul 13, 2018
a890e69
fix legacy settings conf
trickpattyFH20 Jul 13, 2018
e014e5a
setup login
trickpattyFH20 Jul 13, 2018
170ff18
setup createAccount
trickpattyFH20 Jul 13, 2018
b00d98b
move createAccount fetch
trickpattyFH20 Jul 13, 2018
dc161b6
Several refactors and fixes.
jsignanini Jul 13, 2018
92bba03
Remove catch from logout.
jsignanini Jul 16, 2018
287fcef
account actions unit tests
trickpattyFH20 Jul 16, 2018
96baf39
lint
trickpattyFH20 Jul 16, 2018
785f318
Further refactor.
jsignanini Jul 16, 2018
954d689
Refactor account.register.
jsignanini Jul 16, 2018
3287c98
Refactor send validate account email.
jsignanini Jul 16, 2018
8ab1b9c
Refactor reset password.
jsignanini Jul 17, 2018
77b62e7
More refactoring.
jsignanini Jul 17, 2018
973cbc2
fix unit test
trickpattyFH20 Jul 17, 2018
ec5b159
Linter fix.
jsignanini Jul 17, 2018
a1cf6eb
fix login_info unit tests
trickpattyFH20 Jul 17, 2018
0551439
Add specific babel-loader for background source files.
jsignanini Jul 18, 2018
f3d91e2
refresh token logout handler - api as class
trickpattyFH20 Jul 18, 2018
b803acc
export _getJSONAPIErrorsObject - move getCsrfCookie to api
trickpattyFH20 Jul 18, 2018
03b6630
lint
trickpattyFH20 Jul 18, 2018
0a24cf2
Refactor account into own component.
jsignanini Jul 18, 2018
4ab01fc
Move logged in check into Account class. Cleanup.
jsignanini Jul 18, 2018
b254b0e
Refactor account in setup page.
jsignanini Jul 19, 2018
c96f307
Refactor setup page header log in.
jsignanini Jul 19, 2018
0bafa11
lint - use logger in ExtMessenger
trickpattyFH20 Jul 19, 2018
736afa7
update tests
trickpattyFH20 Jul 19, 2018
c244fb9
Update to be in sync with develop branch
IAmThePan Jul 19, 2018
File filter
Filter file types
Jump to
Jump to file
Failed to load files.

Always

Just for now

Refactor account into own component.
  • Loading branch information
jsignanini authored and IAmThePan committed Jul 19, 2018
commit 0a24cf2a5acf95c80bb3c7f8e1dceac083bbe38f
@@ -0,0 +1,134 @@
import { sendMessageInPromise } from '../panel/utils/msg';
import { log } from '../../src/utils/common';
import {
REGISTER_SUCCESS,
REGISTER_FAIL,
LOGIN_SUCCESS,
LOGIN_FAIL,
LOGOUT_SUCCESS,
LOGOUT_FAIL,
RESET_PASSWORD_SUCCESS,
RESET_PASSWORD_FAIL,
GET_USER_SUCCESS,
GET_USER_FAIL,

GET_SETTINGS_DATA
} from './AccountConstants';

export const getUserSettings = () => dispatch => (
sendMessageInPromise('account.getUserSettings')
.then((settings) => {
dispatch({
type: GET_SETTINGS_DATA,
data: { settingsData: settings }
});
})
.catch((error) => {
log('PanelActions getUserSettings error', error);
})
);

export const getUser = () => dispatch => (
sendMessageInPromise('account.getUser')
.then((user) => {
dispatch({
type: GET_USER_SUCCESS,
payload: { user },
});
return user;
})
);

export const login = (email, password) => dispatch => (
sendMessageInPromise('account.login', { email, password })
.then((res) => {
const { errors } = res;
if (errors) {
dispatch({
type: LOGIN_FAIL,
payload: { errors },
});
return false;
}
dispatch({
type: LOGIN_SUCCESS,
payload: { email },
});
return true;
})
.catch((err) => {
log('account.login() error:', err);
dispatch({
type: LOGIN_FAIL,
payload: {
errors: [{ title: err.toString(), detail: err.toString() }],
},
});
})
);

export const register = (email, confirmEmail, firstName, lastName, password) => dispatch => (
sendMessageInPromise('account.register', {
email, confirmEmail, firstName, lastName, password
}).then((res) => {
const { errors } = res;
if (errors) {
dispatch({
type: REGISTER_FAIL,
payload: { errors },
});
return false;
}
dispatch({
type: REGISTER_SUCCESS,
payload: { email },
});
return true;
}).catch((err) => {
dispatch({
type: REGISTER_FAIL,
payload: {
errors: [{ title: err.toString(), detail: err.toString() }],
},
});
})
);

export const logout = () => dispatch => (
sendMessageInPromise('account.logout', {})
.then(() => {
dispatch({ type: LOGOUT_SUCCESS });
})
.catch((err) => {
dispatch({
type: LOGOUT_FAIL,
payload: {
errors: [{ title: err.toString(), detail: err.toString() }],
},
});
})
);

export const resetPassword = email => dispatch => (
sendMessageInPromise('account.resetPassword', { email })
.then((res) => {
const { errors } = res;
if (errors) {
dispatch({
type: RESET_PASSWORD_FAIL,
payload: { errors },
});
return false;
}
dispatch({ type: RESET_PASSWORD_SUCCESS });
return true;
})
.catch((err) => {
dispatch({
type: RESET_PASSWORD_FAIL,
payload: {
errors: [{ title: err.toString(), detail: err.toString() }],
},
});
})
);
@@ -0,0 +1,12 @@
export const LOGIN_SUCCESS = 'LOGIN_SUCCESS';
export const LOGIN_FAIL = 'LOGIN_FAIL';
export const REGISTER_SUCCESS = 'REGISTER_SUCCESS';
export const REGISTER_FAIL = 'REGISTER_FAIL';
export const LOGOUT_SUCCESS = 'LOGOUT_SUCCESS';
export const LOGOUT_FAIL = 'LOGOUT_FAIL';
export const RESET_PASSWORD_SUCCESS = 'RESET_PASSWORD_SUCCESS';
export const RESET_PASSWORD_FAIL = 'RESET_PASSWORD_FAIL';
export const GET_USER_SUCCESS = 'GET_USER_SUCCESS';
export const GET_USER_FAIL = 'GET_USER_FAIL';
export const GET_USER_SETTINGS_SUCCESS = 'GET_USER_SETTINGS_SUCCESS';
export const GET_USER_SETTINGS_FAIL = 'GET_USER_SETTINGS_FAIL';
@@ -0,0 +1,65 @@
/**
* Account Reducer
*
* Ghostery Browser Extension
* https://www.ghostery.com/
*
* Copyright 2018 Ghostery, Inc. All rights reserved.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0
*/

import {
LOGIN_SUCCESS,
LOGOUT_SUCCESS,
REGISTER_SUCCESS,
GET_USER_SUCCESS,
GET_USER_SETTINGS_SUCCESS
} from './AccountConstants';
import { GET_PANEL_DATA } from '../panel/constants/constants';
import { sendMessage } from '../panel/utils/msg';

const initialState = {
loggedIn: false,
userID: '',
user: null,
userSettings: null,
};

export default (state = initialState, action) => {
switch (action.type) {
case GET_PANEL_DATA: {
const { account } = action.data;
if (account === null) {
return Object.assign({}, initialState);
}
const { userID, user, userSettings } = account;
return Object.assign({}, state, {
loggedIn: true,
userID,
user,
userSettings,
});
}
case REGISTER_SUCCESS:
case LOGIN_SUCCESS: {
return Object.assign({}, state, {
loggedIn: true,
});
}
case LOGOUT_SUCCESS: {
return Object.assign({}, initialState);
}
case GET_USER_SUCCESS: {
const { user } = action.payload;
return Object.assign({}, state, { user });
}
case GET_USER_SETTINGS_SUCCESS: {
const { userSettings } = action.payload;
return Object.assign({}, state, { userSettings });
}
default: return state;
}
};
@@ -13,12 +13,12 @@

import configureStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import * as msg from '../../utils/msg';
import * as msg from '../../panel/utils/msg';
import * as accountActions from '../AccountActions';
import {
LOGIN_FAILED, SHOW_NOTIFICATION, LOGIN_SUCCESS,
GET_SETTINGS_DATA, LOGIN_DATA_SUCCESS, LOGOUT
} from '../../constants/constants';
} from '../AccountConstants';

// Fake the translation function to only return the translation key
global.t = function (str) {
ProTip! Use n and p to navigate between commits in a pull request.