aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/github/daneren2005
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2016-02-09 17:23:33 -0800
committerScott Jackson <daneren2005@gmail.com>2016-02-09 17:23:33 -0800
commit19273a993c37a4f989faf326df03b9f396a5f1a5 (patch)
tree2b0467b3a6d1a3d6464624d25f6bc73f556c17d2 /app/src/main/java/github/daneren2005
parentc991a5db04792ad00cb6b1282d378c810dd297df (diff)
downloaddsub-19273a993c37a4f989faf326df03b9f396a5f1a5.tar.gz
dsub-19273a993c37a4f989faf326df03b9f396a5f1a5.tar.bz2
dsub-19273a993c37a4f989faf326df03b9f396a5f1a5.zip
Add requirement for current user password when changing as non-admin
Diffstat (limited to 'app/src/main/java/github/daneren2005')
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/UserUtil.java31
1 files changed, 22 insertions, 9 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/util/UserUtil.java b/app/src/main/java/github/daneren2005/dsub/util/UserUtil.java
index 3f16de21..a83e0935 100644
--- a/app/src/main/java/github/daneren2005/dsub/util/UserUtil.java
+++ b/app/src/main/java/github/daneren2005/dsub/util/UserUtil.java
@@ -29,8 +29,6 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
-import android.widget.ArrayAdapter;
-import android.widget.ListView;
import android.widget.TextView;
import github.daneren2005.dsub.R;
@@ -175,12 +173,7 @@ public final class UserUtil {
.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)) {
+ if(isPasswordCorrect(context, passwordView)) {
lastVerifiedTime = currentTime;
onSuccess.run();
} else {
@@ -199,8 +192,14 @@ public final class UserUtil {
public static void changePassword(final Activity context, final User user) {
View layout = context.getLayoutInflater().inflate(R.layout.change_password, null);
+ View currentPasswordLayout = layout.findViewById(R.id.current_password_layout);
+ final TextView currentPasswordView = (TextView) layout.findViewById(R.id.current_password);
final TextView passwordView = (TextView) layout.findViewById(R.id.new_password);
+ if(isCurrentAdmin()) {
+ currentPasswordLayout.setVisibility(View.GONE);
+ }
+
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.admin_change_password)
.setView(layout)
@@ -215,8 +214,12 @@ public final class UserUtil {
@Override
public void onClick(View v) {
final String password = passwordView.getText().toString();
+ if(!isCurrentAdmin() && !isPasswordCorrect(context, currentPasswordView)) {
+ Util.toast(context, R.string.admin_confirm_password_bad);
+ return;
+ }
// Don't allow blank passwords
- if ("".equals(password)) {
+ else if ("".equals(password)) {
Util.toast(context, R.string.admin_change_password_invalid);
return;
}
@@ -252,6 +255,16 @@ public final class UserUtil {
});
}
+ private static boolean isPasswordCorrect(Context context, TextView passwordView) {
+ return isPasswordCorrect(context, passwordView.getText().toString());
+ }
+ private static boolean isPasswordCorrect(Context context, String password) {
+ SharedPreferences prefs = Util.getPreferences(context);
+ String correctPassword = prefs.getString(Constants.PREFERENCES_KEY_PASSWORD + Util.getActiveServer(context), null);
+
+ return password != null && password.equals(correctPassword);
+ }
+
public static void updateSettings(final Context context, final User user) {
new SilentBackgroundTask<Void>(context) {
@Override