Set "Android" as user agent when gettings captchas.

Don't reuse html.
captchafix2
Floens 11 years ago
parent b45db074cc
commit c37c1b77ae
  1. 20
      Clover/app/src/main/java/org/floens/chan/core/manager/ReplyManager.java
  2. 10
      Clover/app/src/main/java/org/floens/chan/ui/fragment/ReplyFragment.java

@ -321,8 +321,9 @@ public class ReplyManager {
public String responseData = ""; public String responseData = "";
} }
public void getCaptchaChallenge(final CaptchaChallengeListener listener, String reuseHtml) { public void getCaptchaChallenge(final CaptchaChallengeListener listener) {
HttpPost httpPost = new HttpPost(ChanUrls.getCaptchaFallback()); HttpPost httpPost = new HttpPost(ChanUrls.getCaptchaFallback());
httpPost.addHeader("User-Agent", "Android");
HttpPostSendListener postListener = new HttpPostSendListener() { HttpPostSendListener postListener = new HttpPostSendListener() {
@Override @Override
@ -350,11 +351,7 @@ public class ReplyManager {
} }
}; };
if (TextUtils.isEmpty(reuseHtml)) {
sendHttpPost(httpPost, postListener); sendHttpPost(httpPost, postListener);
} else {
postListener.onResponse(reuseHtml, null, null);
}
} }
public interface CaptchaChallengeListener { public interface CaptchaChallengeListener {
@ -381,17 +378,17 @@ public class ReplyManager {
Elements verificationToken = document.select("div.fbc-verification-token textarea"); Elements verificationToken = document.select("div.fbc-verification-token textarea");
String hash = verificationToken.text(); String hash = verificationToken.text();
if (hash.length() > 0) { if (hash.length() > 0) {
listener.onHash(hash, responseString); listener.onHash(hash);
return; return;
} }
} }
listener.onHash(null, responseString); listener.onHash(null);
} }
}); });
} }
private interface CaptchaHashListener { private interface CaptchaHashListener {
public void onHash(String hash, String html); public void onHash(String hash);
} }
/** /**
@ -406,13 +403,12 @@ public class ReplyManager {
CaptchaHashListener captchaHashListener = new CaptchaHashListener() { CaptchaHashListener captchaHashListener = new CaptchaHashListener() {
@Override @Override
public void onHash(String captchaHash, String captchaHtml) { public void onHash(String captchaHash) {
if (captchaHash == null && !reply.usePass) { if (captchaHash == null && !reply.usePass) {
// Could not find a hash in the response html // Could not find a hash in the response html
ReplyResponse e = new ReplyResponse(); ReplyResponse e = new ReplyResponse();
e.isUserError = true; e.isUserError = true;
e.isCaptchaError = true; e.isCaptchaError = true;
e.captchaHtml = captchaHtml;
listener.onResponse(e); listener.onResponse(e);
return; return;
} }
@ -512,7 +508,7 @@ public class ReplyManager {
}; };
if (reply.usePass) { if (reply.usePass) {
captchaHashListener.onHash(null, null); captchaHashListener.onHash(null);
} else { } else {
getCaptchaHash(captchaHashListener, reply.captchaChallenge, reply.captchaResponse); getCaptchaHash(captchaHashListener, reply.captchaChallenge, reply.captchaResponse);
} }
@ -563,8 +559,6 @@ public class ReplyManager {
* The thread no the post has * The thread no the post has
*/ */
public int threadNo = -1; public int threadNo = -1;
public String captchaHtml;
} }
/** /**

@ -204,7 +204,7 @@ public class ReplyFragment extends DialogFragment {
}); });
showCommentCount(); showCommentCount();
getCaptcha(null); getCaptcha();
} else { } else {
Logger.e(TAG, "Loadable in ReplyFragment was null"); Logger.e(TAG, "Loadable in ReplyFragment was null");
closeReply(); closeReply();
@ -263,7 +263,7 @@ public class ReplyFragment extends DialogFragment {
captchaContainer.setOnClickListener(new OnClickListener() { captchaContainer.setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
getCaptcha(null); getCaptcha();
} }
}); });
captchaInput = (TextView) container.findViewById(R.id.reply_captcha); captchaInput = (TextView) container.findViewById(R.id.reply_captcha);
@ -514,7 +514,7 @@ public class ReplyFragment extends DialogFragment {
loadView.setView(text); loadView.setView(text);
} }
private void getCaptcha(String reuseHtml) { private void getCaptcha() {
if (gettingCaptcha) if (gettingCaptcha)
return; return;
gettingCaptcha = true; gettingCaptcha = true;
@ -547,7 +547,7 @@ public class ReplyFragment extends DialogFragment {
captchaContainer.setView(text); captchaContainer.setView(text);
} }
} }
}, reuseHtml); });
} }
/** /**
@ -609,7 +609,7 @@ public class ReplyFragment extends DialogFragment {
cancelButton.setEnabled(true); cancelButton.setEnabled(true);
setClosable(true); setClosable(true);
flipPage(1); flipPage(1);
getCaptcha(response.captchaHtml); getCaptcha();
captchaInput.setText(""); captchaInput.setText("");
} else if (response.isSuccessful) { } else if (response.isSuccessful) {
shouldSaveDraft = false; shouldSaveDraft = false;

Loading…
Cancel
Save