Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //entidad usuario
- <?php
- namespace Actas\MainBundle\Entity;
- use Doctrine\ORM\Mapping as ORM;
- use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
- use Symfony\Component\Validator\Constraints as Assert;
- use Symfony\Component\Security\Core\User\UserInterface;
- /**
- * Usuarios
- *
- * @ORM\Table(name="usuarios")
- * @ORM\Entity(repositoryClass="Actas\MainBundle\Repository\UsuariosRepository")
- * @UniqueEntity(fields="usuario", message="Ese Usuario ya existe")
- */
- class Usuarios implements UserInterface, \Serializable
- {
- /**
- * @var int
- *
- * @ORM\Column(name="id", type="integer")
- * @ORM\Id
- * @ORM\GeneratedValue(strategy="AUTO")
- */
- private $id;
- /**
- * @var string
- *
- * @ORM\Column(name="usuario", type="string", length=100, unique=true)
- * @Assert\NotBlank(message="no deje en blanco")
- */
- private $usuario;
- /**
- * @var string
- *
- * @ORM\Column(name="contrasea", type="string", length=64)
- */
- private $contrasea;
- /**
- * @var bool
- *
- * @ORM\Column(name="is_activo", type="boolean")
- *
- */
- private $is_activo = 0;
- /**
- * Get id
- *
- * @return integer
- */
- public function getId()
- {
- return $this->id;
- }
- /**
- * Set usuario
- *
- * @param string $usuario
- * @return Usuarios
- */
- public function setUsuario($usuario)
- {
- $this->usuario = $usuario;
- return $this;
- }
- /**
- * Get usuario
- *
- * @return string
- */
- public function getUsuario()
- {
- return $this->usuario;
- }
- /**
- * Set contrasea
- *
- * @param string $contrasea
- * @return Usuarios
- */
- public function setContrasea($contrasea)
- {
- $this->contrasea = $contrasea;
- return $this;
- }
- /**
- * Get contrasea
- *
- * @return string
- */
- public function getContrasea()
- {
- return $this->contrasea;
- }
- /**
- * Get is_activo
- *
- * @return boolean
- */
- public function getIsactivo()
- {
- return (boolean)$this->is_activo;
- }
- /**
- * Set is_activo
- *
- * @param boolean is_activo
- * @return Usuarios
- */
- public function setIsactivo($is_activo)
- {
- (boolean)$this->is_activo = $is_activo;
- return $this;
- }
- public function eraseCredentials() {
- }
- public function getPassword() {
- }
- public function getRoles() {
- return array('ROLE_USER');
- }
- public function getSalt() {
- }
- public function getUsername() {
- }
- public function serialize() {
- return serialize(array(
- $this->id,
- $this->usuario,
- $this->contrasea,
- $this->is_activo
- ));
- }
- public function unserialize($serialized) {
- list(
- $this->id,
- $this->usuario,
- $this->contrasea,
- $this->is_activo
- )= unserialize($serialized);
- }
- }
- //login_controller
- <?php
- namespace Actas\MainBundle\Controller;
- use Symfony\Bundle\FrameworkBundle\Controller\Controller;
- use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
- use Symfony\Component\HttpFoundation\Request;
- class LoginController extends Controller
- {
- /**
- * @Route("/login", name="login")
- */
- public function loginAction(Request $request)
- {
- $authenticationUtils = $this->get('security.authentication_utils');
- // get the login error if there is one
- $error = $authenticationUtils->getLastAuthenticationError();
- // last username entered by the user
- $lastUsername = $authenticationUtils->getLastUsername();
- return $this->render(
- 'ActasMainBundle:login:login.html.twig',
- array(
- // last username entered by the user
- 'last_username' => $lastUsername,
- 'error' => $error,
- )
- );
- }
- /**
- * @Route("/logout", name="logout")
- */
- public function logoutAction()
- {
- }
- }
- //security.yml
- # To get started with security, check out the documentation:
- # http://symfony.com/doc/current/book/security.html
- security:
- encoders:
- Actas\MainBundle\Entity\Usuarios:
- algorithm: bcrypt
- providers:
- mysql:
- entity:
- class: ActasMainBundle\Entity\Usuarios
- property: usuario
- # http://symfony.com/doc/current/book/security.html#where-do-users-come-from-user-providers
- firewalls:
- # disables authentication for assets and the profiler, adapt it according to your needs
- dev:
- pattern: ^/(_(profiler|wdt)|css|images|js)/
- security: false
- main:
- anonymous: ~
- form_login:
- login_path: login
- check_path: login
- access_control:
- - {path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY}
- - {path: ^/usuarios, roles: ROLE_USER}
- //login twig
- {% block inputs %}
- {% if error %}
- <div>{{ error.messageKey|trans(error.messageData, 'security') }}</div>
- {% endif %}
- <form action="{{ path('login') }}" method="post">
- <label for="username">Username:</label>
- <input type="text" id="username" name="_username" value="{{ last_username }}" />
- <label for="password">Password:</label>
- <input type="password" id="password" name="_password" />
- {#
- If you want to control the URL the user
- is redirected to on success (more details below)
- <input type="hidden" name="_target_path" value="/account" />
- #}
- <button type="submit">login</button>
- </form>
- {% endblock %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement