Permalink
Browse files

Completed user management. Added favicon

  • Loading branch information...
1 parent 0343ca1 commit d1af1c8b1d65b6ee2c67af2fa71e80ecccbcc85d Timo Haberkern committed Aug 2, 2011
@@ -15,7 +15,7 @@
<ul>
<li>
<a class="my-account"
- href="">
+ href="{{ path('cuteflow_my_account') }}">
{% trans %}My account{% endtrans %}
</a>
</li>
@@ -31,7 +31,7 @@
{% if app.user %}
<div id="loggedas">
- {% trans %}Logged in as{% endtrans %} <a href="">{{ app.user.username }}</a>
+ {% trans %}Logged in as{% endtrans %} <a href="{{ path('cuteflow_user_show', {'username': app.user.username}) }}">{{ app.user.username }}</a>
</div>
{% endif %}
@@ -0,0 +1,31 @@
+<?php
+namespace CuteFlow\CoreBundle\Controller;
+
+use Symfony\Bundle\FrameworkBundle\Controller\Controller;
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
+
+class AccountController extends Controller
+{
+ /**
+ * @Route("account/show/{username}", name="cuteflow_user_show")
+ * @Template()
+ */
+ public function showAction($username)
+ {
+ $em = $this->getDoctrine()->getEntityManager();
+ $user = $em->getRepository('CuteFlowCoreBundle:User')
+ ->findOneByUsername($username);
+
+ return array('user'=>$user);
+ }
+
+ /**
+ * @Route("/my/account", name="cuteflow_my_account")
+ * @Template()
+ */
+ public function editAction()
+ {
+ return array();
+ }
+}
@@ -38,6 +38,11 @@ public function loginAction()
$error = $this->get('request')->getSession()->get(SecurityContext::AUTHENTICATION_ERROR);
}
+ if (!$this->get('request')->getSession()->has('cuteflow_theme')) {
+ $defaultTheme = $this->get('cuteflow.settings_manager')->getSettings()->getDefaultTheme();
+ $this->get('request')->getSession()->set('cuteflow_theme', $defaultTheme);
+ }
+
return array(
'last_username' => $this->get('request')->getSession()->get(SecurityContext::LAST_USERNAME),
'error' => $error,
@@ -78,9 +78,11 @@ public function createAction()
public function saveAction($id)
{
$em = $this->getDoctrine()->getEntityManager();
-
+
+ $newUser = false;
if ($id == -1) {
$user = new User();
+ $newUser = true;
}
else {
$user = $em->find('CuteFlowCoreBundle:User', $id);
@@ -94,6 +96,11 @@ public function saveAction($id)
$userForm->bindRequest($this->getRequest());
if ($userForm->isValid()) {
+
+ if ($newUser) {
+ $this->get('cuteflow.mailer')->sendWelcomeEmailMessage($user);
+ }
+
$user_manager = $this->get('cuteflow.user_manager');
$user_manager->updatePassword($user);
@@ -0,0 +1,83 @@
+<?php
+
+namespace CuteFlow\CoreBundle\Mailer;
+
+use \Symfony\Component\Templating\EngineInterface;
+use CuteFlow\CoreBundle\Model\SettingsManager;
+use CuteFlow\CoreBundle\Entity\User;
+use Symfony\Component\Routing\RouterInterface;
+
+class Mailer
+{
+ /**
+ * @param use Symfony\Component\Routing\RouterInterface $router
+ * @param CuteFlow\CoreBundle\Model\SettingsManager $settingsManager
+ * @param Symfony\Component\Templating\EngineInterface $templating
+ */
+ public function __construct( RouterInterface $router,
+ SettingsManager $settingsManager,
+ EngineInterface $templating,
+ array $parameters)
+ {
+ $this->mailer = $settingsManager->getConfiguredMailer();
+ $this->settingsManager = $settingsManager;
+ $this->templating = $templating;
+ $this->router = $router;
+ $this->parameters = $parameters;
+ }
+
+ /**
+ * @param CuteFlow\CoreBundle\Entity\User $user
+ * @return void
+ */
+ public function sendWelcomeEmailMessage(User $user)
+ {
+ if ($this->settingsManager->getSettings()->getEmailFormat() == 'text/plain') {
+ $template = $this->parameters['welcome.template'].".text.twig";
+ }
+ else {
+ $template = $this->parameters['welcome.template'].".html.twig";
+ }
+ $url = $this->router->generate('cuteflow_dashboard', array(), true);
+ $rendered = $this->templating->render($template, array(
+ 'user' => $user,
+ 'homepage' => $url,
+ 'footer' => $this->settingsManager->getSettings()->getEmailFooter()
+ ));
+ $this->sendEmailMessage($rendered, $user->getEmail());
+ }
+
+ /**
+ * @param string $renderedTemplate
+ * @param string $toEmail
+ * @param string $fromEmail
+ * @return void
+ */
+ protected function sendEmailMessage($renderedTemplate, $toEmail, $fromEmail = null)
+ {
+ // Render the email, use the first line as the subject, and the rest as the body
+ $renderedLines = explode("\n", trim($renderedTemplate));
+ $subject = $renderedLines[0];
+ $body = implode("\n", array_slice($renderedLines, 1));
+
+ $format = $this->settingsManager->getSettings()->getEmailFormat();
+
+ $message = \Swift_Message::newInstance()
+ ->setSubject($subject)
+ ->setTo($toEmail)
+ ->setFrom($this->settingsManager->getSettings()->getEmissionMailAddress())
+ ->setBody($body, $format);
+
+ if ($fromEmail != null) {
+ $message->setFrom($fromEmail);
+ }
+
+ $this->mailer->send($message);
+ }
+
+ protected $mailer;
+ protected $settingsManager;
+ protected $templating;
+ protected $router;
+ protected $parameters;
+}
@@ -0,0 +1,56 @@
+<?php
+namespace CuteFlow\CoreBundle\Model;
+
+use Doctrine\ORM\EntityManager;
+
+class SettingsManager
+{
+ /**
+ * @param \Doctrine\ORM\EntityManager $em
+ */
+ public function __construct(EntityManager $em, $mailer)
+ {
+ $this->entityManager = $em;
+ $this->mailer = $mailer;
+ }
+
+ /**
+ * @return CuteFlow\CoreBundle\Entity\Settings
+ */
+ public function getSettings()
+ {
+ if ($this->settings == null) {
+ $this->settings = $this->entityManager
+ ->getRepository('CuteFlowCoreBundle:Settings')
+ ->find(1);
+ }
+
+ return $this->settings;
+ }
+
+ public function getConfiguredMailer()
+ {
+ $this->mailer->getTransport()->setHost($this->getSettings()->getSmtpHost());
+
+ if ($this->getSettings()->getSmtpAuthentication()) {
+ $this->mailer->getTransport()->setUsername($this->getSettings()->getSmtpUser());
+ $this->mailer->getTransport()->setPassword($this->getSettings()->getSmtpPassword());
+ }
+
+ $this->mailer->getTransport()->setEncryption($this->getSettings()->getSmtpEncryption());
+
+ return $this->mailer;
+ }
+
+ /**
+ * @var \Doctrine\ORM\EntityManager
+ */
+ protected $entityManager;
+
+ /**
+ * @var CuteFlow\CoreBundle\Entity\Settings
+ */
+ protected $settings;
+
+ protected $mailer;
+}
@@ -198,6 +198,18 @@
<source>The password fields must match</source>
<target>Die Passwörter müssen übereinstimmen</target>
</trans-unit>
+ <trans-unit id="50">
+ <source>Activity</source>
+ <target>Aktivität</target>
+ </trans-unit>
+ <trans-unit id="51">
+ <source>Registered on</source>
+ <target>Registriert am</target>
+ </trans-unit>
+ <trans-unit id="52">
+ <source>Information</source>
+ <target>Informationen</target>
+ </trans-unit>
</body>
</file>
</xliff>
@@ -0,0 +1,22 @@
+{% extends 'CuteFlowCoreBundle::layout.html.twig' %}
+
+{% block body %}
+<h2>
+ <img class="gravatar" width="50" height="50" src="{{ gravatar(user.email, 50) }}" />
+ {{ user.firstname }} {{ user.lastName }}
+</h2>
+<div class="splitcontentleft">
+ <h3>{% trans %}Information{% endtrans %}</h3>
+ <ul>
+ <li>{% trans %}Email{% endtrans %}: <a href="mailto:{{ user.email }}">{{ user.email }}</a></li>
+ <li>{% trans %}Registered on{% endtrans %}: {{ user.createdAt|localedate }}</li>
+ <li>{% trans %}Last login{% endtrans %}: {{ user.lastLogin|localedate }}</li>
+ </ul>
+</div>
+<div class="splitcontentright">
+ <h3>{% trans %}Activity{% endtrans %}</h3>
+</div>
+
+{% endblock %}
+
+{% block sidebarclass %}class="nosidebar"{% endblock %}
@@ -0,0 +1,39 @@
+{% block cuteflow_email_subject %}CuteFlow{% endblock %}
+
+<html>
+<head>
+<style>
+body {
+ font-family: Verdana, sans-serif;
+ font-size: 0.8em;
+ color:#484848;
+}
+h1, h2, h3 { font-family: "Trebuchet MS", Verdana, sans-serif; margin: 0px; }
+h1 { font-size: 1.2em; }
+h2, h3 { font-size: 1.1em; }
+a, a:link, a:visited { color: #2A5685;}
+a:hover, a:active { color: #c61a1a; }
+a.wiki-anchor { display: none; }
+hr {
+ width: 100%;
+ height: 1px;
+ background: #ccc;
+ border: 0;
+}
+.footer {
+ font-size: 0.8em;
+ font-style: italic;
+}
+</style>
+</head>
+<body>
+
+{% block cuteflow_email_body %}
+{% endblock %}
+
+<br/><br/>
+{% block footer %}
+{{ footer }}
+{% endblock %}
+</body>
+</html>
@@ -0,0 +1,8 @@
+{% block cuteflow_email_subject %}CuteFlow{% endblock %}
+
+{% block cuteflow_email_body %}
+{% endblock %}
+
+{% block footer %}
+{{ footer }}
+{% endblock %}
@@ -0,0 +1,15 @@
+{% extends 'CuteFlowCoreBundle:Mail:mail_layout.html.twig' %}
+
+{% block cuteflow_email_subject %}[CuteFlow] - {% trans %}Your account information{% endtrans %}{% endblock %}
+
+{% block cuteflow_email_body %}
+
+<p>{% trans%}Your CuteFlow account information{% endtrans %}:</p>
+<ul>
+ <li>{% trans%}Username{% endtrans %}: {{ user.username }}</li>
+ <li>{% trans%}Password{% endtrans %}: {{ user.plainPassword }}</li>
+</ul>
+<br/>
+{% trans %}Login{% endtrans %}: <a href="{{ homepage }}">{{ homepage }}</a>
+
+{% endblock %}
@@ -0,0 +1,15 @@
+{% extends 'CuteFlowCoreBundle:Mail:mail_layout.text.twig' %}
+
+{% block cuteflow_email_subject %}[CuteFlow] - {% trans %}Your account information{% endtrans %}{% endblock %}
+
+{% block cuteflow_email_body %}
+{% trans%}Your CuteFlow account information{% endtrans %}:
+=============================================
+
+* {% trans%}Username{% endtrans %}: {{ user.username }}
+* {% trans%}Password{% endtrans %}: {{ user.plainPassword }}
+
+
+{% trans %}Login{% endtrans %}: {{ homepage }}
+
+{% endblock %}
@@ -5,10 +5,10 @@
{% stylesheets
'@CuteFlowCoreBundle/Resources/public/css/application.css'
- '@CuteFlowCoreBundle/Resources/public/css/theme/modulaMojito/application.css'
%}
<link rel="stylesheet" href="{{ asset_url }}" type="text/css" media="all" />
{% endstylesheets %}
+ <link rel="stylesheet" href="{{ asset("bundles/cuteflowcore/css/theme/" ~ app.session.get('cuteflow_theme') ~ "/application.css") }}" />
{% endblock %}
{% block sidebarclass %}class="nosidebar"{% endblock %}
View
Binary file not shown.

0 comments on commit d1af1c8

Please sign in to comment.