mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 21:03:54 +01:00
Merge pull request #225 from misaochan/webview-activity
Account creation from within app (web view)
This commit is contained in:
commit
8b0bfbc11e
8 changed files with 124 additions and 11 deletions
|
|
@ -181,12 +181,6 @@ public class LoginActivity extends AccountAuthenticatorActivity {
|
|||
}
|
||||
});
|
||||
|
||||
signupButton.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://commons.wikimedia.org/wiki/Special:UserLogin/signup")));
|
||||
}
|
||||
});
|
||||
|
||||
loginButton.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
that.performLogin();
|
||||
|
|
@ -194,8 +188,15 @@ public class LoginActivity extends AccountAuthenticatorActivity {
|
|||
});
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
Intent welcomeIntent = new Intent(this, WelcomeActivity.class);
|
||||
startActivity(welcomeIntent);
|
||||
Bundle extras = getIntent().getExtras();
|
||||
// Only load welcome screen if we weren't redirected from SignupActivity
|
||||
if (extras == null || !extras.getBoolean("Redirected")) {
|
||||
if (extras != null) {
|
||||
Log.d("SignupActivity", "Redirected? " + Boolean.toString(extras.getBoolean("Redirected")));
|
||||
}
|
||||
Intent welcomeIntent = new Intent(this, WelcomeActivity.class);
|
||||
startActivity(welcomeIntent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -227,4 +228,9 @@ public class LoginActivity extends AccountAuthenticatorActivity {
|
|||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
//Called when Sign Up button is clicked
|
||||
public void signUp(View view) {
|
||||
Intent intent = new Intent(this, SignupActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,83 @@
|
|||
package fr.free.nrw.commons.auth;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.app.Activity;
|
||||
import android.util.Log;
|
||||
import android.webkit.CookieManager;
|
||||
import android.webkit.CookieSyncManager;
|
||||
import android.webkit.WebResourceResponse;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
import android.widget.Toast;
|
||||
|
||||
import fr.free.nrw.commons.R;
|
||||
|
||||
public class SignupActivity extends Activity {
|
||||
|
||||
private boolean otherPage;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Log.d("SignupActivity", "Signup Activity started");
|
||||
otherPage = false;
|
||||
|
||||
|
||||
WebView webView = new WebView(this);
|
||||
setContentView(webView);
|
||||
|
||||
webView.setWebViewClient(new MyWebViewClient());
|
||||
WebSettings webSettings = webView.getSettings();
|
||||
//Needed to refresh Captcha. Might introduce XSS vulnerabilities, but we can trust Wikimedia's site... right?
|
||||
webSettings.setJavaScriptEnabled(true);
|
||||
|
||||
webView.loadUrl("https://commons.m.wikimedia.org/w/index.php?title=Special:CreateAccount&returnto=Main+Page&returntoquery=welcome%3Dyes");
|
||||
}
|
||||
|
||||
private class MyWebViewClient extends WebViewClient {
|
||||
@Override
|
||||
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
||||
if (url.equals("https://commons.m.wikimedia.org/w/index.php?title=Main_Page&welcome=yes")) {
|
||||
//Signup success, so clear cookies, notify user, and load LoginActivity again
|
||||
Log.d("SignupActivity", "Overriding URL" + url);
|
||||
|
||||
CookieSyncManager.createInstance(getApplicationContext());
|
||||
CookieManager cookieManager = CookieManager.getInstance();
|
||||
cookieManager.removeAllCookie();
|
||||
cookieManager.setAcceptCookie(false);
|
||||
cookieManager.removeSessionCookie();
|
||||
|
||||
Toast toast = Toast.makeText(getApplicationContext(), "Account created!", Toast.LENGTH_LONG);
|
||||
toast.show();
|
||||
|
||||
Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
|
||||
intent.putExtra("Redirected", true);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
} else {
|
||||
//If user clicks any other links in the webview
|
||||
Log.d("SignupActivity", "Not overriding URL, URL is: " + url);
|
||||
otherPage = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (otherPage == true) {
|
||||
//If we are in any page except the main signup page, back button should take us back to signup page
|
||||
Intent intent = new Intent(this, SignupActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
else {
|
||||
//If we are in signup page, back button should take us back to LoginActivity
|
||||
Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
|
||||
intent.putExtra("Redirected", true);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue