<?php
namespace HVCSiteBundle\Controller;

use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use FOS\RestBundle\Controller\Annotations\View;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;

class UserRestController extends Controller
{
    public function getUserPasswordAction($username, $password)
    {

        $user_manager = $this->container->get('fos_user.user_manager');
        $factory = $this->container->get('security.encoder_factory');
        $user = $user_manager->loadUserByUsername($username);
        $encoder = $factory->getEncoder($user);
        $validated = $encoder->isPasswordValid($user->getPassword(), $password, $user->getSalt());

        if (!$validated) {
            http_response_code(400);
            echo "Validation Failed";
            exit;
        } else {
            $user = $this->getDoctrine()->getRepository('HVCSiteBundle:Comptes')->find($user);
            return $user;
        }
    }
}