Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Commit

Permalink
integrated support for FOSUserBundle
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpapst committed Jul 14, 2018
1 parent 53a15a7 commit 2901667
Show file tree
Hide file tree
Showing 18 changed files with 381 additions and 114 deletions.
14 changes: 13 additions & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,19 @@ private function createRouteAlias(NodeBuilder $rootNodeChildren)
->end()
->scalarNode('adminlte_login')
->defaultValue('login')
->info('name of the login route')
->info('name of the form login route')
->end()
->scalarNode('adminlte_login_check')
->defaultValue('login')
->info('name of the form login_check route')
->end()
->scalarNode('adminlte_registration')
->defaultNull()
->info('name of the user registration form route')
->end()
->scalarNode('adminlte_password_reset')
->defaultNull()
->info('name of the forgot-password form route')
->end()
->scalarNode('adminlte_message')
->defaultValue('message')
Expand Down
1 change: 1 addition & 0 deletions Resources/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ If you cannot find the needed information in this list of topics, please create
* [Form theme](form_theme.md)
* [Twig extensions](twig_widgets.md)
* [Building frontend assets](frontend_assets.md)
* [FOSUserBundle integration](fos_userbundle.md)

Customizing the left menu-sidebar:

Expand Down
7 changes: 5 additions & 2 deletions Resources/docs/configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,13 @@ admin_lte:

Here the theme route name `adminlte_welcome` maps to your route `dashboard` here. Without defining these routes, the theme will not be able to render.

### Available aliases
### Available route aliases

- `adminlte_welcome`: Used for the "homepage" within the theme (defaults to: home)
- `adminlte_login`: The login route (defaults to: login)
- `adminlte_login`: The login route (defaults to: login, must match option: `security.firewalls.xyz.form_login.login_path`)
- `adminlte_login_check`: The login route (defaults to: login_check, must match option: `security.firewalls.xyz.form_login.check_path`)
- `adminlte_registration`: The route for the registration form (defaults to: null). If route is not defined, then the link is not shown.
- `adminlte_password_reset`: The route for the "forgot password" form (defaults to: null). If route is not defined, then the link is not shown.
- `adminlte_message`: Used to generate a link to a specific message, receives parameter `id` (defaults to: message)
- `adminlte_messages`: Used to generate the message list link (defaults to: messages)
- `adminlte_notification`: Used to generate a link to a specific notification, receives parameter `id` (defaults to: notification)
Expand Down
76 changes: 76 additions & 0 deletions Resources/docs/fos_userbundle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# FOSUserBundle integration

This bundle is prepared for a flawless integration with FOSUserBundle, but its not coming out-of-the-box.

First follow the [installation instruction for the FOSUserBundle](http://symfony.com/doc/current/bundles/FOSUserBundle/index.html) and
configure it to your needs.

Then integrate it with the AdminLTEBundle as follows.

## config/packages/admin_lte.yaml

```yaml
admin_lte:
routes:
adminlte_login: fos_user_security_login
adminlte_login_check: fos_user_security_check
adminlte_registration: fos_user_registration_register
adminlte_password_reset: fos_user_resetting_request
```
If you don't want the "password reset" and/or "register account" functionality,
simply remove the configuration keys `adminlte_password_reset` and `adminlte_registration`.

## templates/bundles/FOSUserBundle

Create the directory with the following file structure:

```
// YouAppRoot/templates/bundles/
─ FOSUserBundle
└── views
├── Registration
│ ├── confirmed.html.twig
│ └── register.html.twig
├── Resetting
│ └── request.html.twig
├── Security
│ └── login.html.twig
└── layout.html.twig
```

Add the following files with the following minimal structure,
you might want to overwrite the block `logo_login` to display your app name:

### Registration/register.html.twig

```
{% extends '@AdminLTE/FOSUserBundle/Registration/confirmed.html.twig' %}
```
### Registration/register.html.twig
```
{% extends '@AdminLTE/FOSUserBundle/Registration/register.html.twig' %}
```
### Resetting/request.html.twig
```
{% extends '@AdminLTE/FOSUserBundle/Resetting/request.html.twig' %}
```
### Security/login.html.twig
```
{% extends '@AdminLTE/FOSUserBundle/Security/login.html.twig' %}
```
### layout.html.twig
This example includes an (optional) changed application name:
```
{% extends '@AdminLTE/FOSUserBundle/layout.html.twig' %}
{% block logo_login %}<b>Demo</b><br>Application{% endblock %}
```
54 changes: 41 additions & 13 deletions Resources/docs/layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,12 @@ This bundle ships with two main template files which you need to extend in your
```
{% extends '@AdminLTE/layout/default-layout.html.twig' %}
```
- `login-layout.html.twig` only for the login screen
- `security-layout.html.twig` for the security screens (login, register, forgot password)
```
{% extends '@AdminLTE/layout/login-layout.html.twig' %}
{% extends '@AdminLTE/layout/security-layout.html.twig' %}
```
See [FOSUserBundle](fos_userbundle.md) for an easy integration of the security functionality.

### Login theme and CSRF protection

The theme does not ship with CSRF protection enabled, as this would cause twig errors if `framework.csrf_protection` is disabled.
You can overwrite the block `login_form_end` to enable it (which is highly recommended):

```
{% block login_form_end %}
<input type="hidden" name="_csrf_token" value="{{ csrf_token('authenticate') }}"/>
{% endblock %}
```

## Partials

Expand Down Expand Up @@ -59,8 +50,45 @@ Listed in the order of appearance, these are:
</dl>

## Layout blocks

The blocks are defined in the layout in order of appearance. Some of them do contain some of the major components like the sidebar or navbar.
In order to redefine the block and to keep the default content, don't forget to use `{{parent()}}`
In order to redefine the block and to keep the default content, don't forget to use `{{parent()}}`.

### security-layout.html.twig

<dl>

<dt>login_box
<dd>The main content block, containing the complete body of the

<dt>logo_login
<dd>The welcome title, should hold your application name or logo icon

<dt>login_box_msg
<dd>The box (inside) title, e.g. when you have different forms add a short title/explanation here

<dt>login_box_error
<dd>Security errors will be rendered in this block

<dt>login_form
<dd>

<dt>login_form_start
<dd>

<dt>login_form_end
<dd>

<dt>login_social_auth
<dd>

<dt>login_actions
<dd>

</dl>


### default-layout.html.twig

<dl>

Expand Down
8 changes: 8 additions & 0 deletions Resources/translations/AdminLTEBundle.de.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,18 @@
<source>Password</source>
<target>Passwort</target>
</trans-unit>
<trans-unit id="Show homepage">
<source>Show homepage</source>
<target>Zur Startseite</target>
</trans-unit>
<trans-unit id="Back to login">
<source>Back to login</source>
<target>Zurück zur Anmeldung</target>
</trans-unit>
<trans-unit id="Reset your password">
<source>Reset your password</source>
<target>Passwort zurücksetzen</target>
</trans-unit>
<trans-unit id="I forgot my password">
<source>I forgot my password</source>
<target>Passwort vergessen</target>
Expand Down
8 changes: 8 additions & 0 deletions Resources/translations/AdminLTEBundle.en.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,18 @@
<source>Password</source>
<target>Password</target>
</trans-unit>
<trans-unit id="Show homepage">
<source>Show homepage</source>
<target>Show homepage</target>
</trans-unit>
<trans-unit id="Back to login">
<source>Back to login</source>
<target>Back to login</target>
</trans-unit>
<trans-unit id="Reset your password">
<source>Reset your password</source>
<target>Reset your password</target>
</trans-unit>
<trans-unit id="I forgot my password">
<source>I forgot my password</source>
<target>I forgot my password</target>
Expand Down
26 changes: 25 additions & 1 deletion Resources/translations/AdminLTEBundle.ru.xliff
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file date="2017-01-12T20:00:00Z" source-language="en" target-language="de" datatype="plaintext" original="AdminLTEBundle.en.xliff">
<file date="2017-01-12T20:00:00Z" source-language="en" target-language="ru" datatype="plaintext" original="AdminLTEBundle.en.xliff">
<body>
<trans-unit id="Toggle navigation">
<source>Toggle navigation</source>
<target>Переключить отображение боковой панели</target>
</trans-unit>
<trans-unit id="Remember Me">
<source>Remember Me</source>
<target>Remember Me</target>
</trans-unit>
<trans-unit id="Sign in to start your session">
<source>Sign in to start your session</source>
<target>Логин</target>
Expand All @@ -22,6 +26,26 @@
<source>Password</source>
<target>Пароль</target>
</trans-unit>
<trans-unit id="Show homepage">
<source>Show homepage</source>
<target>Show homepage</target>
</trans-unit>
<trans-unit id="Back to login">
<source>Back to login</source>
<target>Back to login</target>
</trans-unit>
<trans-unit id="Reset your password">
<source>Reset your password</source>
<target>Reset your password</target>
</trans-unit>
<trans-unit id="I forgot my password">
<source>I forgot my password</source>
<target>I forgot my password</target>
</trans-unit>
<trans-unit id="Register a new account">
<source>Register a new account</source>
<target>Register a new account</target>
</trans-unit>
</body>
</file>
</xliff>
16 changes: 16 additions & 0 deletions Resources/views/FOSUserBundle/Registration/confirmed.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{% extends '@AdminLTE/layout/security-layout.html.twig' %}

{% block login_social_auth %}{% endblock %}

{% block login_form %}
{% block fos_user_content %}
<p>{{ 'registration.confirmed'|trans({'%username%': user.username}, 'FOSUserBundle') }}</p>
{% endblock fos_user_content %}
{% endblock %}

{% block login_actions %}
<br>
<a href="{{ path('adminlte_welcome'|route_alias) }}">
{{ 'Show homepage'|trans({}, 'AdminLTEBundle') }}
</a>
{% endblock %}
25 changes: 25 additions & 0 deletions Resources/views/FOSUserBundle/Registration/register.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{% extends '@AdminLTE/layout/security-layout.html.twig' %}

{% block login_social_auth %}{% endblock %}

{% block login_box_msg %}
{{ 'Register a new account'|trans({}, 'AdminLTEBundle') }}
{% endblock %}

{% block login_form %}
{% trans_default_domain 'FOSUserBundle' %}

{{ form_start(form, {'method': 'post', 'action': path('fos_user_registration_register'), 'attr': {'class': 'fos_user_registration_register'}}) }}
{{ form_widget(form) }}
<div class="form-group">
<button type="submit" class="btn btn-primary btn-block btn-flat">{{ 'registration.submit'|trans }}</button>
</div>
{{ form_end(form) }}
{% endblock %}

{% block login_actions %}
<br>
<a href="{{ path('adminlte_login'|route_alias) }}">
{{ 'Back to login'|trans({}, 'AdminLTEBundle') }}
</a>
{% endblock %}
30 changes: 30 additions & 0 deletions Resources/views/FOSUserBundle/Resetting/request.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{% extends '@AdminLTE/layout/security-layout.html.twig' %}

{% block login_social_auth %}{% endblock %}

{% block login_box_msg %}
{{ 'Reset your password'|trans({}, 'AdminLTEBundle') }}
{% endblock %}

{% block login_form %}
{% trans_default_domain 'FOSUserBundle' %}

<form action="{{ path('fos_user_resetting_send_email') }}" method="POST" class="fos_user_resetting_request">
<div class="form-group has-feedback">
<input type="text" id="username" name="username" required="required" class="form-control" placeholder="{{ 'resetting.request.username'|trans }}">
<span class="glyphicon glyphicon-envelope form-control-feedback"></span>
</div>
<div class="row">
<div class="col-xs-12">
<button type="submit" class="btn btn-primary btn-block btn-flat">{{ 'resetting.request.submit'|trans }}</button>
</div>
</div>
</form>
{% endblock %}

{% block login_actions %}
<br>
<a href="{{ path('adminlte_login'|route_alias) }}">
{{ 'Back to login'|trans({}, 'AdminLTEBundle') }}
</a>
{% endblock %}
7 changes: 7 additions & 0 deletions Resources/views/FOSUserBundle/Security/login.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% extends '@AdminLTE/layout/security-layout.html.twig' %}

{% block login_social_auth %}{% endblock %}

{% block login_box_msg %}
{{ 'Sign in to start your session'|trans({}, 'AdminLTEBundle') }}
{% endblock %}
14 changes: 14 additions & 0 deletions Resources/views/FOSUserBundle/layout.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% extends '@AdminLTE/layout/security-layout.html.twig' %}

{% block login_social_auth %}{% endblock %}

{% block login_form %}
{% block fos_user_content %}{% endblock %}
{% endblock %}

{% block login_actions %}
<br>
<a href="{{ path('adminlte_login'|route_alias) }}">
{{ 'Back to login'|trans({}, 'AdminLTEBundle') }}
</a>
{% endblock %}
2 changes: 1 addition & 1 deletion Resources/views/layout/login-layout-avanzu.html.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends '@AdminLTE/layout/login-layout.html.twig' %}
{% extends '@AdminLTE/layout/@AdminLTE/layout/security-layout.html.twig' %}
{#
Do not use this layout if you are starting a fresh project with this bundle.
This file is ONLY meant for migrating from AvanzuAdminTheme to AdminLTE bundle!
Expand Down
Loading

0 comments on commit 2901667

Please sign in to comment.