$results['id'], 'email' => $results['email'], 'password' => $results['password'], 'name' => $results['name'], 'createdAt' => $results['created_at'], 'updatedAt' => $results['updated_at'] ]); } /** * Get a single instance of the User Entity. * * @param int $id * @return User */ public function get(int $id): User { $query = "SELECT * FROM users WHERE id = ? LIMIT 1"; $results = await($this->db->query($query, [ $id ])); return $this->userFromQueryResults($results->resultRows[0]); } /** * Get a single instance of the User Entity by their Email address. * * @param string $email * @return User */ public function getFromEmail(string $email): User { $query = "SELECT * FROM users WHERE email = ? LIMIT 1"; $results = await($this->db->query($query, [ $email ])); if (!count($results->resultRows)) { throw new EntityNotFoundException("Unable to find User"); } return $this->userFromQueryResults($results->resultRows[0]); } /** * @param User $user * @return bool True if the User is saved. */ public function create(User $user): bool { $query = "INSERT INTO users (email, password, name) VALUES (?, ?, ?)"; $results = await($this->db->query($query, [ $user->getEmail(), $this->userAuth->hash($user->getPassword()), $user->getName(), ])); return (bool) $results->insertId; } public function update(User $user): bool { $query = "UPDATE users SET email = ?, name = ?, password = ? WHERE id = ?"; $results = await($this->db->query($query, [ $user->getEmail(), $user->getName(), $this->userAuth->hash($user->getPassword()), $user->getId() ])); return (bool) $results->affectedRows; } /** * @param string $email * @param string $password * @return bool */ public function verifyPassword(string $email, string $password): bool { try { $user = $this->getFromEmail($email); return $this->authUser->verify($password, $user->getPassword()); } catch (\Exception $e) { return false; } } }