Commit 41b8c324 authored by Mat's avatar Mat

les vues login et register

parent dd44e115
......@@ -29,10 +29,10 @@ security:
security: false
main:
pattern: ^/
anonymous: false;
anonymous: false
# un anonyme n'aura accès qu'aux pages login et register
form_login:
login_path: login
login_path: /login
check_path: login-check # une route ou un chemin
default_target_path: /chat
# ce sera souvent la page d'accueil
......
......@@ -2,9 +2,9 @@
namespace SocketBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class ChatController extends Controller
{
......@@ -20,4 +20,20 @@ class ChatController extends Controller
return $this->render('@Socket/Chat/message.html.twig');
}
/**
* @Route(name="login", path="/login")
* @param AuthenticationUtils $utils
* @return \Symfony\Component\HttpFoundation\Response
*/
public function loginAction(AuthenticationUtils $utils)
{
$username = $utils->getLastUsername();
$error = $utils->getLastAuthenticationError();
return $this->render('@Socket/Login/login.html.twig', array(
'username' => $username,
'error' => $error
));
}
}
<?php
namespace SocketBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class UserType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('username')
->add('email')
->add('password')
->add('role')
->add('avatar');
}/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'SocketBundle\Entity\User'
));
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'socketbundle_user';
}
}
<!doctype html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>Login Page</title>
</head>
<body>
<form action="{{ path('login_check') }}" method="post">
{% if error != null %}
{{ error.message }}
{% endif %}
<input type="text" name="_username" value="{{ username }}">
<input type="password" name="_password">
<input type="submit">
</form>
</body>
</html>
\ No newline at end of file
{{ form_start(form) }}
{# ASTUCE
comment il faudrait idéalement mettre la classe dans le template plutôt que dans le formtype
{{ form_widget(form.username,
{"attr":{"class": "MaClasse"}})
}}
#}
{{ form_rest(form) }}
<button>Submit</button>
{# ASTUCE
meilleure pratique selon Khun que de mettre un input submit dans le formtype
#}
{{ form_end(form) }}
{# ASTUCE
Utiliser des macros pour formater des bouts de code html
{{ maMacro('Khun') }}
{% macro maMacro(message) %}
<div>
<p>
<li>{{ message }}</li>
</p>
</div>
{% endmacro %}
#}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment