1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| <?php
namespace MedBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use FOS\RestBundle\Controller\Annotations\RouteResource;
use Symfony\Component\HttpFoundation\JsonResponse;
use FOS\RestBundle\View\ViewHandler;
use FOS\RestBundle\View\View;
use MedBundle\Entity\Med;
use Symfony\Component\Security\Core\User\UserInterface;
Class ApiController extends Controller {
public function getAction() {
$em = $this->getDoctrine()->getManager();
$test = $em->getRepository('MedBundle:Med')->findAll();
$viewHandler = $this->get('fos_rest.view_handler');
// Création d'une vue FOSRestBundle
$view = View::create($test);
$view->setFormat('json');
// Gestion de la réponse
return $viewHandler->handle($view);
//return array('test'=>$test);
}
public function loginAction() {
$em = $this->getDoctrine()->getManager();
$request = $this->getRequest();
if ($request->getMethod() == 'POST') {
$username = $request->request->get('username');
$password = $request->request->get('password');
$test = $em->getRepository('MedBundle:Med')->findOneBy(array('username' => $username));
if (!($test)) { var_dump('error'); } else{
$salt= $test->getSalt();
$pass = crypt($password,$salt);
if ( $pass === $test->getPassword() ) {
var_dump('success'); }
}
$x = $this->get('lexik_jwt_authentication.jwt_manager')->create($test);
var_dump($x);
}
return $this->render('default/login.html.twig');
}
public function logoutAction() {
}
} |
Partager