diff --git a/package-lock.json b/package-lock.json index 61d820f..3200608 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1157,9 +1157,9 @@ } }, "@edx/frontend-platform": { - "version": "1.1.14", - "resolved": "https://registry.npmjs.org/@edx/frontend-platform/-/frontend-platform-1.1.14.tgz", - "integrity": "sha512-wEKKNcjKVNCHL0rgdXIlCF0dwRZc9kuuip2At7+LZ2CxPGJc3s4WGgcsA5yO16YjG2RV+gh2aZV5B/8aczM3Bw==", + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@edx/frontend-platform/-/frontend-platform-1.2.0.tgz", + "integrity": "sha512-fy3ergsRxozDofUyNvY62KU1+rZt6kZVdiSovMWYGGV7QYNYLnjyajfyb1gRhsnnRa6uubuIqcQOsH3AeLE4eg==", "requires": { "@cospired/i18n-iso-languages": "2.1.1", "axios": "0.18.1", @@ -1180,7 +1180,7 @@ "form-urlencoded": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/form-urlencoded/-/form-urlencoded-4.1.1.tgz", - "integrity": "sha512-q4SOWDgKw2Mmec2HNYzTNr/7ZXecEkO9QOwzpzx6q9HR+z+no6CsDFpAELdiyk7G3fUV5WvKy57utZxKgleqhg==" + "integrity": "sha1-Nv/xWCFoRT1XrYnVUAhbPJ3pv4I=" } } }, @@ -14603,7 +14603,7 @@ "pubsub-js": { "version": "1.7.0", "resolved": "https://registry.npmjs.org/pubsub-js/-/pubsub-js-1.7.0.tgz", - "integrity": "sha512-Pb68P9qFZxnvDipHMuj9oT1FoIgBcXJ9C9eWdHCLZAnulaUoJ3+Y87RhGMYilWpun6DMWVmvK70T4RP4drZMSA==" + "integrity": "sha1-7Kl/mkIXvvYrLTqqFVIAUmDMLkk=" }, "pump": { "version": "3.0.0", @@ -14734,8 +14734,7 @@ "querystring": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/querystring/-/querystring-0.2.0.tgz", - "integrity": "sha1-sgmEkgO7Jd+CDadW50cAWHhSFiA=", - "dev": true + "integrity": "sha1-sgmEkgO7Jd+CDadW50cAWHhSFiA=" }, "querystring-es3": { "version": "0.2.1", @@ -14950,7 +14949,7 @@ "react-intl": { "version": "2.9.0", "resolved": "https://registry.npmjs.org/react-intl/-/react-intl-2.9.0.tgz", - "integrity": "sha512-27jnDlb/d2A7mSJwrbOBnUgD+rPep+abmoJE511Tf8BnoONIAUehy/U1zZCHGO17mnOwMWxqN4qC0nW11cD6rA==", + "integrity": "sha1-yXxdF9RxjxV1/b1adp+WAYo7GEM=", "requires": { "hoist-non-react-statics": "^3.3.0", "intl-format-cache": "^2.0.5", diff --git a/package.json b/package.json index 6ae72d3..7d062fe 100755 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "dependencies": { "@edx/frontend-component-footer": "10.0.7", "@edx/frontend-component-header": "2.0.5", - "@edx/frontend-platform": "1.1.14", + "@edx/frontend-platform": "1.2.0", "@edx/paragon": "7.1.5", "@fortawesome/fontawesome-svg-core": "1.2.27", "@fortawesome/free-brands-svg-icons": "5.8.2", @@ -55,6 +55,7 @@ "memoize-one": "5.1.1", "newrelic": "5.13.1", "prop-types": "15.7.2", + "querystring": "0.2.0", "react": "16.10.2", "react-dom": "16.10.2", "react-redux": "7.1.3", diff --git a/src/registration/RegistrationPage.jsx b/src/registration/RegistrationPage.jsx index de58bf3..e016a76 100644 --- a/src/registration/RegistrationPage.jsx +++ b/src/registration/RegistrationPage.jsx @@ -8,7 +8,7 @@ import countryList from './countryList'; import { registerNewUser } from './data/actions'; -class RegistrationPage extends React.Component { +export class RegistrationPage extends React.Component { state = { email: '', name: '', diff --git a/src/registration/data/actions.js b/src/registration/data/actions.js index f7770ed..b702dd6 100644 --- a/src/registration/data/actions.js +++ b/src/registration/data/actions.js @@ -1,6 +1,7 @@ import { AsyncActionType } from './utils'; export const REGISTER_NEW_USER = new AsyncActionType('REGISTRATION', 'REGISTER_NEW_USER'); +export const LOGIN_REQUEST = new AsyncActionType('LOGIN', 'REQUEST'); // Register @@ -22,3 +23,19 @@ export const registerNewUserFailure = () => ({ }); // Login +export const loginRequest = registrationInfo => ({ + type: LOGIN_REQUEST.BASE, + payload: { registrationInfo }, +}); + +export const loginRequestBegin = () => ({ + type: LOGIN_REQUEST.BEGIN, +}); + +export const loginRequestSuccess = () => ({ + type: LOGIN_REQUEST.SUCCESS, +}); + +export const loginRequestFailure = () => ({ + type: LOGIN_REQUEST.FAILURE, +}); diff --git a/src/registration/data/reducers.js b/src/registration/data/reducers.js index 262de8d..2be4d4f 100644 --- a/src/registration/data/reducers.js +++ b/src/registration/data/reducers.js @@ -1,5 +1,6 @@ import { REGISTER_NEW_USER, + LOGIN_REQUEST, } from './actions'; export const defaultState = { @@ -20,6 +21,18 @@ const reducer = (state = defaultState, action) => { return { ...state, }; + case LOGIN_REQUEST.BEGIN: + return { + ...state, + }; + case LOGIN_REQUEST.SUCCESS: + return { + ...state, + }; + case LOGIN_REQUEST.FAILURE: + return { + ...state, + }; default: return state; } diff --git a/src/registration/data/sagas.js b/src/registration/data/sagas.js index ec5ad54..f0728b6 100644 --- a/src/registration/data/sagas.js +++ b/src/registration/data/sagas.js @@ -6,6 +6,10 @@ import { registerNewUserBegin, registerNewUserFailure, registerNewUserSuccess, + LOGIN_REQUEST, + loginRequestBegin, + loginRequestFailure, + loginRequestSuccess, } from './actions'; @@ -25,6 +29,20 @@ export function* handleNewUserRegistration(action) { } } +export function* handleLoginRequest(action) { + try { + yield put(loginRequestBegin()); + + yield call(postNewUser, action.payload.registrationInfo); + + yield put(loginRequestSuccess()); + } catch (e) { + yield put(loginRequestFailure()); + throw e; + } +} + export default function* saga() { yield takeEvery(REGISTER_NEW_USER.BASE, handleNewUserRegistration); + yield takeEvery(LOGIN_REQUEST.BASE, handleLoginRequest); } diff --git a/src/registration/data/service.js b/src/registration/data/service.js index eaa3606..6fbc7d5 100644 --- a/src/registration/data/service.js +++ b/src/registration/data/service.js @@ -1,16 +1,35 @@ import { getConfig } from '@edx/frontend-platform'; -import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth'; +import { getHttpClient } from '@edx/frontend-platform/auth'; +import querystring from 'querystring'; -export default async function postNewUser(registrationInformation) { +export async function postNewUser(registrationInformation) { const requestConfig = { headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, }; - console.log('rickie is fucken baller'); - const { data } = await getAuthenticatedHttpClient() + const { data } = await getHttpClient() .post( - `${getConfig().LMS_BASE_URL}user_api/v1/account/registration/`, - registrationInformation, + `${getConfig().LMS_BASE_URL}/user_api/v1/account/registration/`, + querystring.stringify(registrationInformation), + requestConfig, + ) + .catch((e) => { + console.log('You messed up'); + throw (e); + }); + + return data; +} + +export async function login(creds) { + const requestConfig = { + headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, + }; + + const { data } = await getHttpClient() + .post( + `${getConfig().LMS_BASE_URL}/user_api/v1/account/registration/`, + creds, requestConfig, ) .catch((e) => { diff --git a/src/registration/index.js b/src/registration/index.js index 4f975a2..6c670ac 100644 --- a/src/registration/index.js +++ b/src/registration/index.js @@ -1,4 +1,4 @@ -export { LoginPage } from './LoginPage'; +export { default as LoginPage } from './LoginPage'; export { RegistrationPage } from './RegistrationPage'; export { default as reducer } from './data/reducers'; export { default as saga } from './data/sagas';