mango r176 - in trunk: . lib www



Author: ovitters
Date: Sun Jun  1 00:03:43 2008
New Revision: 176
URL: http://svn.gnome.org/viewvc/mango?rev=176&view=rev

Log:
	* lib/util.php: Add array_same helper function.
	* www/update_user.php: Fix logic once again (PHP is weird). Further,
	check if the user was changed before attempting an update.



Modified:
   trunk/ChangeLog
   trunk/lib/util.php
   trunk/www/update_user.php

Modified: trunk/lib/util.php
==============================================================================
--- trunk/lib/util.php	(original)
+++ trunk/lib/util.php	Sun Jun  1 00:03:43 2008
@@ -34,4 +34,12 @@
     return $return_fingerprint ? rtrim(chunk_split(md5($certificate), 2, ':'), ':') . ' ' . $comment : true;
 }
 
+function array_same($array1, $array2) {
+    # Note: assumes no duplicate entries!
+    return (count($array1) != count($array2)
+            || count(array_diff($array1, $array2)) > 0
+            || count(array_diff($array2, $array1)) > 0);
+
+}
+
 ?>

Modified: trunk/www/update_user.php
==============================================================================
--- trunk/www/update_user.php	(original)
+++ trunk/www/update_user.php	Sun Jun  1 00:03:43 2008
@@ -124,9 +124,9 @@
 
         $changes = false;
         if (!empty($_POST['updateuser'])) {
-            $changes = ($this->process_general_tab($dom, $formnode)) or $changes; // NOTE: Make sure or $changes is last!
-            $changes = ($this->process_sshkeys_tab($dom, $formnode)) or $changes;
-            $changes = ($this->process_groups_tab($dom, $formnode)) or $changes;
+            $changes = $this->process_general_tab($dom, $formnode) ? true : $changes; // NOTE: Needs to be like this
+            $changes = $this->process_sshkeys_tab($dom, $formnode) ? true : $changes;
+            $changes = $this->process_groups_tab($dom, $formnode)  ? true : $changes;
 
             if ($changes) {
                 $formerrors = $this->user->validate();
@@ -186,6 +186,8 @@
     function process_sshkeys_tab(&$dom, &$formnode) {   
         // Read form and validate
         // XXX - compare arrays to check if user changed
+        $prevkeys = array_unique($this->user->authorizedKeys);
+
         $this->user->authorizedKeys = array();
         if($_FILES['keyfile']['tmp_name']) {
             $keyfile = file_get_contents($_FILES['keyfile']['tmp_name']);
@@ -203,12 +205,14 @@
         // Deduplicate keys
         $this->user->authorizedKeys = array_unique($this->user->authorizedKeys);
 
-        return true;
+        return array_same($prevkeys, $this->user->authorizedKeys);
     }
     
     function process_groups_tab(&$dom, &$formnode) {    
         global $AFFECTEDGROUPS;
 
+        $prevgroups = array_unique($this->user->groups);
+
         // Read form and validate
         $this->user->groups = array();
         foreach($_POST as $key => $value) {
@@ -223,8 +227,8 @@
         // Mix other groups back in
         if(is_array($this->othergroups))
             $this->user->groups = array_merge($this->user->groups, $this->othergroups);
-        
-        return true;
+
+        return array_same($prevgroups, $this->user->groups);
     }
 
     function process_actions_tab(&$dom, &$formnode) {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]