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

Feature/api v2 auth #141

Closed
wants to merge 62 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
2688257
login and set user_id from cookie
trickpattyFH20 Jun 6, 2018
f09b82c
store cookie and user login info
trickpattyFH20 Jun 7, 2018
60bbcb2
send login data to view
trickpattyFH20 Jun 7, 2018
ae132f3
- add CSRF cookie
trickpattyFH20 Jun 8, 2018
2d9edc3
csrf token fix cookie name
trickpattyFH20 Jun 8, 2018
22336d0
fix return fetch
trickpattyFH20 Jun 8, 2018
aa708e6
err handle for missing cookie
trickpattyFH20 Jun 8, 2018
392d9ee
lint
trickpattyFH20 Jun 8, 2018
53f8b4f
pull settings
trickpattyFH20 Jun 12, 2018
5942c8d
v2 loggout
trickpattyFH20 Jul 6, 2018
74ab458
settings conf and fix hanging promise
trickpattyFH20 Jul 10, 2018
258c2bf
pull user settings
trickpattyFH20 Jul 10, 2018
6583b4c
move api js from panel to background
trickpattyFH20 Jul 11, 2018
810c7d8
lint
trickpattyFH20 Jul 11, 2018
1d3423b
Enable log in init from the website.
jsignanini Jul 12, 2018
ee54389
Move auth/account domains to globals.
jsignanini Jul 12, 2018
885abf9
pull user settings on login and init
trickpattyFH20 Jul 12, 2018
545c6b5
lint
trickpattyFH20 Jul 12, 2018
dbb9941
Implement logout.
jsignanini Jul 12, 2018
f88d3a2
Implement send verify email.
jsignanini Jul 12, 2018
31df7c8
login data success missing
trickpattyFH20 Jul 12, 2018
e6d964c
Merge branch 'feature/api-v2-auth' of github.com:ghostery/ghostery-ex…
trickpattyFH20 Jul 12, 2018
260d988
pushUserSettings and remove unused
trickpattyFH20 Jul 12, 2018
d00a1eb
Implement create account v2.
jsignanini Jul 12, 2018
99da32f
Fix logout from platform pages not sending message to background.
jsignanini Jul 12, 2018
ac0213d
remove api from panel
trickpattyFH20 Jul 12, 2018
8fb4e18
Merge branch 'feature/api-v2-auth' of github.com:ghostery/ghostery-ex…
trickpattyFH20 Jul 12, 2018
b1f78fa
Fix missing function.
jsignanini Jul 12, 2018
cd56624
Merge branch 'feature/api-v2-auth' of github.com:ghostery/ghostery-ex…
jsignanini Jul 12, 2018
a695d77
Add error handling for v2 login.
jsignanini Jul 12, 2018
a584db6
move userLogin fetch to background
trickpattyFH20 Jul 12, 2018
70f62ff
forgot password email
trickpattyFH20 Jul 13, 2018
1a43e2f
fix lgmogout
trickpattyFH20 Jul 13, 2018
b988746
fix legacy settings conf
trickpattyFH20 Jul 13, 2018
8135136
setup login
trickpattyFH20 Jul 13, 2018
4172242
setup createAccount
trickpattyFH20 Jul 13, 2018
beb276d
move createAccount fetch
trickpattyFH20 Jul 13, 2018
1572834
Several refactors and fixes.
jsignanini Jul 13, 2018
49bf9b1
Remove catch from logout.
jsignanini Jul 16, 2018
02981a8
account actions unit tests
trickpattyFH20 Jul 16, 2018
dc44e85
Merge branch 'feature/api-v2-auth' of github.com:ghostery/ghostery-ex…
trickpattyFH20 Jul 16, 2018
c6f2f16
lint
trickpattyFH20 Jul 16, 2018
1348cb7
Further refactor.
jsignanini Jul 16, 2018
d18d847
Refactor account.register.
jsignanini Jul 16, 2018
5e547e2
Refactor send validate account email.
jsignanini Jul 16, 2018
5418b62
Refactor reset password.
jsignanini Jul 17, 2018
a525f8d
More refactoring.
jsignanini Jul 17, 2018
0c7e1d8
fix unit test
trickpattyFH20 Jul 17, 2018
7027d39
Merge branch 'feature/api-v2-auth' of github.com:ghostery/ghostery-ex…
trickpattyFH20 Jul 17, 2018
8032ca3
Linter fix.
jsignanini Jul 17, 2018
ac8eee0
fix login_info unit tests
trickpattyFH20 Jul 17, 2018
8b455a1
Add specific babel-loader for background source files.
jsignanini Jul 18, 2018
9fb0e71
refresh token logout handler - api as class
trickpattyFH20 Jul 18, 2018
82f499e
export _getJSONAPIErrorsObject - move getCsrfCookie to api
trickpattyFH20 Jul 18, 2018
c6836b9
lint
trickpattyFH20 Jul 18, 2018
ce0b31f
Refactor account into own component.
jsignanini Jul 18, 2018
f17f476
Move logged in check into Account class. Cleanup.
jsignanini Jul 18, 2018
beef14e
Refactor account in setup page.
jsignanini Jul 19, 2018
b570527
Refactor setup page header log in.
jsignanini Jul 19, 2018
07ab815
Merge branch 'develop' into feature/api-v2-auth
jsignanini Jul 19, 2018
220cec8
lint - use logger in ExtMessenger
trickpattyFH20 Jul 19, 2018
b550262
update tests
trickpattyFH20 Jul 19, 2018
File filter
Filter file types
Jump to
Jump to file
Failed to load files.

Always

Just for now

Refactor account in setup page.
  • Loading branch information
jsignanini committed Jul 19, 2018
commit beef14e00864ba0625a0a5a63e3a936101490a2a
@@ -11,16 +11,15 @@ import {
RESET_PASSWORD_FAIL,
GET_USER_SUCCESS,
GET_USER_FAIL,

GET_SETTINGS_DATA
GET_USER_SETTINGS_SUCCESS
} from './AccountConstants';

export const getUserSettings = () => dispatch => (
sendMessageInPromise('account.getUserSettings')
.then((settings) => {
dispatch({
type: GET_SETTINGS_DATA,
data: { settingsData: settings }
type: GET_USER_SETTINGS_SUCCESS,
payload: { settings },
});
})
.catch((error) => {
@@ -30,12 +29,20 @@ export const getUserSettings = () => dispatch => (

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

@@ -57,8 +57,8 @@ export default (state = initialState, action) => {
return Object.assign({}, state, { user });
}
case GET_USER_SETTINGS_SUCCESS: {
const { userSettings } = action.payload;
return Object.assign({}, state, { userSettings });
const { settings } = action.payload;
return Object.assign({}, state, { userSettings: settings });
}
default: return state;
}
@@ -26,9 +26,9 @@ import {
SETTINGS_TOGGLE_EXPAND_CATEGORY,
SETTINGS_UPDATE_SEARCH_VALUE,
SETTINGS_SEARCH_SUBMIT,
SETTINGS_FILTER
SETTINGS_FILTER,
GET_SETTINGS_DATA
} from '../constants/constants';
import { GET_SETTINGS_DATA } from '../../Account/AccountConstants';
import { sendMessageInPromise } from '../utils/msg';
import { hashCode } from '../../../src/utils/common';
import globals from '../../../src/classes/Globals';
@@ -63,3 +63,4 @@ export const SETTINGS_TOGGLE_EXPAND_ALL = 'SETTINGS_TOGGLE_EXPAND_ALL';
export const SETTINGS_TOGGLE_EXPAND_CATEGORY = 'SETTINGS_TOGGLE_EXPAND_CATEGORY';
export const SETTINGS_UPDATE_SEARCH_VALUE = 'SETTINGS_UPDATE_SEARCH_VALUE';
export const SETTINGS_FILTER = 'SETTINGS_FILTER';
export const GET_SETTINGS_DATA = 'GET_SETTINGS_DATA';
@@ -32,7 +32,6 @@ import {
LOGOUT_SUCCESS,
REGISTER_SUCCESS,
REGISTER_FAIL,
LOGIN_DATA_SUCCESS,
RESET_PASSWORD_SUCCESS,
RESET_PASSWORD_FAIL
} from '../../Account/AccountConstants';
@@ -167,13 +166,6 @@ export default (state = initialState, action) => {
const updated = _showNotification(state, action);
return Object.assign({}, state, updated);
}
case LOGIN_DATA_SUCCESS: {
const { email, emailValidated } = action.data;
return Object.assign({}, state, {
email,
emailValidated,
});
}
case TOGGLE_CLIQZ_FEATURE: {
let pingName = '';
switch (action.data.featureName) {
@@ -28,9 +28,9 @@ import {
SETTINGS_TOGGLE_EXPAND_ALL,
SETTINGS_TOGGLE_EXPAND_CATEGORY,
SETTINGS_UPDATE_SEARCH_VALUE,
SETTINGS_FILTER
SETTINGS_FILTER,
GET_SETTINGS_DATA
} from '../constants/constants';
import { GET_SETTINGS_DATA } from '../../Account/AccountConstants';
import { updateTrackerBlocked, updateCategoryBlocked, updateBlockAllTrackers, toggleExpandAll, toggleExpandCategory } from '../utils/blocking';
import { removeFromObject, updateObject } from '../utils/utils';
import { sendMessage } from '../utils/msg';
@@ -10,178 +10,8 @@
* 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 'whatwg-fetch';
import normalize from 'json-api-normalizer';
import build from 'redux-object';
import {
GET_LOGIN_INFO,
LOGIN_SUCCESS,
LOGIN_FAIL,
CREATE_ACCOUNT_SUCCESS,
CREATE_ACCOUNT_FAIL,
CLEAR_MESSAGE
} from '../constants/constants';
import { msg, utils } from '../utils';
import globals from '../../../src/classes/Globals';
import { decodeJwt, log } from '../../../src/utils/common';
import { CLEAR_MESSAGE } from '../constants/constants';

const API_ROOT_URL = `https://consumerapi.${globals.GHOSTERY_DOMAIN}.com`;
export const clearMessage = () => ({ type: CLEAR_MESSAGE });

/**
* called from Header.clearMessage
* @return {Object}
* @memberof SetupActions
*/
export function clearMessage() {
return {
type: CLEAR_MESSAGE,
};
}

/**
* Called from LogInView.componentWillMount()
* @return {Object}
* @memberof SetupActions
*/
export function getLoginInfo() {
return function (dispatch) {
return msg.sendMessageInPromise('fetchUser')
.then((user) => {
dispatch({
type: GET_LOGIN_INFO,
data: user,
});
});
};
}

/**
* Called from LogInView._createAccount()
* @return {Object}
* @memberof SetupActions
*/
export function createAccountFail() {
return {
type: CREATE_ACCOUNT_FAIL,
data: '', // TODO
};
}

/**
* Called from LogInView._signIn()
* @return {Object}
* @memberof SetupActions
*/
export function loginFail() {
return {
type: LOGIN_FAIL,
data: '', // TODO
};
}

/**
* Call consumerAPI and set updated login info to state
* @param {Object} query
* @return {Object} dispatch
* @memberof SetupActions
*/
export function userLogin(email, password) {
return function (dispatch) {
const data = `email=${window.encodeURIComponent(email)}&password=${encodeURIComponent(password)}`;
return msg.sendMessageInPromise('userLogin', data)
.then((response) => {
if (response.errors) {
log('PanelActions userLogin server error', response);
response.errors.forEach((err) => {
let errorText = '';
switch (err.code) {
case '10050':
case '10110':
errorText = t('banner_no_such_account_message');
break;
default:
errorText = t('server_error_message');
}
dispatch({
type: LOGIN_FAIL,
data: errorText
});
});
return false;
}
return msg.sendMessageInPromise('fetchUser')
.then((user) => {
dispatch({
type: LOGIN_SUCCESS,
data: {
text: `${t('panel_signin_success')} ${email}`,
payload: { email }
}
});
});
})
.catch((err) => {
log('PanelActions userLogin server error', err);
dispatch({
type: LOGIN_FAIL,
data: t('server_error_message')
});
});
};
}

/**
* Call consumer API and create new account. Set new login info to state.
* @param {Object} query
* @return {Object} dispatch
* @memberof SetupActions
*/

export const createAccount = (email, confirmEmail, firstName, lastName, password) => (
function (dispatch) {
const data = `email=${window.encodeURIComponent(email)}&email_confirmation=${window.encodeURIComponent(confirmEmail)}&first_name=${window.encodeURIComponent(firstName)}&last_name=${window.encodeURIComponent(lastName)}&password=${window.encodeURIComponent(password)}`;
return msg.sendMessageInPromise('createAccount', data)
.then((response) => {
if (response.errors) {
response.errors.forEach((err) => {
let errorText = '';
switch (err.code) {
case '10070':
errorText = t('email_address_in_use');
break;
case '10080':
errorText = t('invalid_email_confirmation');
break;
default:
errorText = t('server_error_message');
}
dispatch({
type: CREATE_ACCOUNT_FAIL,
data: {
text: errorText,
classes: 'alert',
},
});
});
return;
}
dispatch({
type: CREATE_ACCOUNT_SUCCESS,
data: {
payload: { email },
text: `${t('panel_signin_success')} ${email}`
},
});
})
.catch((err) => {
log('PanelActions createAccount returned with an error', err);
dispatch({
type: CREATE_ACCOUNT_FAIL,
data: {
text: t('server_error_message'),
classes: 'alert',
},
});
});
}
);
export const reset = () => ({ type: 'RESET' });
@@ -17,8 +17,8 @@ import {
UPDATE_NAVIGATION_NEXT_BUTTON,
RESET_NAVIGATION_NEXT_BUTTON,
NAVIGATION_NEXT,
CREATE_ACCOUNT,
SIGN_IN
TRIGGER_LOGIN,
TRIGGER_REGISTER
} from '../constants/constants';
import { msg } from '../utils';

@@ -51,22 +51,14 @@ export function resetNavigationNextButton() {
* @return {Object}
* @memberof SetupActions
*/
export function triggerCreateAccount() {
return {
type: CREATE_ACCOUNT,
};
}
export const triggerCreateAccount = () => ({ type: TRIGGER_REGISTER });

/**
* Called from Navigation and LoginView views
* @return {Object}
* @memberof SetupActions
*/
export function triggerSignIn() {
return {
type: SIGN_IN,
};
}
export const triggerSignIn = () => ({ type: TRIGGER_LOGIN });

/**
* Called from Navigation._close()
ProTip! Use n and p to navigate between commits in a pull request.