mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-09-13 21:57:16 +02:00
Implemented FOS bundle
This commit is contained in:
@@ -1,61 +0,0 @@
|
||||
<?php
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Form\UserType;
|
||||
use App\Entity\User;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
|
||||
class RegistrationController extends AbstractController
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var User
|
||||
*/
|
||||
private $user;
|
||||
|
||||
/**
|
||||
*
|
||||
* @Route("/register", name="user_register")
|
||||
*/
|
||||
public function register(Request $request, UserPasswordEncoderInterface $passwordEncoder,TranslatorInterface $translator): Response
|
||||
{
|
||||
$this->user = new User();
|
||||
$form = $this->createForm(UserType::class, $this->user);
|
||||
$form->handleRequest($request);
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->encodePassword($passwordEncoder);
|
||||
$this->saveUser($translator);
|
||||
return $this->redirectToRoute('login');
|
||||
}
|
||||
return $this->render("user/register.html.twig", array(
|
||||
'form' => $form->createView()
|
||||
));
|
||||
}
|
||||
|
||||
public function encodePassword(UserPasswordEncoderInterface $passwordEncoder): void
|
||||
{
|
||||
$password = $passwordEncoder->encodePassword($this->user, $this->user->getPlainPassword());
|
||||
$this->user->setPassword($password);
|
||||
}
|
||||
|
||||
private function saveUser(TranslatorInterface $translator): void
|
||||
{
|
||||
$entityManager = $this->getDoctrine()->getManager();
|
||||
$entityManager->persist($this->user);
|
||||
try {
|
||||
$entityManager->flush();
|
||||
$this->addFlash('success', $translator->trans('User "%username%" created!',['%username%'=>$this->user->getUsername()]));
|
||||
} catch (\Exception $exception) {
|
||||
$this->addFlash('danger', $translator->trans('User "%username%" could not be created!',['%username%'=>$this->user->getUsername()]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,37 +0,0 @@
|
||||
<?php
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*
|
||||
*/
|
||||
class SecurityController extends AbstractController
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @Route("/login", name="login")
|
||||
*/
|
||||
public function login(AuthenticationUtils $authenticationUtils,TranslatorInterface $translator): Response
|
||||
{
|
||||
$error = $authenticationUtils->getLastAuthenticationError();
|
||||
if ($error) {
|
||||
$this->addFlash('danger', $translator->trans($error->getMessageKey(),$error->getMessageData(),'security'));
|
||||
}else{
|
||||
$lastUsername = $authenticationUtils->getLastUsername();
|
||||
if($lastUsername){
|
||||
$this->addFlash('success', $translator->trans('User %user% loged in.',['%user%'=>$lastUsername]));
|
||||
}
|
||||
}
|
||||
return $this->render("user/login.html.twig",[
|
||||
'last_username'=>$authenticationUtils->getLastUsername(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,8 @@
|
||||
<?php
|
||||
namespace App\Entity\Attribut;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author kevinfrantz
|
||||
@@ -8,7 +10,7 @@ namespace App\Entity\Attribut;
|
||||
*/
|
||||
trait IdAttribut {
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\Id()
|
||||
* @ORM\GeneratedValue
|
||||
* @ORM\Column(type="integer")(strategy="AUTO")
|
||||
*/
|
||||
|
@@ -2,9 +2,8 @@
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use App\Entity\Attribut\UsernameAttribut;
|
||||
use App\Entity\Attribut\PasswordAttribut;
|
||||
use App\Entity\Attribut\PlainPasswordAttribute;
|
||||
use FOS\UserBundle\Model\User as BaseUser;
|
||||
use App\Entity\Attribut\NodeAttribut;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -12,51 +11,39 @@ use App\Entity\Attribut\PlainPasswordAttribute;
|
||||
* @ORM\Table(name="source_user")
|
||||
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
|
||||
*/
|
||||
class User extends AbstractSource implements UserInterface
|
||||
class User extends BaseUser implements SourceInterface
|
||||
{
|
||||
use UsernameAttribut,PasswordAttribut,PlainPasswordAttribute;
|
||||
use NodeAttribut;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="is_active", type="boolean")
|
||||
*/
|
||||
private $isActive;
|
||||
|
||||
/**
|
||||
* @ORM\Id()
|
||||
* @ORM\GeneratedValue
|
||||
* @ORM\Column(type="integer")(strategy="AUTO")
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
public function setId(int $id): void
|
||||
{
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct ();
|
||||
/**
|
||||
* @todo Remove this later
|
||||
* @var \App\Entity\User $isActive
|
||||
*/
|
||||
$this->isActive = true;
|
||||
}
|
||||
|
||||
public function getSalt()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getRoles()
|
||||
{
|
||||
return array('ROLE_USER');
|
||||
}
|
||||
|
||||
public function eraseCredentials()
|
||||
{
|
||||
}
|
||||
|
||||
/** @see \Serializable::serialize() */
|
||||
public function serialize()
|
||||
{
|
||||
return serialize(array(
|
||||
$this->id,
|
||||
$this->username,
|
||||
$this->password,
|
||||
));
|
||||
}
|
||||
|
||||
/** @see \Serializable::unserialize() */
|
||||
public function unserialize($serialized)
|
||||
{
|
||||
list (
|
||||
$this->id,
|
||||
$this->username,
|
||||
$this->password,
|
||||
) = unserialize($serialized, array('allowed_classes' => false));
|
||||
}
|
||||
}
|
||||
|
@@ -1,14 +0,0 @@
|
||||
<?php
|
||||
namespace App\Entity;
|
||||
|
||||
use Symfony\Component\Security\Core\User\UserInterface as SymfonyUserInterface;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*
|
||||
*/
|
||||
interface UserInterface extends SymfonyUserInterface, \Serializable
|
||||
{
|
||||
}
|
||||
|
@@ -0,0 +1,5 @@
|
||||
{% extends "@FOSUser/layout.html.twig" %}
|
||||
|
||||
{% block fos_user_content %}
|
||||
{% include "@FOSUser/ChangePassword/change_password_content.html.twig" %}
|
||||
{% endblock fos_user_content %}
|
@@ -0,0 +1,8 @@
|
||||
{% trans_default_domain 'FOSUserBundle' %}
|
||||
|
||||
{{ form_start(form, { 'action': path('fos_user_change_password'), 'attr': { 'class': 'fos_user_change_password' } }) }}
|
||||
{{ form_widget(form) }}
|
||||
<div>
|
||||
<input type="submit" value="{{ 'change_password.submit'|trans }}" />
|
||||
</div>
|
||||
{{ form_end(form) }}
|
@@ -0,0 +1,5 @@
|
||||
{% extends "@FOSUser/layout.html.twig" %}
|
||||
|
||||
{% block fos_user_content %}
|
||||
{% include "@FOSUser/Group/edit_content.html.twig" %}
|
||||
{% endblock fos_user_content %}
|
@@ -0,0 +1,8 @@
|
||||
{% trans_default_domain 'FOSUserBundle' %}
|
||||
|
||||
{{ form_start(form, { 'action': path('fos_user_group_edit', {'groupName': group_name}), 'attr': { 'class': 'fos_user_group_edit' } }) }}
|
||||
{{ form_widget(form) }}
|
||||
<div>
|
||||
<input type="submit" value="{{ 'group.edit.submit'|trans }}" />
|
||||
</div>
|
||||
{{ form_end(form) }}
|
@@ -0,0 +1,5 @@
|
||||
{% extends "@FOSUser/layout.html.twig" %}
|
||||
|
||||
{% block fos_user_content %}
|
||||
{% include "@FOSUser/Group/list_content.html.twig" %}
|
||||
{% endblock fos_user_content %}
|
@@ -0,0 +1,7 @@
|
||||
<div class="fos_user_group_list">
|
||||
<ul>
|
||||
{% for group in groups %}
|
||||
<li><a href="{{ path('fos_user_group_show', {'groupName': group.getName()} ) }}">{{ group.getName() }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
@@ -0,0 +1,5 @@
|
||||
{% extends "@FOSUser/layout.html.twig" %}
|
||||
|
||||
{% block fos_user_content %}
|
||||
{% include "@FOSUser/Group/new_content.html.twig" %}
|
||||
{% endblock fos_user_content %}
|
@@ -0,0 +1,8 @@
|
||||
{% trans_default_domain 'FOSUserBundle' %}
|
||||
|
||||
{{ form_start(form, { 'action': path('fos_user_group_new'), 'attr': { 'class': 'fos_user_group_new' } }) }}
|
||||
{{ form_widget(form) }}
|
||||
<div>
|
||||
<input type="submit" value="{{ 'group.new.submit'|trans }}" />
|
||||
</div>
|
||||
{{ form_end(form) }}
|
@@ -0,0 +1,5 @@
|
||||
{% extends "@FOSUser/layout.html.twig" %}
|
||||
|
||||
{% block fos_user_content %}
|
||||
{% include "@FOSUser/Group/show_content.html.twig" %}
|
||||
{% endblock fos_user_content %}
|
@@ -0,0 +1,5 @@
|
||||
{% trans_default_domain 'FOSUserBundle' %}
|
||||
|
||||
<div class="fos_user_group_show">
|
||||
<p>{{ 'group.show.name'|trans }}: {{ group.getName() }}</p>
|
||||
</div>
|
@@ -0,0 +1,5 @@
|
||||
{% extends "@FOSUser/layout.html.twig" %}
|
||||
|
||||
{% block fos_user_content %}
|
||||
{% include "@FOSUser/Profile/edit_content.html.twig" %}
|
||||
{% endblock fos_user_content %}
|
@@ -0,0 +1,8 @@
|
||||
{% trans_default_domain 'FOSUserBundle' %}
|
||||
|
||||
{{ form_start(form, { 'action': path('fos_user_profile_edit'), 'attr': { 'class': 'fos_user_profile_edit' } }) }}
|
||||
{{ form_widget(form) }}
|
||||
<div>
|
||||
<input type="submit" value="{{ 'profile.edit.submit'|trans }}" />
|
||||
</div>
|
||||
{{ form_end(form) }}
|
@@ -0,0 +1,5 @@
|
||||
{% extends "@FOSUser/layout.html.twig" %}
|
||||
|
||||
{% block fos_user_content %}
|
||||
{% include "@FOSUser/Profile/show_content.html.twig" %}
|
||||
{% endblock fos_user_content %}
|
@@ -0,0 +1,6 @@
|
||||
{% trans_default_domain 'FOSUserBundle' %}
|
||||
|
||||
<div class="fos_user_user_show">
|
||||
<p>{{ 'profile.show.username'|trans }}: {{ user.username }}</p>
|
||||
<p>{{ 'profile.show.email'|trans }}: {{ user.email }}</p>
|
||||
</div>
|
@@ -0,0 +1,7 @@
|
||||
{% extends "@FOSUser/layout.html.twig" %}
|
||||
|
||||
{% trans_default_domain 'FOSUserBundle' %}
|
||||
|
||||
{% block fos_user_content %}
|
||||
<p>{{ 'registration.check_email'|trans({'%email%': user.email}) }}</p>
|
||||
{% endblock fos_user_content %}
|
@@ -0,0 +1,10 @@
|
||||
{% extends "@FOSUser/layout.html.twig" %}
|
||||
|
||||
{% trans_default_domain 'FOSUserBundle' %}
|
||||
|
||||
{% block fos_user_content %}
|
||||
<p>{{ 'registration.confirmed'|trans({'%username%': user.username}) }}</p>
|
||||
{% if targetUrl %}
|
||||
<p><a href="{{ targetUrl }}">{{ 'registration.back'|trans }}</a></p>
|
||||
{% endif %}
|
||||
{% endblock fos_user_content %}
|
@@ -0,0 +1,13 @@
|
||||
{% trans_default_domain 'FOSUserBundle' %}
|
||||
{% block subject %}
|
||||
{%- autoescape false -%}
|
||||
{{ 'registration.email.subject'|trans({'%username%': user.username, '%confirmationUrl%': confirmationUrl}) }}
|
||||
{%- endautoescape -%}
|
||||
{% endblock %}
|
||||
|
||||
{% block body_text %}
|
||||
{% autoescape false %}
|
||||
{{ 'registration.email.message'|trans({'%username%': user.username, '%confirmationUrl%': confirmationUrl}) }}
|
||||
{% endautoescape %}
|
||||
{% endblock %}
|
||||
{% block body_html %}{% endblock %}
|
@@ -0,0 +1,5 @@
|
||||
{% extends "@FOSUser/layout.html.twig" %}
|
||||
|
||||
{% block fos_user_content %}
|
||||
{% include "@FOSUser/Registration/register_content.html.twig" %}
|
||||
{% endblock fos_user_content %}
|
@@ -0,0 +1,8 @@
|
||||
{% 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>
|
||||
<input type="submit" value="{{ 'registration.submit'|trans }}" />
|
||||
</div>
|
||||
{{ form_end(form) }}
|
@@ -0,0 +1,9 @@
|
||||
{% extends "@FOSUser/layout.html.twig" %}
|
||||
|
||||
{% trans_default_domain 'FOSUserBundle' %}
|
||||
|
||||
{% block fos_user_content %}
|
||||
<p>
|
||||
{{ 'resetting.check_email'|trans({'%tokenLifetime%': tokenLifetime})|nl2br }}
|
||||
</p>
|
||||
{% endblock %}
|
@@ -0,0 +1,13 @@
|
||||
{% trans_default_domain 'FOSUserBundle' %}
|
||||
{% block subject %}
|
||||
{%- autoescape false -%}
|
||||
{{ 'resetting.email.subject'|trans({'%username%': user.username}) }}
|
||||
{%- endautoescape -%}
|
||||
{% endblock %}
|
||||
|
||||
{% block body_text %}
|
||||
{% autoescape false %}
|
||||
{{ 'resetting.email.message'|trans({'%username%': user.username, '%confirmationUrl%': confirmationUrl}) }}
|
||||
{% endautoescape %}
|
||||
{% endblock %}
|
||||
{% block body_html %}{% endblock %}
|
@@ -0,0 +1,5 @@
|
||||
{% extends "@FOSUser/layout.html.twig" %}
|
||||
|
||||
{% block fos_user_content %}
|
||||
{% include "@FOSUser/Resetting/request_content.html.twig" %}
|
||||
{% endblock fos_user_content %}
|
@@ -0,0 +1,11 @@
|
||||
{% trans_default_domain 'FOSUserBundle' %}
|
||||
|
||||
<form action="{{ path('fos_user_resetting_send_email') }}" method="POST" class="fos_user_resetting_request">
|
||||
<div>
|
||||
<label for="username">{{ 'resetting.request.username'|trans }}</label>
|
||||
<input type="text" id="username" name="username" required="required" />
|
||||
</div>
|
||||
<div>
|
||||
<input type="submit" value="{{ 'resetting.request.submit'|trans }}" />
|
||||
</div>
|
||||
</form>
|
@@ -0,0 +1,5 @@
|
||||
{% extends "@FOSUser/layout.html.twig" %}
|
||||
|
||||
{% block fos_user_content %}
|
||||
{% include "@FOSUser/Resetting/reset_content.html.twig" %}
|
||||
{% endblock fos_user_content %}
|
@@ -0,0 +1,8 @@
|
||||
{% trans_default_domain 'FOSUserBundle' %}
|
||||
|
||||
{{ form_start(form, { 'action': path('fos_user_resetting_reset', {'token': token}), 'attr': { 'class': 'fos_user_resetting_reset' } }) }}
|
||||
{{ form_widget(form) }}
|
||||
<div>
|
||||
<input type="submit" value="{{ 'resetting.reset.submit'|trans }}" />
|
||||
</div>
|
||||
{{ form_end(form) }}
|
@@ -0,0 +1,10 @@
|
||||
{% extends "@FOSUser/layout.html.twig" %}
|
||||
{% block title %}
|
||||
{% trans %}login{% endtrans %}
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
<h1>
|
||||
{% trans %}login{% endtrans %}
|
||||
</h1>
|
||||
{{ include('@FOSUser/Security/login_content.html.twig') }}
|
||||
{% endblock %}
|
@@ -0,0 +1,27 @@
|
||||
{% trans_default_domain 'FOSUserBundle' %}
|
||||
{% if error %}
|
||||
{% include "frames/structure/message/message.html.twig" with {'message':error.messageKey|trans(error.messageData, 'security'),'label':'danger'} %}
|
||||
{% endif %}
|
||||
|
||||
<form action="{{ path("fos_user_security_check") }}" method="post">
|
||||
{% if csrf_token %}
|
||||
<input type="hidden" name="_csrf_token" value="{{ csrf_token }}" />
|
||||
{% endif %}
|
||||
<div class="form-group">
|
||||
<label for="username">{{ 'security.login.username'|trans }}</label> <input
|
||||
type="text" id="username" name="_username"
|
||||
value="{{ last_username }}" required="required" class="form-control"
|
||||
autocomplete="username" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="password">{{ 'security.login.password'|trans }}</label> <input
|
||||
type="password" id="password" name="_password" class="form-control" required="required"
|
||||
autocomplete="current-password" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input type="checkbox" id="remember_me" name="_remember_me" value="on" />
|
||||
<label for="remember_me">{{ 'security.login.remember_me'|trans }}</label>
|
||||
</div>
|
||||
<input type="submit" id="_submit" name="_submit"
|
||||
value="{{ 'security.login.submit'|trans }}" class="btn btn-primary"/>
|
||||
</form>
|
@@ -0,0 +1,28 @@
|
||||
|
||||
{% extends "frames/default.html.twig" %}
|
||||
{% block content %}
|
||||
<div>
|
||||
{% if is_granted("IS_AUTHENTICATED_REMEMBERED") %}
|
||||
{{ 'layout.logged_in_as'|trans({'%username%': app.user.username}, 'FOSUserBundle') }}
|
||||
| <a href="{{ path('fos_user_security_logout') }}"> {{ 'layout.logout'|trans({}, 'FOSUserBundle') }}
|
||||
</a>
|
||||
{% else %}
|
||||
<a href="{{ path('fos_user_security_login') }}">{{ 'layout.login'|trans({}, 'FOSUserBundle') }}</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% if app.request.hasPreviousSession %}
|
||||
{% for type, messages in app.session.flashbag.all() %}
|
||||
{% for message in messages %}
|
||||
<div class="flash-{{ type }}">
|
||||
{{ message }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
<div>
|
||||
{% block fos_user_content %}
|
||||
{% endblock fos_user_content %}
|
||||
</div>
|
||||
{% endblock content %}
|
@@ -63,7 +63,7 @@ class UserMenuSubscriber implements EventSubscriberInterface
|
||||
]);
|
||||
} else {
|
||||
$dropdown->addChild('login', [
|
||||
'route' => 'login',
|
||||
'route' => 'fos_user_security_login',
|
||||
'attributes' => [
|
||||
'divider_append' => true,
|
||||
'icon' => 'fas fa-sign-in-alt'
|
||||
@@ -71,7 +71,7 @@ class UserMenuSubscriber implements EventSubscriberInterface
|
||||
]);
|
||||
}
|
||||
$dropdown->addChild('register', [
|
||||
'route' => 'user_register',
|
||||
'route' => 'fos_user_registration_register',
|
||||
'attributes' => [
|
||||
'icon' => 'fas fa-file-signature'
|
||||
]
|
||||
|
Reference in New Issue
Block a user