Commit 51a953da authored by Hermann Mayer's avatar Hermann Mayer

Login: Implemented OAuth Login (first Google). Blog: Article Frontend and…

Login: Implemented OAuth Login (first Google). Blog: Article Frontend and Backend (User/Admin). Comments Frontend implemented.(Create/Delete/Update) Theme: Improved bright theme. Bright theme is now default for mobile requests. Fixtures: Improved Fixtures Structure. Common: Updated bin/ toolchain.
parent e012e662
......@@ -4,6 +4,7 @@
/app/logs/*
/vendor/
/app/config/parameters.yml
/app/config/oauth.yml
/.settings/
/.buildpath
......
......@@ -25,6 +25,8 @@ class AppKernel extends Kernel
new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(),
new Xi\Bundle\BreadcrumbsBundle\XiBreadcrumbsBundle(),
new JMS\SerializerBundle\JMSSerializerBundle(),
new HWI\Bundle\OAuthBundle\HWIOAuthBundle(),
new SunCat\MobileDetectBundle\MobileDetectBundle(),
);
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
......
......@@ -43,6 +43,7 @@
<link rel="icon" href="/favicon.ico" type="image/x-icon">
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:400,300,600' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Source+Code+Pro:400' rel='stylesheet' type='text/css'>
{% javascripts
'@JityHomepageBundle/Resources/public/js/essentials/*.js'
......@@ -167,7 +168,7 @@
<div class="alert alert-block alert-info fade in">
<button data-dismiss="alert" class="close" type="button">×</button>
<p>
<i class="icon-info-sign icon-white"></i> {{ flashMessage }}
<i class="icon-info-sign icon-white"></i> {{ flashMessage|raw }}
</p>
</div>
{% endfor %}
......@@ -176,7 +177,7 @@
<div class="alert alert-block alert-success fade in">
<button data-dismiss="alert" class="close" type="button">×</button>
<p>
<i class="icon-ok-sign icon-white"></i> {{ flashMessage }}
<i class="icon-ok-sign icon-white"></i> {{ flashMessage|raw }}
</p>
</div>
{% endfor %}
......@@ -185,7 +186,7 @@
<div class="alert alert-block alert-error fade in">
<button data-dismiss="alert" class="close" type="button">×</button>
<p>
<i class="icon-warning-sign icon-white"></i> {{ flashMessage }}
<i class="icon-warning-sign icon-white"></i> {{ flashMessage|raw }}
</p>
</div>
{% endfor %}
......@@ -227,7 +228,7 @@
<p><small>
Unter anderem biete ich folgende Diensten an:
<a target="_blank" href="http://gitorious.hermann-mayer.net">Gitorious</a>,
<a target="_blank" href="http://projects.hermann-mayer.net/">Chiliprojects</a> und
<a target="_blank" href="http://projects.hermann-mayer.net/">Chiliprojects</a> und das
<a target="_blank" href="http://ebay-tool.hermann-mayer.net/">eBay Tool</a>.
Allgemeine Informationen können Sie aus folgenden Quellen beziehen:
<a href="{{ path('page', {slug: 'impressum'}) }}">Impressum</a>,
......
......@@ -2,6 +2,7 @@ imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: jity.yml }
- { resource: oauth.yml }
framework:
#esi: ~
......@@ -64,6 +65,21 @@ swiftmailer:
username: %mailer_user%
password: %mailer_password%
# JMS Bundle Config for Security
jms_security_extra:
secure_all_services: false
# JMS Bundle Config for Dependency Injection
jms_di_extra:
locations:
all_bundles: false
bundles: [JityHomepageBundle]
directories: ["%kernel.root_dir%/../src"]
# Mobile Detection Bundle Config
mobile_detect:
redirect:
mobile: ~
tablet: ~
switch_device_view: ~
imports:
- { resource: config.yml }
doctrine:
orm:
metadata_cache_driver: apc
result_cache_driver: apc
query_cache_driver: apc
# doctrine:
# orm:
# metadata_cache_driver: apc
# result_cache_driver: apc
# query_cache_driver: apc
monolog:
handlers:
......
jity_homepage:
admin:
email: jack@hermann-mayer.net
email: admin@jity.de #jack@hermann-mayer.net
impress:
site_admin:
name: Herman Mayer
......
hwi_oauth:
resource_owners:
any_name:
type: google
client_id:
client_secret:
scope: "https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile"
# name of the firewall the oauth bundle is active in
firewall_name: secured_area
......@@ -9,15 +9,6 @@ security:
encode_as_base64: false
iterations: 1
# role_hierarchy:
# ROLE_AUTHOR: ROLE_USER
# ROLE_ADMIN: ROLE_AUTHOR
# ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
providers:
database:
entity: { class: JityHomepageBundle:User }
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
......@@ -27,17 +18,34 @@ security:
pattern: ^/login$
anonymous: ~
secured_area:
pattern: ^/
anonymous: ~
oauth_area:
pattern: ^/
form_login:
default_target_path: /user
logout: ~
provider: database
login_path: /login
check_path: /login_check
success_handler: jity.listener.login.success
anonymous: true
logout:
path: /logout
target: /
success_handler: jity.listener.logout.success
anonymous: true
oauth:
resource_owners:
google: /login/check/google
login_path: /login
failure_path: /login
success_handler: jity.listener.login.success
oauth_user_provider:
service: jity.oauth.user_provider
providers:
database:
entity: { class: JityHomepageBundle:User }
access_control:
- { path: ^/user, roles: ROLE_USER }
- { path: ^/author, roles: ROLE_AUTHOR }
- { path: ^/admin, roles: ROLE_ADMIN }
#- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }
#- { path: ^/_internal/secure, roles: IS_AUTHENTICATED_ANONYMOUSLY, ip: 127.0.0.1 }
No preview for this file type
#!/bin/bash
clear
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" && cd "${DIR}/.."
php app/console doctrine:database:drop --force
php app/console doctrine:database:create
php app/console doctrine:mapping:info || exit 1
php app/console doctrine:database:drop --force || exit 1
php app/console doctrine:database:create || exit 1
php app/console doctrine:schema:create
php app/console doctrine:schema:create || exit 1
yes | php app/console doctrine:fixtures:load
yes | php app/console doctrine:fixtures:load || exit 1
rm -rf app/cache/dev
#!/bin/bash
clear
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" && cd "${DIR}/.."
./bin/regen-db.sh
rm -rf app/cache/*
rm -rf app/cache/*
rm -rf app/logs/*
php app/console cache:clear --env=prod --no-debug
php app/console cache:warmup --env=prod --no-debug
php app/console assetic:dump --env=prod --no-debug
php app/console assets:install --symlink
chmod 777 -R app/logs/
chmod 777 -R app/cache/
chmod 777 -R web/css/
chmod 777 -R web/js/
......@@ -33,7 +33,9 @@
"doctrine/data-fixtures": "dev-master",
"knplabs/knp-markdown-bundle": "dev-master",
"stof/doctrine-extensions-bundle": "dev-master",
"xi/breadcrumbs-bundle": "dev-master"
"xi/breadcrumbs-bundle": "dev-master",
"hwi/oauth-bundle": "dev-master",
"suncat/mobile-detect-bundle": "dev-master"
},
"scripts": {
"post-install-cmd": [
......
This diff is collapsed.
<?php
namespace Jity\HomepageBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Jity\HomepageBundle\Entity\Article;
use Jity\HomepageBundle\Form\ArticleType;
/**
* Article controller.
*
*/
class ArticleController extends Controller
{
/**
* Lists all Article entities.
*
*/
public function indexAction()
{
$em = $this->getDoctrine()->getManager();
$entities = $em->getRepository('JityHomepageBundle:Article')->findAll();
return $this->render('JityHomepageBundle:Article:index.html.twig', array(
'entities' => $entities,
));
}
/**
* Finds and displays a Article entity.
*
*/
public function showAction($id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('JityHomepageBundle:Article')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Article entity.');
}
$deleteForm = $this->createDeleteForm($id);
return $this->render('JityHomepageBundle:Article:show.html.twig', array(
'entity' => $entity,
'delete_form' => $deleteForm->createView(), ));
}
/**
* Displays a form to create a new Article entity.
*
*/
public function newAction()
{
$entity = new Article();
$form = $this->createForm(new ArticleType(), $entity);
return $this->render('JityHomepageBundle:Article:new.html.twig', array(
'entity' => $entity,
'form' => $form->createView(),
));
}
/**
* Creates a new Article entity.
*
*/
public function createAction(Request $request)
{
$entity = new Article();
$form = $this->createForm(new ArticleType(), $entity);
$form->bind($request);
if ($form->isValid()) {
// Set current User as Author
$user = $this->container->get('security.context')->getToken()->getUser();
$entity->setAuthor($user);
$em = $this->getDoctrine()->getManager();
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('author_article_show', array('id' => $entity->getId())));
}
return $this->render('JityHomepageBundle:Article:new.html.twig', array(
'entity' => $entity,
'form' => $form->createView(),
));
}
/**
* Displays a form to edit an existing Article entity.
*
*/
public function editAction($id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('JityHomepageBundle:Article')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Article entity.');
}
$editForm = $this->createForm(new ArticleType(), $entity);
$deleteForm = $this->createDeleteForm($id);
return $this->render('JityHomepageBundle:Article:edit.html.twig', array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
}
/**
* Edits an existing Article entity.
*
*/
public function updateAction(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('JityHomepageBundle:Article')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Article entity.');
}
$deleteForm = $this->createDeleteForm($id);
$editForm = $this->createForm(new ArticleType(), $entity);
$editForm->bind($request);
if ($editForm->isValid()) {
// Set current User as Author
$user = $this->container->get('security.context')->getToken()->getUser();
$entity->setAuthor($user);
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('author_article_edit', array('id' => $id)));
}
return $this->render('JityHomepageBundle:Article:edit.html.twig', array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
}
/**
* Deletes a Article entity.
*
*/
public function deleteAction(Request $request, $id)
{
$form = $this->createDeleteForm($id);
$form->bind($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('JityHomepageBundle:Article')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Article entity.');
}
$em->remove($entity);
$em->flush();
}
return $this->redirect($this->generateUrl('author_article'));
}
private function createDeleteForm($id)
{
return $this->createFormBuilder(array('id' => $id))
->add('id', 'hidden')
->getForm()
;
}
}
<?php
namespace Jity\HomepageBundle\Controller;
use Jity\HomepageBundle\Entity\Article,
Jity\HomepageBundle\Entity\Comment,
Jity\HomepageBundle\Form\CommentType,
Symfony\Component\HttpFoundation\Request,
Symfony\Component\HttpFoundation\Response,
Symfony\Bundle\FrameworkBundle\Controller\Controller;
/**
* BlogController
*
* @uses Controller
* @version $id$
* @author Hermann Mayer <hermann.mayer92@gmail.com>
*/
class BlogController extends Controller
{
/**
* showAction
*
* @param mixed $slug
* @access public
* @return void
*/
public function showAction($slug)
{
// Get Entity Manager
$em = $this->getDoctrine()->getEntityManager();
// Try to get the requested Page
if (!empty($slug)) {
$article = $em->getRepository('JityHomepageBundle:Article')->findOneBySlug($slug);
}
// Article was not found
if (!$article) {
return $this->forward('JityHomepageBundle:Default:showInfo', array('template' => 'homepage_notfound'));
}
// Return the rendered result
return $this->render('JityHomepageBundle:Blog:show.html.twig', array(
'article' => $article
));
}
/**
* dashboardAction
*
* @access public
* @return void
*/
public function dashboardAction()
{
$em = $this->getDoctrine()->getManager();
$entities = $em->getRepository('JityHomepageBundle:Article')->findBy(array(), array('createdAt' => 'DESC'), 10);
foreach ($entities as $entity) {
// Get only the first paragraph (all until first blank line)
$matches = '';
preg_match("/((.*|\n)*)\n[\s]/", $entity->getContent(), $matches);
if (!empty($matches[0])) {
$entity->setContent(trim($matches[0]));
} else {
$entity->setContent(trim(substr($entity->getContent(), 0, 400)));
}
}
return $this->render('JityHomepageBundle:Blog:dashboard.html.twig', array(
'entities' => $entities,
));
}
/**
* sectionArchivAction
*
* @access public
* @return void
*/
public function sectionArchivAction()
{
$em = $this->getDoctrine()->getManager();
// Use DQL because its more powerfull and only one query is needed
$q = $em->createQueryBuilder()
->select('a.createdAt')
->from('JityHomepageBundle:Article', 'a')
->getQuery()
;
$archivMap = array();
// Map the archiv
foreach ($q->getArrayResult() as $entity) {
$date = $entity['createdAt'];
$year = $date->format('Y');
$month = $date->format('F');
if (array_key_exists($year, $archivMap) && array_key_exists($month, $archivMap[$year])) {
// We found a existing year/month combo -> increase counter
$archivMap[$year][$month]++;
} else {
// We found a new year/month combo -> set first entry
$archivMap[$year][$month] = 1;
}
}
return $this->render('JityHomepageBundle:Blog:archiv_section.html.twig', array(
'map' => $archivMap,
));
}
/**
* createCommentFormAction
*
* @param mixed $comment
* @param mixed $form
* @param mixed $action
* @param mixed $renderFormTag
* @param mixed $visible
* @access public
* @return void
*/
public function createCommentFormAction($comment = null, $form = null, $action = null, $renderFormTag = true, $visible = true)
{
if (!$form) {
$form = $this
->createForm(new CommentType(), (!$comment) ? new Comment() : $comment)
->createView()
;
}
return $this->render('JityHomepageBundle:Form:render.html.twig', array(
'renderFormTag' => $renderFormTag,
'visible' => $visible,
'form' => $form,
'action' => $action
));
}
/**
* createCommentAction
*
* @param Request $request
* @access public
* @return void
*/
public function createCommentAction(Request $request, $id)
{
$entity = new Comment();
$form = $this->createForm(new CommentType(), $entity);
$form->bind($request);
$em = $this->getDoctrine()->getManager();
$article = $em->getRepository('JityHomepageBundle:Article')->find($id);
if ($article && $form->isValid()) {
// Set current User as Author
$user = $this->container->get('security.context')->getToken()->getUser();
if (is_object($user)) {
$entity->setAuthor($user);
}
// Try to get the requested Page
if (!empty($slug)) {
$article = $em->getRepository('JityHomepageBundle:Article')->findOneBySlug($slug);
}
$entity->setArticle($article);
$em->persist($entity);
$em->flush();
// Write flash message and redirect back
$this->get('session')->getFlashBag()->add('success', 'Ihr Kommentar wurde gespeichert. &mdash; '
. '<a class="btn btn-small btn-danger" href="#comment-' . $entity->getId()
. '">Zu den Kommentaren</a>');
// Redirect to the page where we came frome
return $this->redirect(
$this->get('router')->generate('article', array(
'slug' => $article->getSlug()
)) . '#top'
);
}
return $this->render('JityHomepageBundle:Blog:show.html.twig', array(
'article' => $article,
'form_new' => $form->createView(),
));
}
/**
* deleteCommentAction
*
* @param Request $request
* @param mixed $id
* @access public
* @return void
*/
public function deleteCommentAction(Request $request, $id)
{
$form = $this->deleteCommentFormAction($id);
$form->bind($request);
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('JityHomepageBundle:Comment')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Comment entity.');
}
if ($form->isValid()) {
$em->remove($entity);
$em->flush();
return new Response();
}
$entity = new Comment();
$form = $this->createForm(new CommentType(), $entity);
return $this->render('JityHomepageBundle:Blog:show.html.twig', array(
'article' => $entity->getArticle()
));
}
/**
* deleteCommentFormAction
*