コード例 #1
0
  public boolean logout() {
    try {
      SharedPreferences preferences =
          PreferenceManager.getDefaultSharedPreferences(App.getAppContext());
      List<AbstractMap.SimpleEntry<String, String>> params = new ArrayList<>();
      AbstractMap.SimpleEntry<String, String> username =
          new AbstractMap.SimpleEntry<>("username", preferences.getString("username", ""));
      AbstractMap.SimpleEntry<String, String> token =
          new AbstractMap.SimpleEntry<>("token", preferences.getString("token", ""));
      params.add(username);
      params.add(token);
      String response = App.HTMLPOST(App.Prefs().getString("domain", "") + "/API/logout", params);
      // TODO: Redo, this whole thing is flawed.
      if (response.equals("Logout successful")) {
        final SharedPreferences.Editor editor = preferences.edit();
        editor.clear();
        editor.commit();
        return true;
      }
      return false;

    } catch (Exception e) {
      return false;
    }
  }
コード例 #2
0
 // Account management functions
 private boolean login(String username, String token, String privlvl, String userid) {
   try {
     // NOTE: Why you shouldn't use sharedpreferences: https://stackoverflow.com/a/23698241
     SharedPreferences preferences =
         PreferenceManager.getDefaultSharedPreferences(App.getAppContext());
     final SharedPreferences.Editor editor = preferences.edit();
     editor.putString("username", username);
     editor.putString("token", token);
     editor.putString("privlvl", privlvl);
     editor.putString("userid", userid);
     editor.commit();
     return true;
   } catch (Exception e) {
     return false;
   }
 }