/** * @param string $first * @param string $second * @param User $user * @return array|bool */ public function changePassword(User $user, $first, $second) { if ($first != $second) { return ['password' => 'The entered passwords don\'t match']; } $user->setPlainPassword($first); $this->update($user); return true; }
/** * @ApiDoc( * section="User", * description="Upload photo for manager", * filters={ * {"name"="token", "type"="text"} * } * ) * @Route("/users/{id}/photo") * @Method("DELETE") * @param User $user * @return JsonResponse */ public function deletePhotoAction(User $user) { $uploadDir = $this->container->getParameter('upload_dir'); $absolutePath = $this->container->getParameter('kernel.root_dir') . '/../web/' . $uploadDir . '/' . $user->getPhoto(); $filesystem = $this->get('filesystem'); if (!$filesystem->exists($absolutePath)) { return new JsonResponse(array('status' => 'error', 'errors' => 'File not found')); } $filesystem->remove($absolutePath); $user->setPhoto(null); $this->getDoctrine()->getManager()->flush(); return new JsonResponse(array('status' => 'success')); }