Added login and posting functionality
Signed-off-by: Gergely Polonkai (W00d5t0ck) <polesz@w00d5t0ck.info>
This commit is contained in:
parent
5bcd9f079b
commit
04d408aee0
@ -23,6 +23,7 @@ class AppKernel extends Kernel
|
|||||||
new Io\TcpdfBundle\IoTcpdfBundle(),
|
new Io\TcpdfBundle\IoTcpdfBundle(),
|
||||||
new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(),
|
new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(),
|
||||||
new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(),
|
new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(),
|
||||||
|
new Ivory\CKEditorBundle\IvoryCKEditorBundle(),
|
||||||
new GergelyPolonkai\FrontBundle\GergelyPolonkaiFrontBundle(),
|
new GergelyPolonkai\FrontBundle\GergelyPolonkaiFrontBundle(),
|
||||||
new GergelyPolonkai\GeshiBundle\GergelyPolonkaiGeshiBundle(),
|
new GergelyPolonkai\GeshiBundle\GergelyPolonkaiGeshiBundle(),
|
||||||
);
|
);
|
||||||
|
28
app/DoctrineMigrations/Version20120904170638.php
Normal file
28
app/DoctrineMigrations/Version20120904170638.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Application\Migrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Migrations\AbstractMigration,
|
||||||
|
Doctrine\DBAL\Schema\Schema;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-generated Migration: Please modify to your need!
|
||||||
|
*/
|
||||||
|
class Version20120904170638 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function up(Schema $schema)
|
||||||
|
{
|
||||||
|
// this up() migration is autogenerated, please modify it to your needs
|
||||||
|
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql");
|
||||||
|
|
||||||
|
$this->addSql("ALTER TABLE users ADD password VARCHAR(50) NOT NULL");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema)
|
||||||
|
{
|
||||||
|
// this down() migration is autogenerated, please modify it to your needs
|
||||||
|
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql");
|
||||||
|
|
||||||
|
$this->addSql("ALTER TABLE users DROP password");
|
||||||
|
}
|
||||||
|
}
|
@ -4,18 +4,18 @@ jms_security_extra:
|
|||||||
|
|
||||||
security:
|
security:
|
||||||
encoders:
|
encoders:
|
||||||
Symfony\Component\Security\Core\User\User: plaintext
|
GergelyPolonkai\FrontBundle\Entity\User:
|
||||||
|
id: gergely_polonkai_front.service.crypt_encoder
|
||||||
|
|
||||||
role_hierarchy:
|
role_hierarchy:
|
||||||
ROLE_ADMIN: ROLE_USER
|
ROLE_ADMIN: ROLE_USER
|
||||||
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
|
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
|
||||||
|
|
||||||
providers:
|
providers:
|
||||||
in_memory:
|
gergely_polonkai_front.entity.user:
|
||||||
memory:
|
entity:
|
||||||
users:
|
class: GergelyPolonkai\FrontBundle\Entity\User
|
||||||
user: { password: userpass, roles: [ 'ROLE_USER' ] }
|
property: username
|
||||||
admin: { password: adminpass, roles: [ 'ROLE_ADMIN' ] }
|
|
||||||
|
|
||||||
firewalls:
|
firewalls:
|
||||||
dev:
|
dev:
|
||||||
@ -23,17 +23,17 @@ security:
|
|||||||
security: false
|
security: false
|
||||||
|
|
||||||
login:
|
login:
|
||||||
pattern: ^/demo/secured/login$
|
pattern: ^/admin/login.html$
|
||||||
security: false
|
security: false
|
||||||
|
|
||||||
secured_area:
|
secured_area:
|
||||||
pattern: ^/demo/secured/
|
pattern: ^/admin
|
||||||
form_login:
|
form_login:
|
||||||
check_path: /demo/secured/login_check
|
check_path: /admin/login-check.do
|
||||||
login_path: /demo/secured/login
|
login_path: /admin/login.html
|
||||||
logout:
|
logout:
|
||||||
path: /demo/secured/logout
|
path: /admin/logout
|
||||||
target: /demo/
|
target: /
|
||||||
#anonymous: ~
|
#anonymous: ~
|
||||||
#http_basic:
|
#http_basic:
|
||||||
# realm: "Secured Demo Area"
|
# realm: "Secured Demo Area"
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
"easybook/geshi": "dev-master",
|
"easybook/geshi": "dev-master",
|
||||||
"stof/doctrine-extensions-bundle": "dev-master",
|
"stof/doctrine-extensions-bundle": "dev-master",
|
||||||
"doctrine/doctrine-migrations-bundle": "dev-master",
|
"doctrine/doctrine-migrations-bundle": "dev-master",
|
||||||
|
"egeloen/ckeditor-bundle": "dev-master",
|
||||||
"gergelypolonkai/tcpdfbundle": "dev-master"
|
"gergelypolonkai/tcpdfbundle": "dev-master"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -0,0 +1,79 @@
|
|||||||
|
<?php
|
||||||
|
namespace GergelyPolonkai\FrontBundle\Controller;
|
||||||
|
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||||
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||||
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
|
||||||
|
use Symfony\Component\Security\Core\SecurityContext;
|
||||||
|
|
||||||
|
use GergelyPolonkai\FrontBundle\Form\PostType;
|
||||||
|
use GergelyPolonkai\FrontBundle\Entity\Post;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of AdminController
|
||||||
|
*
|
||||||
|
* @author polonkai.gergely
|
||||||
|
*
|
||||||
|
* @Route("/admin")
|
||||||
|
*/
|
||||||
|
class AdminController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*
|
||||||
|
* @Route("/login.html")
|
||||||
|
* @Template
|
||||||
|
*/
|
||||||
|
public function loginAction()
|
||||||
|
{
|
||||||
|
$request = $this->getRequest();
|
||||||
|
$session = $request->getSession();
|
||||||
|
|
||||||
|
if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
|
||||||
|
$error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
|
||||||
|
} else {
|
||||||
|
$error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
|
||||||
|
$session->remove(SecurityContext::AUTHENTICATION_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'last_username' => $session->get(SecurityContext::LAST_USERNAME),
|
||||||
|
'error' => $error,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Route("/login-check.do", name="GergelyPolonkaiFrontBundle_adminLoginCheck")
|
||||||
|
*/
|
||||||
|
public function loginCheckAction()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Route("/blog/post", name="GergelyPolonkaiFrontBundle_adminNewBlogPost")
|
||||||
|
* @Template
|
||||||
|
*/
|
||||||
|
public function newBlogPostAction()
|
||||||
|
{
|
||||||
|
$post = new Post();
|
||||||
|
$form = $this->createForm(new PostType(), $post);
|
||||||
|
$request = $this->getRequest();
|
||||||
|
$user = $this->get('security.context')->getToken()->getUser();
|
||||||
|
|
||||||
|
if ($request->getMethod() === 'POST') {
|
||||||
|
$form->bind($request);
|
||||||
|
if ($form->isValid()) {
|
||||||
|
$post->setUser($user);
|
||||||
|
$em = $this->getDoctrine()->getEntityManager();
|
||||||
|
$em->persist($post);
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
return $this->redirect($this->generateUrl('GergelyPolonkaiFrontBundle_adminNewBlogPost'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'form' => $form->createView(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,7 @@ namespace GergelyPolonkai\FrontBundle\Entity;
|
|||||||
|
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
use Gedmo\Mapping\Annotation as GedmoORM;
|
use Gedmo\Mapping\Annotation as GedmoORM;
|
||||||
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description of Post
|
* Description of Post
|
||||||
@ -36,6 +37,7 @@ class Post
|
|||||||
* @var string $title
|
* @var string $title
|
||||||
*
|
*
|
||||||
* @ORM\Column(type="string", length=100)
|
* @ORM\Column(type="string", length=100)
|
||||||
|
* @Assert\NotBlank()
|
||||||
*/
|
*/
|
||||||
private $title;
|
private $title;
|
||||||
|
|
||||||
@ -51,6 +53,7 @@ class Post
|
|||||||
* @var string $content
|
* @var string $content
|
||||||
*
|
*
|
||||||
* @ORM\Column(type="text", nullable=false)
|
* @ORM\Column(type="text", nullable=false)
|
||||||
|
* @Assert\NotBlank()
|
||||||
*/
|
*/
|
||||||
private $content;
|
private $content;
|
||||||
|
|
||||||
@ -160,4 +163,30 @@ class Post
|
|||||||
{
|
{
|
||||||
return $this->createdAt;
|
return $this->createdAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set slug
|
||||||
|
*
|
||||||
|
* @param string $slug
|
||||||
|
* @return Post
|
||||||
|
*/
|
||||||
|
public function setSlug($slug)
|
||||||
|
{
|
||||||
|
$this->slug = $slug;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set createdAt
|
||||||
|
*
|
||||||
|
* @param \DateTime $createdAt
|
||||||
|
* @return Post
|
||||||
|
*/
|
||||||
|
public function setCreatedAt($createdAt)
|
||||||
|
{
|
||||||
|
$this->createdAt = $createdAt;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
@ -2,6 +2,7 @@
|
|||||||
namespace GergelyPolonkai\FrontBundle\Entity;
|
namespace GergelyPolonkai\FrontBundle\Entity;
|
||||||
|
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use Symfony\Component\Security\Core\User\UserInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description of User
|
* Description of User
|
||||||
@ -11,7 +12,7 @@ use Doctrine\ORM\Mapping as ORM;
|
|||||||
* @ORM\Entity
|
* @ORM\Entity
|
||||||
* @ORM\Table(name="users")
|
* @ORM\Table(name="users")
|
||||||
*/
|
*/
|
||||||
class User
|
class User implements UserInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @ORM\Id
|
* @ORM\Id
|
||||||
@ -30,6 +31,29 @@ class User
|
|||||||
*/
|
*/
|
||||||
private $name;
|
private $name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string $password
|
||||||
|
*
|
||||||
|
* @ORM\Column(type="string", length=50, nullable=false)
|
||||||
|
*/
|
||||||
|
private $password;
|
||||||
|
|
||||||
|
public function __toString()
|
||||||
|
{
|
||||||
|
return $this->name . '(' . $this->username . ')';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSalt() {
|
||||||
|
return $this->password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function eraseCredentials() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRoles() {
|
||||||
|
return array('ROLE_ADMIN');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get id
|
* Get id
|
||||||
*
|
*
|
||||||
@ -85,4 +109,26 @@ class User
|
|||||||
{
|
{
|
||||||
return $this->name;
|
return $this->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set password
|
||||||
|
*
|
||||||
|
* @param string $password
|
||||||
|
* @return User
|
||||||
|
*/
|
||||||
|
public function setPassword($password)
|
||||||
|
{
|
||||||
|
$this->password = $password;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get password
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getPassword()
|
||||||
|
{
|
||||||
|
return $this->password;
|
||||||
|
}
|
||||||
}
|
}
|
30
src/GergelyPolonkai/FrontBundle/Form/PostType.php
Normal file
30
src/GergelyPolonkai/FrontBundle/Form/PostType.php
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace GergelyPolonkai\FrontBundle\Form;
|
||||||
|
|
||||||
|
use Symfony\Component\Form\AbstractType;
|
||||||
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
|
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
|
||||||
|
|
||||||
|
class PostType extends AbstractType
|
||||||
|
{
|
||||||
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||||
|
{
|
||||||
|
$builder
|
||||||
|
->add('title')
|
||||||
|
->add('content', 'ckeditor')
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDefaultOptions(OptionsResolverInterface $resolver)
|
||||||
|
{
|
||||||
|
$resolver->setDefaults(array(
|
||||||
|
'data_class' => 'GergelyPolonkai\FrontBundle\Entity\Post'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return 'gergelypolonkai_frontbundle_posttype';
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
{% extends 'GergelyPolonkaiFrontBundle:Default:front_base.html.twig' %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h3>Bejelentkezés</h3>
|
||||||
|
{% if error %}
|
||||||
|
<div id="error">{{ error }}</div>
|
||||||
|
{% endif %}
|
||||||
|
<form method="post" action="{{ path('GergelyPolonkaiFrontBundle_adminLoginCheck') }}">
|
||||||
|
<input type="text" name="_username" vale="{{ last_username }}" />
|
||||||
|
<input type="password" name="_password" />
|
||||||
|
<button type="submit">Login</button>
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
@ -0,0 +1,8 @@
|
|||||||
|
{% extends 'GergelyPolonkaiFrontBundle:Default:front_base.html.twig' %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<form method="post" action="{{ path('GergelyPolonkaiFrontBundle_adminNewBlogPost') }}">
|
||||||
|
{{ form_widget(form) }}
|
||||||
|
<button type="submit">Save</button>
|
||||||
|
</form>
|
||||||
|
{% endblock content %}
|
23
src/GergelyPolonkai/FrontBundle/Service/CryptEncoder.php
Normal file
23
src/GergelyPolonkai/FrontBundle/Service/CryptEncoder.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
namespace GergelyPolonkai\FrontBundle\Service;
|
||||||
|
|
||||||
|
use Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface;
|
||||||
|
use JMS\DiExtraBundle\Annotation as DI;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of CryptEncoder
|
||||||
|
*
|
||||||
|
* @author polonkai.gergely
|
||||||
|
*
|
||||||
|
* @DI\Service("gergely_polonkai_front.service.crypt_encoder")
|
||||||
|
*/
|
||||||
|
class CryptEncoder implements PasswordEncoderInterface
|
||||||
|
{
|
||||||
|
public function encodePassword($raw, $salt) {
|
||||||
|
return crypt($raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isPasswordValid($encoded, $raw, $salt) {
|
||||||
|
return (crypt($raw, $encoded) === $encoded);
|
||||||
|
}
|
||||||
|
}
|
@ -35,6 +35,7 @@ class GeshiHighlight extends \Twig_Extension
|
|||||||
$this->geshi->set_source($code);
|
$this->geshi->set_source($code);
|
||||||
$this->geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
|
$this->geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
|
||||||
$this->geshi->enable_keyword_links(false);
|
$this->geshi->enable_keyword_links(false);
|
||||||
|
$this->geshi->set_overall_class("code");
|
||||||
$this->geshi->enable_classes();
|
$this->geshi->enable_classes();
|
||||||
|
|
||||||
return $this->geshi->parse_code();
|
return $this->geshi->parse_code();
|
||||||
|
Loading…
Reference in New Issue
Block a user