Permalink
Browse files

Initial work on refactoring

- Cleaned up various whitespace, coding standard, etc issues
- Removed UserMeta
- Removed Repository concept
- Using hydrators
- Switched to using Zend\Crypt\Password
- Converted to OOP-style options strategy
- Not quite working yet -- needs a bit more work
  • Loading branch information...
1 parent dc26512 commit 96516164992aa7d7884f265bb26b24497ad6ad1d @EvanDotPro EvanDotPro committed Jun 26, 2012
Showing with 973 additions and 1,445 deletions.
  1. +34 −55 Module.php
  2. +1 −1 composer.json
  3. +15 −17 config/module.config.php
  4. +1 −16 data/schema.sql
  5. +1 −16 data/schema.sqlite.sql
  6. +51 −56 src/ZfcUser/Authentication/Adapter/Db.php
  7. +10 −10 src/ZfcUser/Authentication/Storage/Db.php
  8. +64 −31 src/ZfcUser/Controller/UserController.php
  9. +141 −0 src/ZfcUser/Entity/User.php
  10. +81 −0 src/ZfcUser/Entity/UserInterface.php
  11. +1 −1 src/ZfcUser/Form/Base.php
  12. +32 −3 src/ZfcUser/Form/Login.php
  13. +4 −4 src/ZfcUser/Form/LoginFilter.php
  14. +45 −17 src/ZfcUser/Form/Register.php
  15. +75 −46 src/ZfcUser/Form/RegisterFilter.php
  16. +18 −40 src/ZfcUser/Mapper/User.php
  17. +51 −0 src/ZfcUser/Mapper/UserHydrator.php
  18. +13 −0 src/ZfcUser/Mapper/UserInterface.php
  19. +0 −112 src/ZfcUser/Mapper/UserMeta.php
  20. +0 −10 src/ZfcUser/Mapper/UserMetaInterface.php
  21. +0 −298 src/ZfcUser/Model/User.php
  22. +0 −191 src/ZfcUser/Model/UserInterface.php
  23. +0 −104 src/ZfcUser/Model/UserMeta.php
  24. +0 −58 src/ZfcUser/Model/UserMetaInterface.php
  25. +10 −0 src/ZfcUser/Options/AuthenticationOptionsInterface.php
  26. +177 −0 src/ZfcUser/Options/ModuleOptions.php
  27. +14 −0 src/ZfcUser/Options/PasswordOptionsInterface.php
  28. +30 −0 src/ZfcUser/Options/RegistrationOptionsInterface.php
  29. +12 −0 src/ZfcUser/Options/UserControllerOptionsInterface.php
  30. +15 −0 src/ZfcUser/Options/UserServiceOptionsInterface.php
  31. +0 −125 src/ZfcUser/Repository/User.php
  32. +0 −13 src/ZfcUser/Repository/UserInterface.php
  33. +47 −109 src/ZfcUser/Service/User.php
  34. +0 −86 src/ZfcUser/Util/Password.php
  35. +19 −19 src/ZfcUser/Validator/AbstractRecord.php
  36. +1 −1 src/ZfcUser/Validator/RecordExists.php
  37. +3 −3 src/ZfcUser/View/Helper/ZfcUserIdentity.php
  38. +7 −3 view/zfc-user/user/register.phtml
View
@@ -8,18 +8,13 @@
Zend\ModuleManager\Feature\ConfigProviderInterface,
Zend\ModuleManager\Feature\ServiceProviderInterface;
-class Module implements
- AutoloaderProviderInterface,
- ConfigProviderInterface,
+class Module implements
+ AutoloaderProviderInterface,
+ ConfigProviderInterface,
ServiceProviderInterface
{
protected static $options;
- public function init(ModuleManager $moduleManager)
- {
- $moduleManager->events()->attach('loadModules.post', array($this, 'modulesLoaded'));
- }
-
public function getAutoloaderConfig()
{
return array(
@@ -49,7 +44,16 @@ public function getServiceConfiguration()
'zfcuser_user_service' => 'ZfcUser\Service\User',
'zfcUserAuthentication' => 'ZfcUser\Controller\Plugin\ZfcUserAuthentication',
),
+ 'aliases' => array(
+ 'zfcUserIdentity' => 'ZfcUser\View\Helper\ZfcUserIdentity',
+ ),
'factories' => array(
+
+ 'zfcuser_module_options' => function ($sm) {
+ $config = $sm->get('Configuration');
+ return new Options\ModuleOptions($config['zfcuser']);
+ },
+
'ZfcUser\View\Helper\ZfcUserIdentity' => function ($sm) {
$viewHelper = new View\Helper\ZfcUserIdentity;
$viewHelper->setAuthService($sm->get('zfcuser_auth_service'));
@@ -61,6 +65,9 @@ public function getServiceConfiguration()
return $viewHelper;
},
+ // We alias this one because it's ZfcUser's instance of
+ // Zend\Authentication\AuthenticationService. We don't want to
+ // hog the FQCN service alias for a Zend\* class.
'zfcuser_auth_service' => function ($sm) {
return new \Zend\Authentication\AuthenticationService(
$sm->get('ZfcUser\Authentication\Storage\Db'),
@@ -77,16 +84,21 @@ public function getServiceConfiguration()
},
'zfcuser_login_form' => function($sm) {
- $form = new \ZfcUser\Form\Login();
- // TODO set hydrator and input filter?
+ $options = $sm->get('zfcuser_module_options');
+ $form = new Form\Login(null, $sm->get('zfcuser_module_options'));
+ $form->setInputFilter(new Form\LoginFilter($options));
return $form;
},
'zfcuser_register_form' => function ($sm) {
- $form = new \ZfcUser\Form\Register();
+ $options = $sm->get('zfcuser_module_options');
+ $form = new Form\Register(null, $options);
//$form->setCaptchaElement($sm->get('zfcuser_captcha_element'));
- $form->setInputFilter($sm->get('ZfcUser\Form\RegisterFilter'));
- $form->setHydrator($sm->get('zfcuser_user_hydrator'));
+ $form->setInputFilter(new Form\RegisterFilter(
+ $sm->get('zfcuser_uemail_validator'),
+ $sm->get('zfcuser_uusername_validator'),
+ $options
+ ));
return $form;
},
@@ -96,48 +108,26 @@ public function getServiceConfiguration()
},
'zfcuser_user_mapper' => function ($sm) {
- $adapter = $sm->get('zfcuser_zend_db_adapter');
- $tg = new \Zend\Db\TableGateway\TableGateway('user', $adapter);
$mapper = new Mapper\User();
- $mapper->setTableGateway($tg);
- return $mapper;
- },
-
- 'zfcuser_user_repository' => function ($sm) {
- $mapper = $sm->get('zfcuser_user_mapper');
- return new Repository\User($mapper);
- },
-
- 'zfcuser_usermeta_mapper' => function ($sm) {
- $adapter = $sm->get('zfcuser_zend_db_adapter');
- $tg = new \Zend\Db\TableGateway\TableGateway('user_meta', $adapter);
- $mapper = new Mapper\UserMeta($tg);
- $mapper->setTableGateway($tg);
+ $mapper->setDbAdapter($sm->get('zfcuser_zend_db_adapter'));
+ $mapper->setEntityPrototype(new Entity\User);
+ $mapper->setHydrator(new Mapper\UserHydrator(false));
return $mapper;
},
'zfcuser_uemail_validator' => function($sm) {
- $repository = $sm->get('zfcuser_user_repository');
- return new \ZfcUser\Validator\NoRecordExists(array(
- 'repository' => $repository,
- 'key' => 'email'
+ return new Validator\NoRecordExists(array(
+ 'mapper' => $sm->get('zfcuser_user_mapper'),
+ 'key' => 'email'
));
},
'zfcuser_uusername_validator' => function($sm) {
- $repository = $sm->get('zfcuser_user_repository');
- return new \ZfcUser\Validator\NoRecordExists(array(
- 'repository' => $repository,
- 'key' => 'username'
+ return new Validator\NoRecordExists(array(
+ 'mapper' => $sm->get('zfcuser_user_mapper'),
+ 'key' => 'username'
));
},
-
- 'ZfcUser\Form\RegisterFilter' => function($sm) {
- return new \ZfcUser\Form\RegisterFilter(
- $sm->get('zfcuser_uemail_validator'),
- $sm->get('zfcuser_uusername_validator')
- );
- },
),
);
}
@@ -157,15 +147,4 @@ public function modulesLoaded($e)
static::$options['auth_identity_fields'] = array_unique(static::$options['auth_identity_fields']);
}
-
- /**
- * @TODO: Come up with a better way of handling module settings/options
- */
- public static function getOption($option)
- {
- if (!isset(static::$options[$option])) {
- return null;
- }
- return static::$options[$option];
- }
}
View
@@ -21,7 +21,7 @@
"require": {
"php": ">=5.3.3",
"zendframework/zendframework": "dev-master",
- "zf-commons/zfc-base": "dev-master"
+ "zf-commons/zfc-base": "dev-master"
},
"autoload": {
"psr-0": {
@@ -1,33 +1,31 @@
<?php
return array(
'zfcuser' => array(
- 'user_model_class' => 'ZfcUser\Model\User',
- 'usermeta_model_class' => 'ZfcUser\Model\UserMeta',
- 'enable_registration' => true,
+ //'user_entity_class' => 'ZfcUser\Entity\User',
+ //'enable_registration' => true,
//NOTE: Please override the setting below via your zfcuser.global.php file
// Uncommenting the line below will break any overrides in later config files
// due to the way config file merging works with array values
//'auth_identity_fields' => array( 'email' ),
- 'enable_username' => false,
- 'enable_display_name' => false,
- 'require_activation' => false,
- 'login_after_registration' => true,
- 'registration_form_captcha' => true,
- 'password_hash_algorithm' => 'blowfish', // blowfish, sha512, sha256
- 'blowfish_cost' => 10, // integer between 4 and 31
- 'sha256_rounds' => 5000, // integer between 1000 and 999,999,999
- 'sha512_rounds' => 5000, // integer between 1000 and 999,999,999
+ //'enable_username' => false,
+ //'enable_display_name' => false,
+ //'require_activation' => false,
+ //'login_after_registration' => true,
+ //'registration_form_captcha' => true,
+ //'password_hash_algorithm' => 'blowfish', // blowfish, sha512, sha256
+ //'blowfish_cost' => 10, // integer between 4 and 31
+ //'sha256_rounds' => 5000, // integer between 1000 and 999,999,999
+ //'sha512_rounds' => 5000, // integer between 1000 and 999,999,999
),
'view_manager' => array(
'template_path_stack' => array(
'zfcuser' => __DIR__ . '/../view',
),
- 'helper_map' => array(
- 'Zend\Form\View\HelperLoader',
- 'zfcUserIdentity' => 'ZfcUser\View\Helper\ZfcUserIdentity',
- 'zfcUserLoginWidget' => 'ZfcUser\View\Helper\ZfcUserLoginWidget',
- ),
+ //'helper_map' => array(
+ // 'zfcUserIdentity' => 'ZfcUser\View\Helper\ZfcUserIdentity',
+ // 'zfcUserLoginWidget' => 'ZfcUser\View\Helper\ZfcUserLoginWidget',
+ //),
),
'controller' => array(
View
@@ -4,20 +4,5 @@ CREATE TABLE user
username VARCHAR(255) DEFAULT NULL UNIQUE,
email VARCHAR(255) NOT NULL UNIQUE,
display_name VARCHAR(50) DEFAULT NULL,
- password VARCHAR(128) NOT NULL,
- last_login DATETIME DEFAULT NULL,
- last_ip INTEGER DEFAULT NULL,
- register_time DATETIME NOT NULL,
- register_ip INTEGER NOT NULL,
- active TINYINT(1) NOT NULL,
- enabled TINYINT(1) NOT NULL
-) ENGINE=InnoDB;
-
-CREATE TABLE user_meta
-(
- meta_key VARCHAR(255) NOT NULL,
- user_id INTEGER NOT NULL,
- meta LONGTEXT NOT NULL,
- PRIMARY KEY(meta_key, user_id),
- FOREIGN KEY (user_id) REFERENCES user (user_id)
+ password VARCHAR(128) NOT NULL
) ENGINE=InnoDB;
@@ -4,20 +4,5 @@ CREATE TABLE user
username VARCHAR(255) DEFAULT NULL UNIQUE,
email VARCHAR(255) NOT NULL UNIQUE,
display_name VARCHAR(50) DEFAULT NULL,
- password VARCHAR(128) NOT NULL,
- last_login DATETIME DEFAULT NULL,
- last_ip INTEGER DEFAULT NULL,
- register_time DATETIME NOT NULL,
- register_ip INTEGER NOT NULL,
- active TINYINT(1) NOT NULL,
- enabled TINYINT(1) NOT NULL
-);
-
-CREATE TABLE user_meta
-(
- meta_key VARCHAR(255) NOT NULL,
- user_id INTEGER NOT NULL,
- meta LONGTEXT NOT NULL,
- PRIMARY KEY(meta_key, user_id),
- FOREIGN KEY (user_id) REFERENCES user (user_id)
+ password VARCHAR(128) NOT NULL
);
Oops, something went wrong.

0 comments on commit 9651616

Please sign in to comment.