From 33336256d0135df5a22273b28fd2bfade7136de7 Mon Sep 17 00:00:00 2001
From: Liam Cardenas <me@liamcardenas.com>
Date: Wed, 20 Dec 2017 10:56:54 -0800
Subject: [PATCH] Formuate proper recapthca request

---
 .../component/userEmailVerify/index.js        |  3 ++-
 .../component/userEmailVerify/view.jsx        | 16 ++++++++---
 src/renderer/redux/actions/user.js            | 27 ++++++++++++-------
 3 files changed, 32 insertions(+), 14 deletions(-)

diff --git a/src/renderer/component/userEmailVerify/index.js b/src/renderer/component/userEmailVerify/index.js
index e0fa0902b..2566f44b0 100644
--- a/src/renderer/component/userEmailVerify/index.js
+++ b/src/renderer/component/userEmailVerify/index.js
@@ -20,7 +20,8 @@ const select = state => ({
 });
 
 const perform = dispatch => ({
-  verifyUserEmail: code => dispatch(doUserEmailVerify(code)),
+  verifyUserEmail: (code, recaptcha) =>
+    dispatch(doUserEmailVerify(code, recaptcha)),
 });
 
 export default connect(select, perform)(UserEmailVerify);
diff --git a/src/renderer/component/userEmailVerify/view.jsx b/src/renderer/component/userEmailVerify/view.jsx
index 14faa8764..ee8b427ee 100644
--- a/src/renderer/component/userEmailVerify/view.jsx
+++ b/src/renderer/component/userEmailVerify/view.jsx
@@ -11,6 +11,7 @@ class UserEmailVerify extends React.PureComponent {
 
     this.state = {
       code: "",
+      recaptcha: "",
     };
   }
 
@@ -21,8 +22,14 @@ class UserEmailVerify extends React.PureComponent {
   }
 
   handleSubmit() {
-    const { code } = this.state;
-    this.props.verifyUserEmail(code);
+    const { code, recaptcha } = this.state;
+    this.props.verifyUserEmail(code, recaptcha);
+  }
+
+  verifyCallback(response) {
+    this.setState({
+      recaptcha: String(response).trim(),
+    });
   }
 
   render() {
@@ -46,7 +53,10 @@ class UserEmailVerify extends React.PureComponent {
           }}
           errorMessage={errorMessage}
         />
-        <Recaptcha sitekey="6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI" />
+        <Recaptcha
+          sitekey="6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI"
+          verifyCallback={this.verifyCallback.bind(this)}
+        />
         {/* render help separately so it always shows */}
         <div className="form-field__helper">
           <p>
diff --git a/src/renderer/redux/actions/user.js b/src/renderer/redux/actions/user.js
index 7111369e8..807090ad1 100644
--- a/src/renderer/redux/actions/user.js
+++ b/src/renderer/redux/actions/user.js
@@ -68,14 +68,14 @@ export function doUserEmailNew(email) {
         data: { email },
       });
       dispatch(doUserFetch());
-    }
+    };
 
     const failure = error => {
       dispatch({
         type: types.USER_EMAIL_NEW_FAILURE,
         data: { error },
       });
-    }
+    };
 
     lbryio
       .call(
@@ -86,12 +86,14 @@ export function doUserEmailNew(email) {
       )
       .catch(error => {
         if (error.response && error.response.status == 409) {
-          return lbryio.call(
-            "user_email",
-            "resend_token",
-            { email: email, only_if_expired: true },
-            "post"
-          ).then(success, failure);
+          return lbryio
+            .call(
+              "user_email",
+              "resend_token",
+              { email: email, only_if_expired: true },
+              "post"
+            )
+            .then(success, failure);
         }
         throw error;
       })
@@ -99,10 +101,11 @@ export function doUserEmailNew(email) {
   };
 }
 
-export function doUserEmailVerify(verificationToken) {
+export function doUserEmailVerify(verificationToken, recaptcha) {
   return function(dispatch, getState) {
     const email = selectEmailToVerify(getState());
     verificationToken = verificationToken.toString().trim();
+    recaptcha = recaptcha.toString().trim();
 
     dispatch({
       type: types.USER_EMAIL_VERIFY_STARTED,
@@ -113,7 +116,11 @@ export function doUserEmailVerify(verificationToken) {
       .call(
         "user_email",
         "confirm",
-        { verification_token: verificationToken, email: email },
+        {
+          verification_token: verificationToken,
+          email: email,
+          recaptcha: recaptcha,
+        },
         "post"
       )
       .then(userEmail => {