Skip to content

Commit

Permalink
added new config to change pw length, its important for different games
Browse files Browse the repository at this point in the history
added option classes
little service optimize
  • Loading branch information
kokspflanze committed May 29, 2015
1 parent 7e128c8 commit d654fc7
Show file tree
Hide file tree
Showing 17 changed files with 349 additions and 82 deletions.
9 changes: 8 additions & 1 deletion config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,18 @@
/*
* set other pw for web as ingame
*/
'different-passwords' => true,
'different_passwords' => true,
/**
* work with secret pw system, there is atm no admin view to handle the question =[
*/
'secret_question' => false,
/**
* some games does not allowed so long password
*/
'length' => [
'min' => 6,
'max' => 32
],
],
'news' => [
/**
Expand Down
53 changes: 46 additions & 7 deletions src/PServerCMS/Form/ChangePwdFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,22 @@
namespace PServerCMS\Form;

use ZfcBase\InputFilter\ProvidesEventsInputFilter;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\ServiceManager\ServiceManager;

class ChangePwdFilter extends ProvidesEventsInputFilter
{
protected $serviceManager;

public function __construct()
/**
* @param ServiceLocatorInterface $serviceLocatorInterface
*/
public function __construct( ServiceLocatorInterface $serviceLocatorInterface )
{
$this->setServiceManager($serviceLocatorInterface);

$passwordLengthOptions = $this->getPasswordOptions()->getLength();

$this->add(array(
'name' => 'currentPassword',
'required' => true,
Expand All @@ -17,12 +27,13 @@ public function __construct()
array(
'name' => 'StringLength',
'options' => array(
'min' => 6,
'max' => 32,
'min' => $passwordLengthOptions['min'],
'max' => $passwordLengthOptions['max'],
),
),
),
));

$this->add(array(
'name' => 'password',
'required' => true,
Expand All @@ -31,8 +42,8 @@ public function __construct()
array(
'name' => 'StringLength',
'options' => array(
'min' => 6,
'max' => 32,
'min' => $passwordLengthOptions['min'],
'max' => $passwordLengthOptions['max'],
),
),
),
Expand All @@ -46,8 +57,8 @@ public function __construct()
array(
'name' => 'StringLength',
'options' => array(
'min' => 6,
'max' => 32,
'min' => $passwordLengthOptions['min'],
'max' => $passwordLengthOptions['max'],
),
),
array(
Expand All @@ -59,4 +70,32 @@ public function __construct()
),
));
}

/**
* @param ServiceManager $oServiceManager
*
* @return $this
*/
public function setServiceManager( ServiceManager $oServiceManager )
{
$this->serviceManager = $oServiceManager;

return $this;
}

/**
* @return ServiceManager
*/
protected function getServiceManager()
{
return $this->serviceManager;
}

/**
* @return \PServerCMS\Options\PasswordOptions
*/
protected function getPasswordOptions()
{
return $this->getServiceManager()->get('pserver_password_options');
}
}
45 changes: 39 additions & 6 deletions src/PServerCMS/Form/PasswordFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,33 @@
use ZfcBase\InputFilter\ProvidesEventsInputFilter;
use Zend\ServiceManager\ServiceLocatorInterface;
use PServerCMS\Validator\SimilarText;
use Zend\ServiceManager\ServiceManager;

class PasswordFilter extends ProvidesEventsInputFilter
{
/** @var \PServerCMS\Validator\SimilarText */
protected $similarText;
/** @var User */
protected $user;
protected $serviceManager;

/**
* @param ServiceLocatorInterface $serviceLocatorInterface
*/
public function __construct( ServiceLocatorInterface $serviceLocatorInterface )
{
$this->setServiceManager($serviceLocatorInterface);

/** @var \PServerCMS\Service\ConfigRead $configService */
$configService = $serviceLocatorInterface->get( 'pserver_configread_service' );
$configService = $this->getServiceManager()->get( 'pserver_configread_service' );
if($configService->get('pserver.password.secret_question')) {
$secretQuestion = $serviceLocatorInterface->get( 'pserver_secret_question' );
$secretQuestion = $this->getServiceManager()->get( 'pserver_secret_question' );
$similarText = new \PServerCMS\Validator\SimilarText( $secretQuestion );
$this->setSimilarText( $similarText );
}

$passwordLengthOptions = $this->getPasswordOptions()->getLength();

$this->add(array(
'name' => 'password',
'required' => true,
Expand All @@ -35,8 +41,8 @@ public function __construct( ServiceLocatorInterface $serviceLocatorInterface )
array(
'name' => 'StringLength',
'options' => array(
'min' => 6,
'max' => 32,
'min' => $passwordLengthOptions['min'],
'max' => $passwordLengthOptions['max'],
),
),
),
Expand All @@ -50,8 +56,8 @@ public function __construct( ServiceLocatorInterface $serviceLocatorInterface )
array(
'name' => 'StringLength',
'options' => array(
'min' => 6,
'max' => 32,
'min' => $passwordLengthOptions['min'],
'max' => $passwordLengthOptions['max'],
),
),
array(
Expand All @@ -64,6 +70,26 @@ public function __construct( ServiceLocatorInterface $serviceLocatorInterface )
));
}

/**
* @param ServiceManager $oServiceManager
*
* @return $this
*/
public function setServiceManager( ServiceManager $oServiceManager )
{
$this->serviceManager = $oServiceManager;

return $this;
}

/**
* @return ServiceManager
*/
protected function getServiceManager()
{
return $this->serviceManager;
}

/**
* @param User $user
*/
Expand Down Expand Up @@ -102,4 +128,11 @@ protected function getSimilarText()
return $this->similarText;
}

/**
* @return \PServerCMS\Options\PasswordOptions
*/
protected function getPasswordOptions()
{
return $this->getServiceManager()->get('pserver_password_options');
}
}
30 changes: 20 additions & 10 deletions src/PServerCMS/Form/RegisterFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public function __construct( ServiceManager $serviceManager )
),
));

$passwordLengthOptions = $this->getPasswordOptions()->getLength();

$this->add(array(
'name' => 'password',
'required' => true,
Expand All @@ -85,8 +87,8 @@ public function __construct( ServiceManager $serviceManager )
array(
'name' => 'StringLength',
'options' => array(
'min' => 6,
'max' => 32,
'min' => $passwordLengthOptions['min'],
'max' => $passwordLengthOptions['max'],
),
),
),
Expand All @@ -100,8 +102,8 @@ public function __construct( ServiceManager $serviceManager )
array(
'name' => 'StringLength',
'options' => array(
'min' => 6,
'max' => 32,
'min' => $passwordLengthOptions['min'],
'max' => $passwordLengthOptions['max'],
),
),
array(
Expand Down Expand Up @@ -224,11 +226,19 @@ protected function getEntityManager()
return $this->entityManager;
}

/**
* @return \PServerCMS\Options\EntityOptions
*/
protected function getEntityOptions()
/**
* @return \PServerCMS\Options\EntityOptions
*/
protected function getEntityOptions()
{
return $this->getServiceManager()->get('pserver_entity_options');
}
return $this->getServiceManager()->get('pserver_entity_options');
}

/**
* @return \PServerCMS\Options\PasswordOptions
*/
protected function getPasswordOptions()
{
return $this->getServiceManager()->get('pserver_password_options');
}
}
14 changes: 12 additions & 2 deletions src/PServerCMS/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ public function getServiceConfig()
);
return $form;
},
'pserver_user_changepwd_form' => function () {
'pserver_user_changepwd_form' => function ( $sm ) {
$form = new Form\ChangePwd();
$form->setInputFilter( new Form\ChangePwdFilter() );
$form->setInputFilter( new Form\ChangePwdFilter($sm) );
return $form;
},
'pserver_entity_options' => function ( $sm ) {
Expand All @@ -134,6 +134,16 @@ public function getServiceConfig()
$config = $sm->get( 'Configuration' );
return new Options\MailOptions( $config['pserver']['mail'] );
},
'pserver_general_options' => function ( $sm ) {
/** @var $sm \Zend\ServiceManager\ServiceLocatorInterface */
$config = $sm->get( 'Configuration' );
return new Options\GeneralOptions( $config['pserver']['general'] );
},
'pserver_password_options' => function ( $sm ) {
/** @var $sm \Zend\ServiceManager\ServiceLocatorInterface */
$config = $sm->get( 'Configuration' );
return new Options\PasswordOptions( $config['pserver']['password'] );
},
'zfcticketsystem_ticketsystem_new_form' => function ( $sm ) {
/** @var $sm \Zend\ServiceManager\ServiceLocatorInterface */
$form = new \ZfcTicketSystem\Form\TicketSystem( $sm );
Expand Down
67 changes: 67 additions & 0 deletions src/PServerCMS/Options/GeneralOptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php


namespace PServerCMS\Options;

use Zend\Stdlib\AbstractOptions;

class GeneralOptions extends AbstractOptions
{
protected $__strictMode__ = false;

/**
* @var array
*/
protected $datetime = [
'format' => [
'time' => 'Y-m-d H:i'
],
];

/**
* @var array
*/
protected $cache = [
'enable' => false
];

/**
* @return array
*/
public function getDatetime()
{
return $this->datetime;
}

/**
* @param array $datetime
* @return GeneralOptions
*/
public function setDatetime( array $datetime )
{
$this->datetime = $datetime;

return $this;
}

/**
* @return array
*/
public function getCache()
{
return $this->cache;
}

/**
* @param array $cache
* @return GeneralOptions
*/
public function setCache( array $cache )
{
$this->cache = $cache;

return $this;
}


}
Loading

0 comments on commit d654fc7

Please sign in to comment.