Skip to content

Commit

Permalink
Add extra user fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Rabaix committed Jun 5, 2012
1 parent ea102a7 commit 3f8e91e
Show file tree
Hide file tree
Showing 20 changed files with 2,554 additions and 265 deletions.
12 changes: 0 additions & 12 deletions Admin/Entity/UserAdmin.php
Expand Up @@ -16,17 +16,5 @@

class UserAdmin extends BaseUserAdmin
{
/**
* {@inheritdoc}
*/
protected function configureFormFields(FormMapper $formMapper)
{
parent::configureFormFields($formMapper);

$formMapper
->with('Management')
->add('credentialsExpired', null, array('required' => false))
->end()
;
}
}
75 changes: 72 additions & 3 deletions Admin/Model/UserAdmin.php
Expand Up @@ -15,6 +15,7 @@
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Show\ShowMapper;

use FOS\UserBundle\Model\UserManagerInterface;

Expand Down Expand Up @@ -59,6 +60,45 @@ protected function configureDatagridFilters(DatagridMapper $filterMapper)
;
}

/**
* {@inheritdoc}
*/
protected function configureShowFields(ShowMapper $showMapper)
{
$showMapper
->with('General')
->add('username')
->add('email')
->end()
->with('Groups')
->add('groups')
->end()
->with('Profile')
->add('dateOfBirth', 'date')
->add('firstname')
->add('lastname')
->add('website')
->add('biography')
->add('gender')
->add('locale')
->add('timezone')
->add('phone')
->end()
->with('Social')
->add('facebookUid')
->add('facebookName')
->add('twitterUid')
->add('twitterName')
->add('gplusUid')
->add('gplusName')
->end()
->with('Security')
->add('token')
->add('twoStepVerificationCode')
->end();
;
}

/**
* {@inheritdoc}
*/
Expand All @@ -73,7 +113,29 @@ protected function configureFormFields(FormMapper $formMapper)
->with('Groups')
->add('groups', 'sonata_type_model', array('required' => false))
->end()
->with('Management')
->with('Profile')
->add('dateOfBirth', 'date', array('required' => false))
->add('firstname', null, array('required' => false))
->add('lastname', null, array('required' => false))
->add('website', 'url', array('required' => false))
->add('biography', 'text', array('required' => false))
->add('gender', null, array('required' => false))
->add('locale', null, array('required' => false))
->add('timezone', null, array('required' => false))
->add('phone', null, array('required' => false))
->end()
->with('Social')
->add('facebookUid', null, array('required' => false))
->add('facebookName', null, array('required' => false))
->add('twitterUid', null, array('required' => false))
->add('twitterName', null, array('required' => false))
->add('gplusUid', null, array('required' => false))
->add('gplusName', null, array('required' => false))
->end()
;

if (!$this->getSubject()->hasRole('ROLE_SUPER_ADMIN')) {
$formMapper->with('Management')
->add('roles', 'sonata_security_roles', array(
'expanded' => true,
'multiple' => true,
Expand All @@ -82,8 +144,15 @@ protected function configureFormFields(FormMapper $formMapper)
->add('locked', null, array('required' => false))
->add('expired', null, array('required' => false))
->add('enabled', null, array('required' => false))
->end()
;
->add('credentialsExpired', null, array('required' => false))
->end();
}

$formMapper
->with('Security')
->add('token', null, array('required' => false))
->add('twoStepVerificationCode', null, array('required' => false))
->end();
}

/**
Expand Down
119 changes: 1 addition & 118 deletions Document/BaseUser.php
Expand Up @@ -11,89 +11,14 @@

namespace Sonata\UserBundle\Document;

use FOS\UserBundle\Document\User as AbstractedUser;
use Sonata\UserBundle\Model\User as AbstractedUser;
use Sonata\UserBundle\Model\UserInterface;

/**
* Represents a Base User Document
*/
class BaseUser extends AbstractedUser implements UserInterface
{
/**
* @var \DateTime
*/
protected $createdAt;

/**
* @var \DateTime
*/
protected $updatedAt;

/**
* @var string
*/
protected $twoStepVerificationCode;

/**
* Sets the creation date
*
* @param \DateTime|null $createdAt
*/
public function setCreatedAt(\DateTime $createdAt = null)
{
$this->createdAt = $createdAt;
}

/**
* Returns the creation date
*
* @return \DateTime|null
*/
public function getCreatedAt()
{
return $this->createdAt;
}

/**
* Sets the last update date
*
* @param \DateTime|null $updatedAt
*/
public function setUpdatedAt(\DateTime $updatedAt = null)
{
$this->updatedAt = $updatedAt;
}

/**
* Returns the last update date
*
* @return \DateTime|null
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}

/**
* Returns the credentials expiration date
*
* @return \DateTime
*/
public function getCredentialsExpireAt()
{
return $this->credentialsExpireAt;
}

/**
* Sets the credentials expiration date
*
* @param \DateTime|null $date
*/
public function setCredentialsExpireAt(\DateTime $date = null)
{
$this->credentialsExpireAt = $date;
}

/**
* Hook on pre-persist operations
*/
Expand All @@ -110,46 +35,4 @@ public function preUpdate()
{
$this->updatedAt = new \DateTime;
}

/**
* Returns a string representation
*
* @return string
*/
public function __toString()
{
return $this->getUsername() ?: '-';
}

/**
* Sets the user groups
*
* @param array $groups
*/
public function setGroups($groups)
{
foreach ($groups as $group) {
$this->addGroup($group);
}
}

/**
* Sets the two-step verification code
*
* @param string $twoStepVerificationCode
*/
public function setTwoStepVerificationCode($twoStepVerificationCode)
{
$this->twoStepVerificationCode = $twoStepVerificationCode;
}

/**
* Returns the two-step verification code
*
* @return string
*/
public function getTwoStepVerificationCode()
{
return $this->twoStepVerificationCode;
}
}

2 comments on commit 3f8e91e

@gimler
Copy link
Contributor

@gimler gimler commented on 3f8e91e Jul 26, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you add this fields? The fields are not included in FOSUserBundle.

@rande
Copy link
Member

@rande rande commented on 3f8e91e Jul 26, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it is only basic fields for an user. The purpose on the SonataUserBundle is to add more feature on top of the FOSUserBundle.

If you don't need all these fields, you can create your on User class, and configure the bundle to use your class.

Please sign in to comment.