aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2014-07-15 15:51:49 -0700
committerScott Jackson <daneren2005@gmail.com>2014-07-15 15:51:49 -0700
commitd04a5041c3467e5a289f6af3b07fbcb20a6ea078 (patch)
treed116ec8c98c46322e41d2028cccb33c9b8ef6f43 /src
parent9de00f4464e5cab586c578ce6ccb337d3c9416d9 (diff)
downloaddsub-d04a5041c3467e5a289f6af3b07fbcb20a6ea078.tar.gz
dsub-d04a5041c3467e5a289f6af3b07fbcb20a6ea078.tar.bz2
dsub-d04a5041c3467e5a289f6af3b07fbcb20a6ea078.zip
#368 Added util method to ask user for credentials
Diffstat (limited to 'src')
-rw-r--r--src/github/daneren2005/dsub/util/UserUtil.java39
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);