youshido/security-user

Bundle for easy integrations security user

Installs: 2 905

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 4

Forks: 1

Type:symfony-bundle

v0.1.1 2016-11-19 05:30 UTC

This package is not auto-updated.

Last update: 2024-10-26 18:44:06 UTC


README

Install via Composer:

composer require youshido/security-user

Enable in your AppKernel.php:

new new Youshido\SecurityUserBundle\YoushidoSecurityUserBundle(),

Create your User class:

<?php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Youshido\SecurityUserBundle\Entity\SecuredUser;

/**
 * User
 *
 * @ORM\Table(name="user")
 * @ORM\Entity
 */
class User extends SecuredUser
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    //your custom fields

Create User form (if needed):

<?php

namespace AppBundle\Form\Type;

use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Youshido\SecurityUserBundle\Form\Type\SecuredUserType;

class UserType extends SecuredUserType
{

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        parent::buildForm($builder, $options);
    
        $builder
            ->add('plan', 'entity', [
                'class' => 'AppBundle\Entity\Plan'
            ])
            ->add('terms', 'checkbox', [
                'mapped' => false,
            ])
        ;
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'data_class' => 'AppBundle\Entity\User'
        ]);
    }

Insert to your security.yml file:

providers:
    yuser_provider:
        entity:
            class: /* your user class */
            property: email

encoders:
    /* your user class */: md5

firewalls:
    dev:
        pattern: ^/(_(profiler|wdt|error)|css|images|js)/
        security: false
        
    default:
        pattern: ^/
        provider: yuser_provider
        anonymous: ~
        form_login:
            login_path: security.login
            check_path:  security.login_check
            success_handler: security.authentication_handler
            failure_handler: security.authentication_handler
        logout:
            path:   security.logout
            target: /

Configure plugin (required!):

youshido_security_user:
    model: /* your user class */

Available config options:

youshido_security_user:
    model: /* your user class */
    templates:
        login_form: @YoushidoSecurityUser/Security/login.html.twig
        register_form: @YoushidoSecurityUser/Security/register.html.twig
        activation_success: @YoushidoSecurityUser/Security/activation_success.html.twig
        
        recovery_form: @YoushidoSecurityUser/Security/recovery.html.twig
        recovery_success: @YoushidoSecurityUser/Security/recovery_success.html.twig
        
        change_password_success: @YoushidoSecurityUser/Security/change_password_success.html.twig
        change_password_error: @YoushidoSecurityUser/Security/recovery_error.html.twig
        change_password_form: @YoushidoSecurityUser/Security/change_password.html.twig
        
        register_letter: @YoushidoSecurityUser/Letters/register_letter.html.twig
        recovery_letter: @YoushidoSecurityUser/Letters/recovery_letter.html.twig
    redirects:
        register_success: homepage
    mailer:
        from: from@test.com
        subject:
            recovery: Recovery letter
            register: Register letter
    form:
        registration: AppBundle\Form\Type\UserType
    send_mails:
        register: true
        recovery: true