<?php

namespace BodyRep\Controller;
 
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Component\HttpFoundation\RedirectResponse;
 
# Annotations & templates
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

class AuthController extends Controller
{
    /**
     * @Route("/", name="_auth")
     * @Template()
     */
    public function indexAction()
    {
        return new RedirectResponse($this->generateUrl('_login'));
    }

    /**
    /**
     * @Route("/login", name="_login")
     * @Template()
     */
    public function loginAction()
    {
        $request = $this->getRequest();
        $session = $request->getSession();
 
        // get the login error if there is one
        if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
            $error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
        } else {
            $error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
        }
 
        return $this->render('BodyRep:Auth:login.html.twig', array(
            // last username entered by the user
            'last_username' => $session->get(SecurityContext::LAST_USERNAME),
            'error'         => $error,
        ));
    }
    /**
     * @Route("/login/check", name="_login_check")
     * @Template()
     */       
    public function securityCheckAction()
    {
        // The security layer will intercept this request
    }
    /**
     * @Route("/logout", name="_logout")
     * @Template()
     */
    public function logoutAction()
    {
        // The security layer will intercept this request
    }

    public function navbarAction()
    {
        // The security layer will intercept this request
    }
}