Skip to content

Commit

Permalink
inital
Browse files Browse the repository at this point in the history
  • Loading branch information
bmatschullat committed Dec 18, 2016
1 parent 47382bf commit 4c2886b
Show file tree
Hide file tree
Showing 15 changed files with 1,171 additions and 0 deletions.
64 changes: 64 additions & 0 deletions Command/AppCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/**
* @author Bennet Matschullat, Marketline GmbH <[email protected]>
* @date 23.06.2016 - 09:36
* @github <bmatschullat>
* @project - PhpStorm
*/

namespace Dreimweb\UserBundle\Command;



use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class AppCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('app:sendmails')
->setDescription('Send all Mails from que')
;
}

protected function execute(InputInterface $input, OutputInterface $output)
{
//$this->denyAccessUnlessGranted(['ROLE_DEVELOPER'], null, 'Unzureichende Rechte fuer diese Seite');
$repo = $this->getContainer()->get('doctrine');
$logger = $this->getContainer()->get('logger');
$manager = $repo->getManager();
$mails = $repo->getRepository('DreimwebUserBundle:Email')->findBy(['flagstate' => 0]);

/** @var Email $mail */
foreach ($mails as $mail) {
$mail->setFlagstate(true);
$message = \Swift_Message::newInstance()
->setSubject($mail->getSubject())
->setFrom('[email protected]', 'appname')
->setReplyTo('[email protected]')
->setTo($mail->getReceiver())
->setBody($mail->getBodyMessage(), 'text/html');
$type = $message->getHeaders()->get('Content-Type');

$output->writeln(sprintf('mail "%s" to "%s"', $mail->getSubject(), $mail->getReceiver()));
$type->setValue('text/html');
$type->setParameter('charset', 'utf-8');

// push to the logger
$logger->info(sprintf('mail "%s" to "%s"', $mail->getSubject(), $mail->getReceiver()));

$this->getContainer()->get('mailer')->send($message);
$manager->persist($mail);
}


$manager->flush();
$output->writeln('OK');
}
}
71 changes: 71 additions & 0 deletions Controller/SecurityController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
namespace Dreimweb\UserBundle\Controller;
use Dreimweb\UserBundle\Entity\Email;
use Ramsey\Uuid\Uuid;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Dreimweb\UserBundle\Entity\User;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Security;
class SecurityController extends Controller
{
/**
* @Route("/auth/login", name="_login")
* @Template()
*/
public function loginAction(Request $request)
{
$session = $request->getSession();
// get the login error if there is one
$error = $session->get(Security::AUTHENTICATION_ERROR);
$session->remove(Security::AUTHENTICATION_ERROR);
return array(
// last username entered by the user
'last_username' => $session->get(Security::LAST_USERNAME),
'error' => $error,
);
}
/**
* @Route("/auth/login_check", name="login_check")
* @Template()
*/
public function loginCheckAction()
{
return array(// ...
);
}
/**
* @Route("/auth/logout", name="_logout")
*/
public function logoutAction(Request $request)
{
$this->container->get('security.context')->setToken(null);
$uri = $this->get('router')->generate('homepage');
return $this->redirect($uri);
}
/**
* @Route("/auth/activation/{ident_key}", name="_user_activation")
*/
public function activationAction(Request $request, $ident_key)
{
// load session manager
$session = $this->get('session');
// load doctrine manager
$em = $this->getDoctrine()->getManager();
$userRepo = $em->getRepository('DreimwebUserBundle:User');
/** @var User $user */
$user = $userRepo->findOneBy(['ident_key' => $ident_key]);
if ($user) {
$user->setFlagstate(true);
$user->setIsActive(true);
$em->persist($user);
$em->flush();
$session->getFlashBag()->add('notice', 'Ihr Benutzerkonto wurde erfolgreich aktiviert');
} else {
$session->getFlashBag()->add('error', 'Kein Benutzer mit diesen Daten gefunden');
}
$uri = $this->get('router')->generate('_login');
return $this->redirect($uri);
}
}
59 changes: 59 additions & 0 deletions DataFixtures/ORM/LoadUserData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* @author Bennet Matschullat, 3mweb <[email protected]>
* @date 05.11.15 - 10:44
* @github <bmatschullat>
* @project - user bundle
*/

namespace Dreimweb\UserBundle\DataFixtures\ORM;

use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\Id\UuidGenerator;
use Dreimweb\UserBundle\Entity\User;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

class LoadUserData implements FixtureInterface, ContainerAwareInterface
{

// - - -
private $container;

public function setContainer(ContainerInterface $container = null)
{
$this->container = $container;
}

public function load(ObjectManager $manager)
{
$user = new User();
$user->setUsername('developer');
$user->setPassword($this->encodePassword($user, 'darthpass'));
$user->setEmail('[email protected]');
$user->setRoles(['ROLE_USER', 'ROLE_DEVELOPER', 'ROLE_ADMIN']);
$user->setFirstname('Vorname');
$user->setLastname('Nachname');
$user->setIsActive(true);

$manager->persist($user);
$manager->flush();
}

private function encodePassword(User $user, $plainPassword)
{
$encoder = $this->container->get('security.encoder_factory')
->getEncoder($user);

return $encoder->encodePassword($plainPassword, $user->getSalt());
}


public function getOrder()
{
return 1;
}


}
29 changes: 29 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Dreimweb\UserBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
* This is the class that validates and merges configuration from your app/config files.
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/configuration.html}
*/
class Configuration implements ConfigurationInterface
{
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('dreimweb_user');

// Here you should define the parameters that are allowed to
// configure your bundle. See the documentation linked above for
// more information on that topic.

return $treeBuilder;
}
}
28 changes: 28 additions & 0 deletions DependencyInjection/DreimwebUserExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Dreimweb\UserBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;

/**
* This is the class that loads and manages your bundle configuration.
*
* @link http://symfony.com/doc/current/cookbook/bundles/extension.html
*/
class DreimwebUserExtension extends Extension
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
}
}
9 changes: 9 additions & 0 deletions DreimwebUserBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Dreimweb\UserBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class DreimwebUserBundle extends Bundle
{
}
Loading

0 comments on commit 4c2886b

Please sign in to comment.