]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/passwordsettings.php
Add ChangePassword event
[quix0rs-gnu-social.git] / actions / passwordsettings.php
index cd4beac3f2120a9c83a81f4ddc8a4e98c8573777..87eb45a7d054f33bedd9a828683a93d36ee1608d 100644 (file)
@@ -164,23 +164,32 @@ class PasswordsettingsAction extends AccountSettingsAction
                 $this->showForm(_('Incorrect old password'));
                 return;
             }
+        }else{
+            $oldpassword = null;
         }
 
-        $original = clone($user);
+        $errormsg = false;
+        if(! Event::handle('ChangePassword', array($user->nickname, $oldpassword, $newpassword, &$errormsg))){
+            //no handler changed the password, so change the password internally
+            $original = clone($user);
 
-        $user->password = common_munge_password($newpassword, $user->id);
+            $user->password = common_munge_password($newpassword, $user->id);
 
-        $val = $user->validate();
-        if ($val !== true) {
-            $this->showForm(_('Error saving user; invalid.'));
-            return;
-        }
+            $val = $user->validate();
+            if ($val !== true) {
+                $this->showForm(_('Error saving user; invalid.'));
+                return;
+            }
 
-        if (!$user->update($original)) {
-            $this->serverError(_('Can\'t save new password.'));
-            return;
+            if (!$user->update($original)) {
+                $this->serverError(_('Can\'t save new password.'));
+                return;
+            }
         }
 
-        $this->showForm(_('Password saved.'), true);
+        if($errormsg === false)
+            $this->showForm(_('Password saved.'), true);
+        else
+            $this->showForm($errormsg);
     }
 }