From: Mikael Nordfeldth Date: Wed, 30 Dec 2015 16:44:24 +0000 (+0100) Subject: Added User->setPassword($password) X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=d7a8ee99afbad082b7b67dd5a068aa8834adbd70;p=quix0rs-gnu-social.git Added User->setPassword($password) --- diff --git a/classes/User.php b/classes/User.php index e33c83e89c..cbe923fc0e 100644 --- a/classes/User.php +++ b/classes/User.php @@ -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); diff --git a/scripts/setpassword.php b/scripts/setpassword.php index 6908ef556a..66964b2a08 100755 --- a/scripts/setpassword.php +++ b/scripts/setpassword.php @@ -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";