]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Added User->setPassword($password)
authorMikael Nordfeldth <mmn@hethane.se>
Wed, 30 Dec 2015 16:44:24 +0000 (17:44 +0100)
committerMikael Nordfeldth <mmn@hethane.se>
Wed, 30 Dec 2015 16:44:24 +0000 (17:44 +0100)
classes/User.php
scripts/setpassword.php

index e33c83e89cf0f74f3c07957a4caec50e94f84624..cbe923fc0eddb711a9573e4565c5a904ce61b521 100644 (file)
@@ -1012,6 +1012,16 @@ class User extends Managed_DataObject
         return !empty($this->password);
     }
 
+    public function setPassword($password)
+    {
+        $orig = clone($this);
+        $this->password = common_munge_password($password, $this->getProfile());
+
+        if (!$this->update($orig)) {
+            throw new ServerException("Error updating user '{$nickname}'.");
+        }
+    }
+
     public function delPref($namespace, $topic)
     {
         return $this->getProfile()->delPref($namespace, $topic);
index 6908ef556a7faeb53ec1ae33ea26c7f8747a65cc..66964b2a088d58f252599646832ff17aaeec2bc8 100755 (executable)
@@ -41,21 +41,12 @@ if (mb_strlen($password) < 6) {
     exit(1);
 }
 
-$user = User::getKV('nickname', $nickname);
-
-if (!$user) {
-    print "No such user '$nickname'.\n";
+try {
+    $user = User::getByNickname($nickname);
+    $user->setPassword($password);
+} catch (NoSuchUserException $e) {
+    print $e->getMessage();
     exit(1);
 }
 
-$original = clone($user);
-
-$user->password = common_munge_password($password, $user->getProfile());
-
-if (!$user->update($original)) {
-    print "Error updating user '$nickname'.\n";
-    exit(1);
-} else {
-    print "Password for user '$nickname' updated.\n";
-    exit(0);
-}
+print "Password for user '$nickname' updated.\n";