Skip to content

Instantly share code, notes, and snippets.

@madsunrise
Created May 11, 2019 21:53
Show Gist options
  • Save madsunrise/81f2dc65536ed260126fece15ebe4028 to your computer and use it in GitHub Desktop.
Save madsunrise/81f2dc65536ed260126fece15ebe4028 to your computer and use it in GitHub Desktop.
public void isAuthorised(Callback callback) {
if (mSettings.contains(APP_PREFERENCES_LOGIN) && mSettings.contains(APP_PREFERENCES_PASSWORD)) {
final String login = mSettings.getString(APP_PREFERENCES_LOGIN, "");
final String passwd = mSettings.getString(APP_PREFERENCES_PASSWORD, "");
NetworkService.getInstance().getApi().getUserWithCreds(login, passwd).enqueue(new Callback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response) {
User u = response.body();
callback.onResult(u.isHasPermit());
}
@Override
public void onFailure(Call<User> call, Throwable t) {
Log.e(LOG_TAG, t.getMessage(), t);
callback.onResult(false);
}
});
} else {
callback.onResult(false);
}
public interface Callback {
void onResult(boolean authSuccessful);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment