Code Monkey home page Code Monkey logo

sulucommunitybundle's Introduction

SuluCommunityBundle

Installation

composer require sulu/community-bundle

Add to app/AbstractKernel.php

new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Sulu\Bundle\CommunityBundle\SuluCommunityBundle(),

Configuration

Routes

app/config/website/routing.yml:

sulu_community:
    type: portal
    resource: "@SuluCommunityBundle/Resources/config/routing_website.xml"

app/config/admin/routing.yml:

sulu_community_api:
    type: rest
    resource: "@SuluCommunityBundle/Resources/config/routing_api.xml"
    prefix: /admin/api

Webspace

app/Resources/webspaces/<your_webspace>.xml:

    <security>
        <system>Website</system>
    </security>

Community

app/config/config.yml:

sulu_community:
    webspaces:
        example:
            from: %from_email%

Security

app/config/website/security.yml:

security:
    session_fixation_strategy: none

    access_decision_manager:
        strategy: affirmative

    acl:
        connection: default

    encoders:
        Sulu\Bundle\SecurityBundle\Entity\User:
            algorithm: sha512
            iterations: 5000
            encode_as_base64: false

    providers:
        sulu:
            id: sulu_security.user_provider

    access_control:
       - { path: /profile, roles: ROLE_USER }
       - { path: /completion, roles: ROLE_USER }

    firewalls:
        <webspace_key>:
            pattern: ^/
            anonymous: ~
            form_login:
                login_path: sulu_community.login
                check_path: sulu_community.login
            logout:
                path: sulu_community.logout
                target: sulu_community.login
            remember_me:
                secret:   '%secret%'
                lifetime: 604800 # 1 week in seconds
                path:     /

sulu_security:
    checker:
        enabled: true

Setup

app/console sulu:community:init

Additional Features

Embedded Login

Activate ESI to use the login-embed.html.twig.

app/config/config.yml:

framework:
    esi:             { enabled: true }

Insert following in your twig file:

{{ render_esi(controller('SuluCommunityBundle:Login:embed')) }}

Completion Form

You can add an additional completion form to complete the user registration after confirmation.

Create Service

<?php

namespace AppBundle\Validator;

use Sulu\Bundle\CommunityBundle\Validator\User\CompletionInterface;
use Sulu\Bundle\SecurityBundle\Entity\User;

/**
 * Validates the user before he can access pages.
 */
class CompletionValidator implements CompletionInterface
{
    /**
     * {@inheritdoc}
     */
    public function validate(User $user, $webspaceKey)
    {
        $contact = $user->getContact();

        if (!$contact
            || !$contact->getFirstName()
            || !$contact->getLastName()
            || !$user->getUsername()
            || !$user->getEmail()
        ) {
            return false;
        }

        return true;
    }
}

Register Service

<service id="app.completion_validator" class="AppBundle\Validator\CompletionValidator" />

Create Form

<?php

namespace AppBundle\Form\Type\CompletionType;

use Sulu\Bundle\SecurityBundle\Entity\User;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
 * Create the registration form type.
 */
class CompletionType extends AbstractType
{
    /**
     * {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        // Create your form

        $builder->add('submit', SubmitType::class);
    }

    /**
     * {@inheritdoc}
     */
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(
            [
                'data_class' => User::class,
                'validation_groups' => ['completion'],
            ]
        );
    }
}

Configuration

# Community Configuration
sulu_community:
    webspaces:
        <webspace_key>:
            completion:
                form: AppBundle\Form\Type\CompletionType
                service: app.completion_validator

sulucommunitybundle's People

Contributors

alexander-schranz avatar chirimoya avatar wachterjohannes avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.