Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pdobrigkeit committed Feb 18, 2013
1 parent 129aeab commit 9d00baf
Show file tree
Hide file tree
Showing 8 changed files with 244 additions and 0 deletions.
60 changes: 60 additions & 0 deletions Module.php
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';
}
}
29 changes: 29 additions & 0 deletions composer.json
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"
]
}
}
17 changes: 17 additions & 0 deletions config/module.config.php
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'
)
)
)
),
);
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>
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>
8 changes: 8 additions & 0 deletions src/GoalioForgotPasswordDoctrineORM/Entity/Password.php
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
{}
67 changes: 67 additions & 0 deletions src/GoalioForgotPasswordDoctrineORM/Mapper/Password.php
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 src/GoalioForgotPasswordDoctrineORM/Options/ModuleOptions.php
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;
}
}

0 comments on commit 9d00baf

Please sign in to comment.