/**
  * Saves the user to the database.
  *
  * @param User $user
  *
  * @return User $user
  */
 public function save($user)
 {
     $userData = array('username' => $user->getUsername(), 'password' => $user->getPassword(), 'roles' => $user->getRoles());
     if ($user->getId()) {
         // If a new image was uploaded, make sure the filename gets set.
         $this->db->update('users', $userData, array('id' => $user->getId()));
     } else {
         $userData['password'] = $this->encoder->encodePassword($userData['password'], '');
         $this->db->insert('users', $userData);
         $last = $this->db->lastInsertId();
         return $this->find($last);
     }
 }