-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
129aeab
commit 9d00baf
Showing
8 changed files
with
244 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace GoalioForgotPasswordDoctrineORM; | ||
|
||
use Doctrine\ORM\Mapping\Driver\XmlDriver; | ||
use ZfcUser\Module as ZfcUser; | ||
|
||
class Module | ||
{ | ||
public function onBootstrap($e) | ||
{ | ||
$app = $e->getParam('application'); | ||
$sm = $app->getServiceManager(); | ||
$options = $sm->get('goalioforgotpassword_module_options'); | ||
|
||
// Add the default entity driver only if specified in configuration | ||
if ($options->getEnableDefaultEntities()) { | ||
$chain = $sm->get('doctrine.driver.orm_default'); | ||
$chain->addDriver(new XmlDriver(__DIR__ . '/config/xml/zfcuserdoctrineorm'), 'ZfcUserDoctrineORM\Entity'); | ||
} | ||
} | ||
|
||
public function getAutoloaderConfig() | ||
{ | ||
return array( | ||
'Zend\Loader\StandardAutoloader' => array( | ||
'namespaces' => array( | ||
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__, | ||
), | ||
), | ||
); | ||
} | ||
|
||
public function getServiceConfig() | ||
{ | ||
return array( | ||
'aliases' => array( | ||
'goalioforgotpassword_doctrine_em' => 'doctrine.entitymanager.orm_default', | ||
|
||
), | ||
'factories' => array( | ||
'goalioforgotpassword_module_options' => function ($sm) { | ||
$config = $sm->get('Config'); | ||
return new Options\ModuleOptions(isset($config['goalioforgotpassword']) ? $config['goalioforgotpassword'] : array()); | ||
}, | ||
'goalioforgotpassword_password_mapper' => function ($sm) { | ||
return new \GoalioForgotPasswordDoctrineORM\Mapper\User( | ||
$sm->get('goalioforgotpassword_doctrine_em'), | ||
$sm->get('goalioforgotpassword_module_options') | ||
); | ||
}, | ||
), | ||
); | ||
} | ||
|
||
public function getConfig() | ||
{ | ||
return include __DIR__ . '/config/module.config.php'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "goalio/goalio-forgotpassword-doctrine-orm", | ||
"description": "Doctrine2 ORM storage adapter for GoalioForgotPassword.", | ||
"type": "library", | ||
"keywords": [ | ||
"zf2" | ||
], | ||
"homepage": "https://github.com/goalio/GoalioForgotPasswordDoctrineORM", | ||
"authors": [ | ||
{ | ||
"name": "Philipp Dobrigkeit", | ||
"email": "[email protected]", | ||
"homepage": "http://www.goalio.de" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.3.3", | ||
"goalio/goalio-forgotpassword": "0.*", | ||
"doctrine/doctrine-orm-module": "0.*" | ||
}, | ||
"autoload": { | ||
"psr-0": { | ||
"GoalioForgotPasswordDoctrineORM": "src/" | ||
}, | ||
"classmap": [ | ||
"./Module.php" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
return array( | ||
'doctrine' => array( | ||
'driver' => array( | ||
'goalioforgotpassword_entity' => array( | ||
'class' => 'Doctrine\ORM\Mapping\Driver\XmlDriver', | ||
'paths' => __DIR__ . '/xml/goalioforgotpassword' | ||
), | ||
|
||
'orm_default' => array( | ||
'drivers' => array( | ||
'GoalioForgotPasswordDoctrineORM\Entity' => 'goalioforgotpassword_entity' | ||
) | ||
) | ||
) | ||
), | ||
); |
17 changes: 17 additions & 0 deletions
17
config/xml/goalioforgotpassword/GoalioForgotPassword.Entity.Password.dcm.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping | ||
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> | ||
|
||
<mapped-superclass name="GoalioForgotPassword\Entity\Password" table="user_password_reset"> | ||
|
||
|
||
<id name="request_key" type="string" length="32" /> | ||
|
||
<field name="userId" type="integer" column="user_id" unique="true" /> | ||
<field name="requestTime" column="request_time" type="datetime" /> | ||
|
||
</mapped-superclass> | ||
|
||
</doctrine-mapping> |
11 changes: 11 additions & 0 deletions
11
...l/goalioforgotpassworddoctrineorm/GoalioForgotPasswordDoctrineORM.Entity.Password.dcm.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping | ||
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> | ||
|
||
<entity name="GoalioForgotPasswordDoctrineORM\Entity\Password" table="user_password_reset"> | ||
|
||
</entity> | ||
|
||
</doctrine-mapping> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace GoalioForgotPasswordDoctrineORM\Entity; | ||
|
||
use GoalioForgotPassword\Entity\Password as GoalioForgotPasswordEntity; | ||
|
||
class Password extends GoalioForgotPasswordEntity | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
namespace GoalioForgotPasswordDoctrineORM\Mapper; | ||
|
||
use Doctrine\ORM\EntityManager; | ||
use GoalioForgotPassword\Mapper\Password as GoalioPasswordMapper; | ||
use GoalioForgotPassword\Options\ModuleOptions; | ||
use Zend\Stdlib\Hydrator\HydratorInterface; | ||
|
||
class Password extends GoalioPasswordMapper | ||
{ | ||
/** | ||
* @var \Doctrine\ORM\EntityManager | ||
*/ | ||
protected $em; | ||
|
||
/** | ||
* @var \GoalioForgotPassword\Options\ModuleOptions | ||
*/ | ||
protected $options; | ||
|
||
public function __construct(EntityManager $em, ModuleOptions $options) | ||
{ | ||
$this->em = $em; | ||
$this->options = $options; | ||
} | ||
|
||
public function remove($passwordModel) | ||
{ | ||
$this->em->remove($passwordModel); | ||
$this->em->flush(); | ||
} | ||
|
||
public function findByUser($userId) | ||
{ | ||
$er = $this->em->getRepository($this->options->getPasswordEntityClass()); | ||
|
||
return $er->findOneBy(array('user' => $userId)); | ||
} | ||
|
||
public function findByUserIdRequestKey($userId, $key) | ||
{ | ||
$er = $this->em->getRepository($this->options->getPasswordEntityClass()); | ||
return $er->findOneBy(array('user' => $userId, 'requestKey' => $key)); | ||
} | ||
|
||
public function cleanExpiredForgotRequests($expiryTime=86400) | ||
{ | ||
|
||
} | ||
|
||
public function cleanPriorForgotRequests($userId) | ||
{ | ||
$dql = sprintf("DELETE %s u WHERE u.user = %s", $this->options->getPasswordEntityClass(), $userId); | ||
$query = $this->em->createQuery($dql); | ||
$query->getResult(); | ||
} | ||
|
||
public function persist($passwordModel) | ||
{ | ||
$this->em->persist($passwordModel); | ||
$this->em->flush(); | ||
|
||
return $passwordModel; | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
src/GoalioForgotPasswordDoctrineORM/Options/ModuleOptions.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace GoalioForgotPasswordDoctrineORM\Options; | ||
|
||
use GoalioForgotPassword\Options\ModuleOptions as BaseModuleOptions; | ||
|
||
class ModuleOptions extends BaseModuleOptions | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $passwordEntityClass = 'GoalioForgotPasswordDoctrineORM\Entity\Password'; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
protected $enableDefaultEntities = true; | ||
|
||
/** | ||
* @param boolean $enableDefaultEntities | ||
*/ | ||
public function setEnableDefaultEntities($enableDefaultEntities) | ||
{ | ||
$this->enableDefaultEntities = $enableDefaultEntities; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return boolean | ||
*/ | ||
public function getEnableDefaultEntities() | ||
{ | ||
return $this->enableDefaultEntities; | ||
} | ||
} |