Search in sources :

Example 1 with CsrfTokenClient

use of org.wikipedia.csrf.CsrfTokenClient in project apps-android-wikipedia by wikimedia.

the class EditSectionActivity method getEditTokenThenSave.

private void getEditTokenThenSave(boolean forceLogin) {
    cancelCalls();
    captchaHandler.hideCaptcha();
    editSummaryFragment.saveSummary();
    csrfClient = new CsrfTokenClient(title.getWikiSite(), title.getWikiSite());
    csrfClient.request(forceLogin, new CsrfTokenClient.Callback() {

        @Override
        public void success(@NonNull String token) {
            doSave(token);
        }

        @Override
        public void failure(@NonNull Throwable caught) {
            showError(caught);
        }

        @Override
        public void twoFactorPrompt() {
            showError(new LoginClient.LoginFailedException(getResources().getString(R.string.login_2fa_other_workflow_error_msg)));
        }
    });
}
Also used : CsrfTokenClient(org.wikipedia.csrf.CsrfTokenClient)

Example 2 with CsrfTokenClient

use of org.wikipedia.csrf.CsrfTokenClient in project apps-android-wikipedia by wikimedia.

the class NotificationPollBroadcastReceiver method markRead.

public static void markRead(@NonNull WikiSite wiki, @NonNull List<Notification> notifications, boolean unread) {
    final String idListStr = TextUtils.join("|", notifications);
    CsrfTokenClient editTokenClient = new CsrfTokenClient(wiki, WikipediaApp.getInstance().getWikiSite());
    editTokenClient.request(new CsrfTokenClient.DefaultCallback() {

        @SuppressLint("CheckResult")
        @Override
        public void success(@NonNull String token) {
            ServiceFactory.get(wiki).markRead(token, unread ? null : idListStr, unread ? idListStr : null).subscribeOn(Schedulers.io()).subscribe(response -> {
            }, L::e);
        }
    });
}
Also used : Context(android.content.Context) ServiceFactory(org.wikipedia.dataclient.ServiceFactory) AccountUtil(org.wikipedia.auth.AccountUtil) AlarmManager(android.app.AlarmManager) R(org.wikipedia.R) Intent(android.content.Intent) SystemClock(android.os.SystemClock) TextUtils(android.text.TextUtils) CsrfTokenClient(org.wikipedia.csrf.CsrfTokenClient) HashMap(java.util.HashMap) PendingIntent(android.app.PendingIntent) NonNull(android.support.annotation.NonNull) BroadcastReceiver(android.content.BroadcastReceiver) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) WikiSite(org.wikipedia.dataclient.WikiSite) Prefs(org.wikipedia.settings.Prefs) ArrayList(java.util.ArrayList) TimeUnit(java.util.concurrent.TimeUnit) SuppressLint(android.annotation.SuppressLint) List(java.util.List) WikipediaApp(org.wikipedia.WikipediaApp) Map(java.util.Map) L(org.wikipedia.util.log.L) Schedulers(io.reactivex.schedulers.Schedulers) CsrfTokenClient(org.wikipedia.csrf.CsrfTokenClient) SuppressLint(android.annotation.SuppressLint)

Aggregations

CsrfTokenClient (org.wikipedia.csrf.CsrfTokenClient)2 SuppressLint (android.annotation.SuppressLint)1 AlarmManager (android.app.AlarmManager)1 PendingIntent (android.app.PendingIntent)1 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 Intent (android.content.Intent)1 SystemClock (android.os.SystemClock)1 NonNull (android.support.annotation.NonNull)1 TextUtils (android.text.TextUtils)1 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)1 Schedulers (io.reactivex.schedulers.Schedulers)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 TimeUnit (java.util.concurrent.TimeUnit)1 R (org.wikipedia.R)1 WikipediaApp (org.wikipedia.WikipediaApp)1 AccountUtil (org.wikipedia.auth.AccountUtil)1