<?php
/**
 * Created by PhpStorm.
 * User: danielknudsen
 * Date: 05.04.18
 * Time: 13:09
 */
namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Config\Definition\Exception\Exception;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Annotation\Route;

class PublicController extends AbstractController
{
    /**
     * @Route("/", name="index")
     */
    public function showIndexAction()
    {
        $data = array(
            // you might translate this message
            'message' => 'PHP api'
        );
        return new JsonResponse($data);
    }

    /**
     * Login
     * @Route("/login", name="login")
     */
    public function loginAction()
    {
        $error = $this->get('security.authentication_utils')->getLastAuthenticationError();

        $data = [
            'error' => $error
        ];

        return new JsonResponse($data);
    }

    /**
     * @Route("/logout", name="security_logout")
     */
    public function logoutAction()
    {
        throw new Exception('this should not be reached');
    }

}