avanzu / profile-bundle

Symfony ProfileBundle

安装次数: 18

依赖者: 0

建议者: 0

安全: 0

星标: 2

关注者: 0

分叉: 1

开放问题: 0

类型:symfony-bundle

dev-master 2013-08-02 05:19 UTC

This package is not auto-updated.

Last update: 2024-09-14 12:02:12 UTC


README

创建用户实体

use Doctrine\ORM\Mapping as ORM;
use Avanzu\ProfileBundle\Entity\User as BaseUser;

/**
 * @ORM\Entity()
 */
class User extends BaseUser {}

创建用户类型

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class UserType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('username')
            ->add('email')
            ->add('plainPassword', 'repeated',
                  array(
                'first_name'  => 'password',
                'second_name' => 'confirm',
                'type'        => 'password',
            ));
        ;
    }

    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'Pma\CommonBundle\Entity\User'
        ));
    }

    public function getName()
    {
        return 'avanzu_profile_user';
    }
}

配置

#config.yml
avanzu_profile: 
    user_class: Pma\CommonBundle\Entity\User
    form:
      class:
        user: Pma\CommonBundle\Form\Type\UserType
# routing.yml 
avanzu_profile_profile: 
    resource: "@AvanzuProfileBundle/Controller/ProfileController.php"
    type: annotation
    prefix: /profile

avanzu_profile_security: 
  resource: "@AvanzuProfileBundle/Controller/SecurityController.php"
  type: annotation
  prefix: /

avanzu_profile_registration: 
  resource: "@AvanzuProfileBundle/Controller/RegistrationController.php"
  type: annotation
  prefix: /

avanzu_profile_resetting: 
  resource: "@AvanzuProfileBundle/Controller/ResettingController.php"
  type: annotation
  prefix: /
# security.yml

security:
    encoders:
        Avanzu\ProfileBundle\Entity\User: sha512

providers:
    avanzu_profile_bundle:
        entity: { class: __your bundle and userclass__, property: username }

firewalls:
    main:
        pattern: ^/
        provider: avanzu_profile_bundle
        form_login: 
          login_path: /login
          check_path: /login-check
        anonymous: ~
        logout: ~


access_control:
    - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY}
    - { path: ^/profile, roles: ROLE_USER }
    - { path: ^/, roles: IS_AUTHENTICATED_ANONYMOUSLY }