diff --git a/module/VuFind/src/VuFind/Auth/Database.php b/module/VuFind/src/VuFind/Auth/Database.php index 8d930d16eba001d390d53004f4ba773ddee21a47..f350266aa995b411b6be4d30d6c9826b623dc6a6 100644 --- a/module/VuFind/src/VuFind/Auth/Database.php +++ b/module/VuFind/src/VuFind/Auth/Database.php @@ -141,23 +141,18 @@ class Database extends AbstractBase } // If we got this far, we're ready to create the account: - $data = [ - 'username' => $params['username'], - 'firstname' => $params['firstname'], - 'lastname' => $params['lastname'], - 'email' => $params['email'], - 'created' => date('Y-m-d H:i:s') - ]; - + $user = $table->createRowForUsername($params['username']); + $user->firstname = $params['firstname']; + $user->lastname = $params['lastname']; + $user->email = $params['email']; if ($this->passwordHashingEnabled()) { $bcrypt = new Bcrypt(); - $data['pass_hash'] = $bcrypt->create($params['password']); + $user->pass_hash = $bcrypt->create($params['password']); } else { - $data['password'] = $params['password']; + $user->password = $params['password']; } - // Create the row and send it back to the caller: - $table->insert($data); - return $table->getByUsername($params['username'], false); + $user->save(); + return $user; } /** diff --git a/module/VuFind/src/VuFind/Db/Table/User.php b/module/VuFind/src/VuFind/Db/Table/User.php index 08c893d533c27a48d40b4c77dbac9abad82cdb98..9444c836e079978eefc240fd867b2d4df6cde7f6 100644 --- a/module/VuFind/src/VuFind/Db/Table/User.php +++ b/module/VuFind/src/VuFind/Db/Table/User.php @@ -57,8 +57,23 @@ class User extends Gateway } /** - * Retrieve a user object from the database based on username; create a new - * row if no existing match is found. + * Create a row for the specified username. + * + * @param string $username Username to use for retrieval. + * + * @return UserRow + */ + public function createRowForUsername($username) + { + $row = $this->createRow(); + $row->username = $username; + $row->created = date('Y-m-d H:i:s'); + return $row; + } + + /** + * Retrieve a user object from the database based on username; when requested, + * create a new row if no existing match is found. * * @param string $username Username to use for retrieval. * @param bool $create Should we create users that don't already exist? @@ -68,12 +83,8 @@ class User extends Gateway public function getByUsername($username, $create = true) { $row = $this->select(['username' => $username])->current(); - if ($create && empty($row)) { - $row = $this->createRow(); - $row->username = $username; - $row->created = date('Y-m-d H:i:s'); - } - return $row; + return ($create && empty($row)) + ? $this->createRowForUsername($username) : $row; } /**