improvements
This commit is contained in:
71
src/AppBundle/Controller/ProfileController.php
Normal file
71
src/AppBundle/Controller/ProfileController.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai package.
|
||||
*
|
||||
* (c) Kevin Papst <kevin@kevinpapst.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace AppBundle\Controller;
|
||||
|
||||
use TimesheetBundle\Entity\Timesheet;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
|
||||
|
||||
/**
|
||||
* User profile controller
|
||||
*
|
||||
* @Route("/profile")
|
||||
* @Security("has_role('ROLE_USER')")
|
||||
*
|
||||
* @author Kevin Papst <kevin@kevinpapst.de>
|
||||
*/
|
||||
class ProfileController extends Controller
|
||||
{
|
||||
/**
|
||||
* @Route("/", defaults={"ident": null}, name="user_profile")
|
||||
* @Route("/{ident}/", requirements={"ident": "[a-zA-Z0-9\-].*"}, name="user_profile_ident")
|
||||
* @Method("GET")
|
||||
*/
|
||||
public function indexAction($ident)
|
||||
{
|
||||
// FIXME fetch values dynamically and add trans filter to macros
|
||||
$items = [
|
||||
[
|
||||
'title' => 'Projects',
|
||||
'url' => '#',
|
||||
'color' => 'blue',
|
||||
'amount' => 12
|
||||
],
|
||||
[
|
||||
'title' => 'Tasks',
|
||||
'url' => '#',
|
||||
'color' => 'aqua',
|
||||
'amount' => 5
|
||||
],
|
||||
[
|
||||
'title' => 'Projects',
|
||||
'url' => '#',
|
||||
'color' => 'red',
|
||||
'amount' => 27
|
||||
],
|
||||
[
|
||||
'title' => 'Einträge',
|
||||
'url' => '#',
|
||||
'color' => 'green',
|
||||
'amount' => 842
|
||||
],
|
||||
];
|
||||
|
||||
return $this->render(
|
||||
'user/profile.html.twig',
|
||||
['user' => $this->getUser(), 'items' => $items]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,7 @@ class SecurityController extends Controller
|
||||
{
|
||||
$helper = $this->get('security.authentication_utils');
|
||||
|
||||
//return $this->render('AvanzuAdminThemeBundle:Security:login.html.twig', [
|
||||
return $this->render('security/login.html.twig', [
|
||||
// last username entered by the user (if any)
|
||||
'last_username' => $helper->getLastUsername(),
|
||||
|
||||
@@ -41,6 +41,8 @@ class LoadFixtures implements FixtureInterface, ContainerAwareInterface
|
||||
$passwordEncoder = $this->container->get('security.password_encoder');
|
||||
|
||||
$claraCustomer = new User();
|
||||
$claraCustomer->setAlias('Clara Haynes');
|
||||
$claraCustomer->setTitle('CFO');
|
||||
$claraCustomer->setUsername('clara_customer');
|
||||
$claraCustomer->setEmail('clara_customer@example.com');
|
||||
$claraCustomer->setRoles(['ROLE_CUSTOMER']);
|
||||
@@ -49,6 +51,8 @@ class LoadFixtures implements FixtureInterface, ContainerAwareInterface
|
||||
$manager->persist($claraCustomer);
|
||||
|
||||
$johnUser = new User();
|
||||
$johnUser->setAlias('John Doe');
|
||||
$johnUser->setTitle('Lead Developer');
|
||||
$johnUser->setUsername('john_user');
|
||||
$johnUser->setEmail('john_user@example.com');
|
||||
$johnUser->setRoles(['ROLE_USER']);
|
||||
@@ -57,6 +61,8 @@ class LoadFixtures implements FixtureInterface, ContainerAwareInterface
|
||||
$manager->persist($johnUser);
|
||||
|
||||
$tonyTeamlead = new User();
|
||||
$tonyTeamlead->setAlias('Tony Maier');
|
||||
$tonyTeamlead->setTitle('Head of Development');
|
||||
$tonyTeamlead->setUsername('tony_teamlead');
|
||||
$tonyTeamlead->setEmail('tony_teamlead@example.com');
|
||||
$tonyTeamlead->setRoles(['ROLE_TEAMLEAD']);
|
||||
@@ -65,6 +71,8 @@ class LoadFixtures implements FixtureInterface, ContainerAwareInterface
|
||||
$manager->persist($tonyTeamlead);
|
||||
|
||||
$annaAdmin = new User();
|
||||
$annaAdmin->setAlias('Anna Smith');
|
||||
$annaAdmin->setTitle('Administrator');
|
||||
$annaAdmin->setUsername('anna_admin');
|
||||
$annaAdmin->setEmail('anna_admin@example.com');
|
||||
$annaAdmin->setRoles(['ROLE_ADMIN']);
|
||||
|
||||
@@ -7,7 +7,7 @@ use Symfony\Component\Security\Core\User\UserInterface;
|
||||
|
||||
|
||||
/**
|
||||
* KimaiUsers
|
||||
* User
|
||||
*
|
||||
* @ORM\Entity(repositoryClass="AppBundle\Repository\UserRepository")
|
||||
* @ORM\Table(name="users", uniqueConstraints={@ORM\UniqueConstraint(name="name", columns={"name"}), @ORM\UniqueConstraint(name="apikey", columns={"apikey"})})
|
||||
@@ -46,6 +46,8 @@ class User implements UserInterface
|
||||
private $alias;
|
||||
|
||||
/**
|
||||
* FIXME remove me
|
||||
*
|
||||
* @var boolean
|
||||
*
|
||||
* @ORM\Column(name="trash", type="boolean", nullable=false)
|
||||
@@ -67,6 +69,8 @@ class User implements UserInterface
|
||||
private $passwordresethash;
|
||||
|
||||
/**
|
||||
* FIXME remove me
|
||||
*
|
||||
* @var integer
|
||||
*
|
||||
* @ORM\Column(name="ban", type="integer", nullable=false)
|
||||
@@ -74,6 +78,7 @@ class User implements UserInterface
|
||||
private $ban = '0';
|
||||
|
||||
/**
|
||||
* FIXME remove me
|
||||
* @var integer
|
||||
*
|
||||
* @ORM\Column(name="banTime", type="integer", nullable=false)
|
||||
@@ -88,7 +93,7 @@ class User implements UserInterface
|
||||
private $secure = '0';
|
||||
|
||||
/**
|
||||
* FIXME
|
||||
* FIXME manytoone relation
|
||||
*
|
||||
* @var integer
|
||||
*
|
||||
@@ -97,7 +102,7 @@ class User implements UserInterface
|
||||
private $lastproject = '1';
|
||||
|
||||
/**
|
||||
* FIXME
|
||||
* FIXME manytoone
|
||||
*
|
||||
* @var integer
|
||||
*
|
||||
@@ -133,17 +138,32 @@ class User implements UserInterface
|
||||
*/
|
||||
private $apikey;
|
||||
|
||||
// ======= new columns for kimai 2 =======
|
||||
/**
|
||||
* @ORM\Column(type="json_array")
|
||||
*/
|
||||
private $roles = [];
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="title", type="string", length=50, nullable=true)
|
||||
*/
|
||||
private $title;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="avatar", type="string", length=50, nullable=true)
|
||||
*/
|
||||
private $avatar;
|
||||
|
||||
/**
|
||||
* Set alias
|
||||
*
|
||||
* @param string $alias
|
||||
*
|
||||
* @return KimaiUsers
|
||||
* @return User
|
||||
*/
|
||||
public function setAlias($alias)
|
||||
{
|
||||
@@ -167,7 +187,7 @@ class User implements UserInterface
|
||||
*
|
||||
* @param boolean $trash
|
||||
*
|
||||
* @return KimaiUsers
|
||||
* @return User
|
||||
*/
|
||||
public function setTrash($trash)
|
||||
{
|
||||
@@ -191,7 +211,7 @@ class User implements UserInterface
|
||||
*
|
||||
* @param boolean $active
|
||||
*
|
||||
* @return KimaiUsers
|
||||
* @return User
|
||||
*/
|
||||
public function setActive($active)
|
||||
{
|
||||
@@ -215,7 +235,7 @@ class User implements UserInterface
|
||||
*
|
||||
* @param string $password
|
||||
*
|
||||
* @return KimaiUsers
|
||||
* @return User
|
||||
*/
|
||||
public function setPassword($password)
|
||||
{
|
||||
@@ -239,7 +259,7 @@ class User implements UserInterface
|
||||
*
|
||||
* @param string $passwordresethash
|
||||
*
|
||||
* @return KimaiUsers
|
||||
* @return User
|
||||
*/
|
||||
public function setPasswordresethash($passwordresethash)
|
||||
{
|
||||
@@ -263,7 +283,7 @@ class User implements UserInterface
|
||||
*
|
||||
* @param integer $ban
|
||||
*
|
||||
* @return KimaiUsers
|
||||
* @return User
|
||||
*/
|
||||
public function setBan($ban)
|
||||
{
|
||||
@@ -287,7 +307,7 @@ class User implements UserInterface
|
||||
*
|
||||
* @param integer $bantime
|
||||
*
|
||||
* @return KimaiUsers
|
||||
* @return User
|
||||
*/
|
||||
public function setBantime($bantime)
|
||||
{
|
||||
@@ -311,7 +331,7 @@ class User implements UserInterface
|
||||
*
|
||||
* @param string $secure
|
||||
*
|
||||
* @return KimaiUsers
|
||||
* @return User
|
||||
*/
|
||||
public function setSecure($secure)
|
||||
{
|
||||
@@ -335,7 +355,7 @@ class User implements UserInterface
|
||||
*
|
||||
* @param integer $lastproject
|
||||
*
|
||||
* @return KimaiUsers
|
||||
* @return User
|
||||
*/
|
||||
public function setLastproject($lastproject)
|
||||
{
|
||||
@@ -359,7 +379,7 @@ class User implements UserInterface
|
||||
*
|
||||
* @param integer $lastactivity
|
||||
*
|
||||
* @return KimaiUsers
|
||||
* @return User
|
||||
*/
|
||||
public function setLastactivity($lastactivity)
|
||||
{
|
||||
@@ -383,7 +403,7 @@ class User implements UserInterface
|
||||
*
|
||||
* @param integer $lastrecord
|
||||
*
|
||||
* @return KimaiUsers
|
||||
* @return User
|
||||
*/
|
||||
public function setLastrecord($lastrecord)
|
||||
{
|
||||
@@ -407,7 +427,7 @@ class User implements UserInterface
|
||||
*
|
||||
* @param string $timeframebegin
|
||||
*
|
||||
* @return KimaiUsers
|
||||
* @return User
|
||||
*/
|
||||
public function setTimeframebegin($timeframebegin)
|
||||
{
|
||||
@@ -431,7 +451,7 @@ class User implements UserInterface
|
||||
*
|
||||
* @param string $timeframeend
|
||||
*
|
||||
* @return KimaiUsers
|
||||
* @return User
|
||||
*/
|
||||
public function setTimeframeend($timeframeend)
|
||||
{
|
||||
@@ -455,7 +475,7 @@ class User implements UserInterface
|
||||
*
|
||||
* @param string $apikey
|
||||
*
|
||||
* @return KimaiUsers
|
||||
* @return User
|
||||
*/
|
||||
public function setApikey($apikey)
|
||||
{
|
||||
@@ -474,30 +494,6 @@ class User implements UserInterface
|
||||
return $this->apikey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set globalroleid
|
||||
*
|
||||
* @param integer $globalroleid
|
||||
*
|
||||
* @return KimaiUsers
|
||||
*/
|
||||
public function setGlobalroleid($globalroleid)
|
||||
{
|
||||
$this->globalroleid = $globalroleid;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get globalroleid
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getGlobalroleid()
|
||||
{
|
||||
return $this->globalroleid;
|
||||
}
|
||||
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
@@ -565,8 +561,40 @@ class User implements UserInterface
|
||||
// $this->plainPassword = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $title
|
||||
*/
|
||||
public function setTitle($title)
|
||||
{
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAvatar()
|
||||
{
|
||||
return $this->avatar;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $avatar
|
||||
*/
|
||||
public function setAvatar($avatar)
|
||||
{
|
||||
$this->avatar = $avatar;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->getUsername();
|
||||
return $this->getAlias() ?: $this->getUsername();
|
||||
}
|
||||
}
|
||||
@@ -75,7 +75,7 @@ class MenuBuilder
|
||||
|
||||
if ($isAdmin) {
|
||||
$event->addItem(
|
||||
new MenuItemModel('admin', 'menu.admin_dashboard', '', [], 'fa fa-dashboard')
|
||||
new MenuItemModel('admin', 'menu.admin', '', [], 'fa fa-dashboard')
|
||||
);
|
||||
|
||||
$this->eventDispatcher->dispatch(
|
||||
|
||||
59
src/AppBundle/EventListener/NavbarShowUserListener.php
Normal file
59
src/AppBundle/EventListener/NavbarShowUserListener.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai package.
|
||||
*
|
||||
* (c) Kevin Papst <kevin@kevinpapst.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace AppBundle\EventListener;
|
||||
|
||||
use AppBundle\Entity\User;
|
||||
use Avanzu\AdminThemeBundle\Event\ShowUserEvent;
|
||||
use Avanzu\AdminThemeBundle\Model\UserModel;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
|
||||
/**
|
||||
* Class NavbarShowUserListener
|
||||
*
|
||||
* @author Kevin Papst <kevin@kevinpapst.de>
|
||||
*/
|
||||
class NavbarShowUserListener
|
||||
{
|
||||
/**
|
||||
* @var TokenStorageInterface
|
||||
*/
|
||||
protected $storage;
|
||||
|
||||
public function __construct(TokenStorageInterface $tokenStorage)
|
||||
{
|
||||
$this->storage = $tokenStorage;
|
||||
}
|
||||
|
||||
public function onShowUser(ShowUserEvent $event)
|
||||
{
|
||||
/* @var $myUser User */
|
||||
$myUser = $this->storage->getToken()->getUser();
|
||||
|
||||
$titles = [];
|
||||
$roles = $this->storage->getToken()->getRoles();
|
||||
foreach ($roles as $role) {
|
||||
$titles[] = ucfirst(strtolower(str_replace('ROLE_', '', $role->getRole())));
|
||||
}
|
||||
|
||||
$user = new UserModel();
|
||||
$user->setName($myUser->getAlias() ?: $myUser->getUsername())
|
||||
->setUsername($myUser->getUsername())
|
||||
->setIsOnline(true)
|
||||
->setTitle($myUser->getTitle())
|
||||
->setAvatar($myUser->getAvatar())
|
||||
->setMemberSince(new \DateTime()) // FIXME add column to entity
|
||||
;
|
||||
|
||||
$event->setUser($user);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user