diff options
-rw-r--r-- | src/github/daneren2005/dsub/util/UserUtil.java | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/github/daneren2005/dsub/util/UserUtil.java b/src/github/daneren2005/dsub/util/UserUtil.java index 2d1b097a..50ee2b7c 100644 --- a/src/github/daneren2005/dsub/util/UserUtil.java +++ b/src/github/daneren2005/dsub/util/UserUtil.java @@ -43,8 +43,11 @@ import github.daneren2005.dsub.view.SettingsAdapter; public final class UserUtil {
private static final String TAG = UserUtil.class.getSimpleName();
+ private static final long MIN_VERIFY_DURATION = 1000L * 60L * 60L;
+
private static int instance = -1;
private static User currentUser;
+ private static long lastVerifiedTime = 0;
public static void refreshCurrentUser(Context context, boolean forceRefresh) {
currentUser = null;
@@ -137,6 +140,42 @@ public final class UserUtil { return false;
}
+
+ public static void confirmCredentials(final Context context, final Runnable onSuccess) {
+ final long currentTime = System.currentTimeMillis();
+ // If already ran this check within last x time, just go ahead and auth
+ if((currentTime - lastVerified) < MIN_VERIFY_DURATION) {
+ onSuccess.run();
+ } else {
+ View layout = context.getLayoutInflater().inflate(R.layout.verify_password, null);
+ final TextView passwordView = (TextView) layout.findViewById(R.id.password);
+
+ AlertDialog.Builder builder = new AlertDialog.Builder(context);
+ builder.setTitle(R.string.admin_confirm_password)
+ .setView(layout)
+ .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int id) {
+ String password = passwordView.getText().toString();
+
+ SharedPreferences prefs = Util.getPreferences(context);
+ String correctPassword = prefs.getString(Constants.PREFERENCES_KEY_PASSWORD + Util.getActiveServer(context), null);
+
+ if(password != null && password.equals(correctPassword)) {
+ lastVerified = currentTime;
+ onSuccess.run();
+ } else {
+ Util.toast(context, R.string.admin_confirm_password_bad);
+ }
+ }
+ })
+ .setNegativeButton(R.string.common_cancel, null)
+ .setCancellable(true);
+
+ AlertDialog dialog = builder.create();
+ dialog.show();
+ }
+ }
public static void changePassword(final Activity context, final User user) {
View layout = context.getLayoutInflater().inflate(R.layout.change_password, null);
|