<commit_before>package fr.free.nrw.commons.auth;

import android.accounts.AccountAuthenticatorResponse;
import android.accounts.AccountManager;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;

import java.io.IOException;

import fr.free.nrw.commons.CommonsApplication;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.mwapi.EventLog;
import timber.log.Timber;

class LoginTask extends AsyncTask<String, String, String> {

    private LoginActivity loginActivity;
    private String username;
    private String password;
    private String twoFactorCode = "";
    private CommonsApplication app;

    public LoginTask(LoginActivity loginActivity, String username, String password, String twoFactorCode) {
        this.loginActivity = loginActivity;
        this.username = username;
        this.password = password;
        this.twoFactorCode = twoFactorCode;
        app = CommonsApplication.getInstance();
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        loginActivity.progressDialog = new ProgressDialog(loginActivity);
        loginActivity.progressDialog.setIndeterminate(true);
        loginActivity.progressDialog.setTitle(loginActivity.getString(R.string.logging_in_title));
        loginActivity.progressDialog.setMessage(loginActivity.getString(R.string.logging_in_message));
        loginActivity.progressDialog.setCanceledOnTouchOutside(false);
        loginActivity.progressDialog.show();
    }

    @Override
    protected String doInBackground(String... params) {
        try {
            if (twoFactorCode.isEmpty()) {
                return app.getMWApi().login(username, password);
            } else {
                return app.getMWApi().login(username, password, twoFactorCode);
            }
        } catch (IOException e) {
            // Do something better!
            return "NetworkFailure";
        }
    }

    @Override
    protected void onPostExecute(String result) {
        super.onPostExecute(result);
        EventLog.schema(CommonsApplication.EVENT_LOGIN_ATTEMPT)
                .param("username", username)
                .param("result", result)
                .log();

        if (result.equals("PASS")) {
            handlePassResult();
        } else {
            handleOtherResults(result);
        }
    }

    private void handlePassResult() {
        loginActivity.showSuccessToastAndDismissDialog();

        AccountAuthenticatorResponse response = null;

        Bundle extras = loginActivity.getIntent().getExtras();
        if (extras != null) {
            Timber.d("Bundle of extras: %s", extras);
            response = extras.getParcelable(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE);
            if (response != null) {
                Bundle authResult = new Bundle();
                authResult.putString(AccountManager.KEY_ACCOUNT_NAME, username);
                authResult.putString(AccountManager.KEY_ACCOUNT_TYPE, AccountUtil.accountType());
                response.onResult(authResult);
            }
        }

        AccountUtil.createAccount(response, username, password);
        loginActivity.startMainActivity();<commit_msg>Readding log that I accidently deleted<commit_after>package fr.free.nrw.commons.auth;

import android.accounts.AccountAuthenticatorResponse;
import android.accounts.AccountManager;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;

import java.io.IOException;

import fr.free.nrw.commons.CommonsApplication;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.mwapi.EventLog;
import timber.log.Timber;

class LoginTask extends AsyncTask<String, String, String> {

    private LoginActivity loginActivity;
    private String username;
    private String password;
    private String twoFactorCode = "";
    private CommonsApplication app;

    public LoginTask(LoginActivity loginActivity, String username, String password, String twoFactorCode) {
        this.loginActivity = loginActivity;
        this.username = username;
        this.password = password;
        this.twoFactorCode = twoFactorCode;
        app = CommonsApplication.getInstance();
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        loginActivity.progressDialog = new ProgressDialog(loginActivity);
        loginActivity.progressDialog.setIndeterminate(true);
        loginActivity.progressDialog.setTitle(loginActivity.getString(R.string.logging_in_title));
        loginActivity.progressDialog.setMessage(loginActivity.getString(R.string.logging_in_message));
        loginActivity.progressDialog.setCanceledOnTouchOutside(false);
        loginActivity.progressDialog.show();
    }

    @Override
    protected String doInBackground(String... params) {
        try {
            if (twoFactorCode.isEmpty()) {
                return app.getMWApi().login(username, password);
            } else {
                return app.getMWApi().login(username, password, twoFactorCode);
            }
        } catch (IOException e) {
            // Do something better!
            return "NetworkFailure";
        }
    }

    @Override
    protected void onPostExecute(String result) {
        super.onPostExecute(result);
        Timber.d("Login done!");
        EventLog.schema(CommonsApplication.EVENT_LOGIN_ATTEMPT)
                .param("username", username)
                .param("result", result)
                .log();

        if (result.equals("PASS")) {
            handlePassResult();
        } else {
            handleOtherResults(result);
        }
    }

    private void handlePassResult() {
        loginActivity.showSuccessToastAndDismissDialog();

        AccountAuthenticatorResponse response = null;

        Bundle extras = loginActivity.getIntent().getExtras();
        if (extras != null) {
            Timber.d("Bundle of extras: %s", extras);
            response = extras.getParcelable(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE);
            if (response != null) {
                Bundle authResult = new Bundle();
                authResult.putString(AccountManager.KEY_ACCOUNT_NAME, username);
                authResult.putString(AccountManager.KEY_ACCOUNT_TYPE, AccountUtil.accountType());
                response.onResult(authResult);
            }
        }

        AccountUtil.createAccount(response, username, password);
        loginActivity.startMainActivity();
{'fraction_non_alphanumeric': 0.09378862793572311, 'fraction_numerical': 0.0, 'mean_word_length': 2.7655613728912156, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3629673', 'n_tokens_mistral': 1692, 'n_tokens_neox': 1631, 'n_words': 310}