Skip to content

Commit

Permalink
Mailer (#82)
Browse files Browse the repository at this point in the history
* symfony mailer replaces switfmailer
  • Loading branch information
Yosimitso authored Feb 14, 2022
1 parent fb621eb commit 14453f4
Show file tree
Hide file tree
Showing 41 changed files with 257 additions and 6,898 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ npm-debug.log
php_errors.log
composer.lock
var
Tests/Scenario/error.html
11 changes: 0 additions & 11 deletions COMMON-ERRORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ Common errors :

*The service "yosimitso_workingforum_base_controller" has a dependency on a non-existent service "templating"*

Sf 3 : add to app/config/config.yml :

Sf 4 : add to config/framework.yaml :

You have to define your templating engine to Symfony, ex for Twig :
Expand All @@ -12,18 +10,9 @@ framework:
templating:
engines: ['twig']
````
--------------------------

*The service "yosimitso_workingforum_util_subscription" has a dependency on a non-existent parameter "swiftmailer.sender_address". Did you mean this: "swiftmailer.single_address"?*

Sf 3 : add to app/config/config.yml :

Sf 4 : add to config/swiftmailer.yaml :
````yaml
swiftmailer:
sender_address: '[email protected]'
````
--------------------------------
*SQLSTATE[42000]: Syntax error or access violation : 1071 Specified key was too long; max key length is 767 bytes*

This error occurs on old versions of MySQL (< 5.6)
Expand Down
3 changes: 2 additions & 1 deletion CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ yosimitso_working_forum_bundle:
| | theme_color | No | String not empty | green | Theme color |
| | lock_thread_older_than | No | Integer (0 = disabled) | 365 | Days between the last thread's post and the autolocking of the thread, 0 means disabled |
| | post_flood_sec | No | Integer (0 = disabled) | 30 | seconds minimum between each post for an user |
| | mailer_sender_address | No | String | (empty) | "From" email address used by the bundle
|vote:|
| |threshold_useful_post | No | Integer > 0 | 5 | Number of votes needed for a post to be considered as useful |
|file_upload:|
Expand All @@ -22,4 +23,4 @@ yosimitso_working_forum_bundle:
| | accepted_format | No | Array | [image/jpg, image/jpeg, image/png, image/gif, image/tiff, application/pdf] | Accepted file format |
| | preview_file | No | Boolean | true | For images only, display or not the thumbnail |
|thread_subscription:|
| | enable | **Yes** | Boolean | false | Allow or not thread's subscription, remember to check your swiftmailer configuration
| | enable | **Yes** | Boolean | false | Allow or not thread's subscription, remember to check your mailer configuration
15 changes: 6 additions & 9 deletions Controller/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,13 @@
use Doctrine\ORM\EntityManagerInterface;
use Knp\Component\Pager\PaginatorInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Yosimitso\WorkingForumBundle\Entity\UserInterface;
use Yosimitso\WorkingForumBundle\Security\AuthorizationGuardInterface;
use Symfony\Component\Translation\DataCollectorTranslator;
use Yosimitso\WorkingForumBundle\Service\BundleParametersService;

/**
* Class BaseController
*
* @package Yosimitso\WorkingForumBundle\Controller
*/
class BaseController extends AbstractController
{
/**
Expand Down Expand Up @@ -63,10 +55,15 @@ public function setParameters(
) {
$this->em = $em;
$this->authorizationGuard = $authorizationGuard;
$this->user = (is_object($token)) ? $token->getUser() : null;
$this->user = (is_object($token) && $token->getUser() instanceof UserInterface) ? $token->getUser() : null;
$this->flashbag = $session->getFlashBag();
$this->translator = $translator;
$this->paginator = $paginator;
$this->bundleParameters = $bundleParameters;
}

protected function isUserAnonymous(): bool
{
return !$this->user instanceof UserInterface;
}
}
11 changes: 3 additions & 8 deletions Controller/ForumController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Yosimitso\WorkingForumBundle\Controller\BaseController;
use Yosimitso\WorkingForumBundle\Entity\Forum;
use Yosimitso\WorkingForumBundle\Entity\Rules;
use Yosimitso\WorkingForumBundle\Entity\Subforum;
Expand All @@ -15,16 +13,13 @@
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

/**
* Class ForumController
*
* @Route("/")
* @package Yosimitso\WorkingForumBundle\Controller
*/
class ForumController extends BaseController
{
private $dateFormat;
private $postPerPage;
private $threadPerPage;
private string $dateFormat;
private int $postPerPage;
private int $threadPerPage;

public function __construct(string $dateFormat, int $postPerPage, int $threadPerPage)
{
Expand Down
7 changes: 1 addition & 6 deletions Controller/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
use Yosimitso\WorkingForumBundle\Entity\Subforum;
use Yosimitso\WorkingForumBundle\Service\ThreadService;

/**
* Class PostController
*
* @package Yosimitso\WorkingForumBundle\Controller
*/
class PostController extends BaseController
{
/**
Expand All @@ -37,7 +32,7 @@ public function voteUpAction(Request $request)
{
$postId = $request->get('postId');

if (is_null($this->user)) {
if ($this->isUserAnonymous()) {
return new JsonResponse(['res' => 'false', 'errMsg' => 'You must be a registered user'], 403);
}

Expand Down
1 change: 0 additions & 1 deletion Controller/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Yosimitso\WorkingForumBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Form\FormFactory;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand Down
17 changes: 6 additions & 11 deletions Controller/ThreadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Symfony\Component\Config\Definition\Exception\Exception;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Yosimitso\WorkingForumBundle\Entity\Forum;
use Yosimitso\WorkingForumBundle\Entity\Post;
use Yosimitso\WorkingForumBundle\Entity\PostReport;
Expand All @@ -18,13 +17,12 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Yosimitso\WorkingForumBundle\Service\BundleParametersService;
use Yosimitso\WorkingForumBundle\Service\FileUploaderService;
use Yosimitso\WorkingForumBundle\Twig\Extension\SmileyTwigExtension;
use Yosimitso\WorkingForumBundle\Service\ThreadService;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;

/**
* @Route("/")
Expand Down Expand Up @@ -59,26 +57,23 @@ public function __construct(FileUploaderService $fileUploaderService, SmileyTwig
*/
public function indexAction(Forum $forum, Subforum $subforum, Thread $thread, Request $request)
{
$anonymousUser = (is_null($this->user)) ? true : false;

$autolock = $this->threadService->isAutolock($thread); // CHECK IF THREAD IS AUTOMATICALLY LOCKED (TOO OLD?)
$listSmiley = $this->smileyTwigExtension->getListSmiley(); // Smileys available for markdown

$post = new Post($this->user, $thread);

if (!$this->bundleParameters->thread_subscription['enable']) { // SUBSCRIPTION SYSTEM DISABLED
$canSubscribeThread = false;
} else {
$canSubscribeThread = (empty($this->em->getRepository(Subscription::class)->findBy(['thread' => $thread, 'user' => $this->user]))); // HAS ALREADY SUBSCRIBED ?
}

if (!$anonymousUser) {
if (!$this->isUserAnonymous()) {
$post = new Post($this->user, $thread);
$form = $this->createForm(PostType::class, $post, ['canSubscribeThread' => $canSubscribeThread]); // create form for posting
$form->handleRequest($request);

if ($form->isSubmitted()) { // USER SUBMIT HIS POST

if (!$anonymousUser && $this->user->isBanned()) // USER IS BANNED CAN'T POST
if ($this->user->isBanned()) // USER IS BANNED CAN'T POST
{
$this->flashbag->add(
'error',
Expand All @@ -98,7 +93,7 @@ public function indexAction(Forum $forum, Subforum $subforum, Thread $thread, Re
return $this->threadService->redirectToThread($forum, $subforum, $thread);
}

if ($form->isValid() && !$anonymousUser) {
if ($form->isValid()) {

try {
$this->threadService->post($subforum, $thread, $post, $this->user, $form);
Expand Down Expand Up @@ -179,7 +174,7 @@ public function indexAction(Forum $forum, Subforum $subforum, Thread $thread, Re
*/
public function newAction(Forum $forum, Subforum $subforum, Request $request)
{
if (is_null($this->user)) { //ANONYMOUS CAN'T POST
if ($this->isUserAnonymous()) { //ANONYMOUS CAN'T POST
throw new AccessDeniedHttpException("access denied");
}

Expand Down
2 changes: 2 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ public function getConfigTreeBuilder()
->end()
->end()
->end()
->scalarNode('mailer_sender_address')
->end()
->end()
;

Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/YosimitsoWorkingForumExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,6 @@ public function load(array $configs, ContainerBuilder $container)
$container->setParameter('yosimitso_working_forum.post_flood_sec', $config['post_flood_sec']);
$container->setParameter('yosimitso_working_forum.site_title', $config['site_title']);
$container->setParameter('yosimitso_working_forum.thread_subscription', $config['thread_subscription']);
$container->setParameter('yosimitso_working_forum.mailer_sender_address', $config['mailer_sender_address']);
}
}
37 changes: 10 additions & 27 deletions Entity/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,71 +23,54 @@ class Subscription
* @ORM\Column(name="id", type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
private int $id;

/**
* @var ArrayCollection
* @ORM\ManyToOne(targetEntity="Yosimitso\WorkingForumBundle\Entity\Thread", inversedBy="post")
* @ORM\JoinColumn(name="thread_id", referencedColumnName="id", nullable=true)
*/
private $thread;
private Thread $thread;

/**
* @var UserInterface
*
* @ORM\ManyToOne(targetEntity="Yosimitso\WorkingForumBundle\Entity\UserInterface")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=true)
*/
private $user;
private UserInterface $user;

public function __construct(Thread $thread, UserInterface $user)
{
$this->setThread($thread);
$this->setUser($user);
}

/**
* @return int
*/
public function getId()

public function getId(): int
{
return $this->id;
}

/**
* @param Thread $thread
*
* @return Post
*/
public function setThread(Thread $thread)
public function setThread(Thread $thread): self
{
$this->thread = $thread;

return $this;
}

/**
* @return ArrayCollection
*/
public function getThread()
public function getThread(): Thread
{
return $this->thread;
}

/**
* @return UserInterface
*/
public function getUser()
public function getUser(): UserInterface
{
return $this->user;
}

/**
* @param UserInterface $user
*
* @return Post
*/
public function setUser(UserInterface $user)

public function setUser(UserInterface $user): self
{
$this->user = $user;

Expand Down
Loading

0 comments on commit 14453f4

Please sign in to comment.