-
Notifications
You must be signed in to change notification settings - Fork 7
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
Showing
12 changed files
with
198 additions
and
89 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
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
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
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
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
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,75 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Venne:CMS (https://github.com/Venne) | ||
* | ||
* Copyright (c) 2011, 2012 Josef Kříž (http://www.josef-kriz.cz) | ||
* | ||
* For the full copyright and license information, please view | ||
* the file license.txt that was distributed with this source code. | ||
*/ | ||
|
||
namespace Venne\Security\DefaultType\Mapping; | ||
|
||
use Doctrine\ORM\Mapping\ClassMetadata; | ||
use Kdyby\DoctrineForms\EntityFormMapper; | ||
use Nette\ComponentModel\Component; | ||
use Venne\Security\User; | ||
|
||
/** | ||
* @author Josef Kříž <[email protected]> | ||
*/ | ||
class PasswordContainer extends \Nette\Object implements \Kdyby\DoctrineForms\IComponentMapper | ||
{ | ||
|
||
/** @var \Kdyby\DoctrineForms\EntityFormMapper */ | ||
private $mapper; | ||
|
||
public function setEntityFormMapper(EntityFormMapper $mapper) | ||
{ | ||
$this->mapper = $mapper; | ||
} | ||
|
||
/** | ||
* @param ClassMetadata $meta | ||
* @param Component $component | ||
* @param object $entity | ||
* @return boolean | ||
*/ | ||
public function load(ClassMetadata $meta, Component $component, $entity) | ||
{ | ||
if (!$component instanceof \Venne\Security\DefaultType\PasswordContainer) { | ||
return false; | ||
} | ||
|
||
if (!$entity instanceof User) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* @param ClassMetadata $meta | ||
* @param Component $component | ||
* @param object $entity | ||
* @return boolean | ||
*/ | ||
public function save(ClassMetadata $meta, Component $component, $entity) | ||
{ | ||
if (!$component instanceof \Venne\Security\DefaultType\PasswordContainer) { | ||
return false; | ||
} | ||
|
||
if (!$entity instanceof User) { | ||
return false; | ||
} | ||
|
||
if ($component->isPasswordSet()) { | ||
$entity->setPassword($component->getValue()); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
} |
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,70 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Venne:CMS (https://github.com/Venne) | ||
* | ||
* Copyright (c) 2011, 2012 Josef Kříž (http://www.josef-kriz.cz) | ||
* | ||
* For the full copyright and license information, please view | ||
* the file license.txt that was distributed with this source code. | ||
*/ | ||
|
||
namespace Venne\Security\DefaultType; | ||
|
||
use Nette\Forms\Form; | ||
|
||
/** | ||
* @author Josef Kříž <[email protected]> | ||
*/ | ||
class PasswordContainer extends \Nette\Forms\Container | ||
{ | ||
|
||
/** @var boolean */ | ||
private $forceChangePassword; | ||
|
||
public function __construct($forceChangePassword = false) | ||
{ | ||
$this->monitor(Form::class); | ||
$this->forceChangePassword = $forceChangePassword; | ||
} | ||
|
||
protected function attached($obj) | ||
{ | ||
parent::attached($obj); | ||
|
||
$form = $this->getForm(); | ||
|
||
$this->setCurrentGroup($form->addGroup()); | ||
|
||
if (!$this->forceChangePassword) { | ||
$passwordNew = $this->addCheckbox('password_new', 'Change password'); | ||
$passwordNew->addCondition($form::EQUAL, true)->toggle('setPasswd'); | ||
} | ||
|
||
$this->setCurrentGroup($form->addGroup()->setOption('container', 'fieldset id=setPasswd')); | ||
$this->addPassword('password_set', 'Password') | ||
->addConditionOn($passwordNew, Form::FILLED) | ||
->addRule(Form::FILLED, 'Enter password') | ||
->addRule(Form::MIN_LENGTH, 'Password is short', 5); | ||
$this->addPassword('password_confirm', 'Confirm password') | ||
->addConditionOn($passwordNew, Form::FILLED) | ||
->addRule(Form::EQUAL, 'Invalid re password', $this['password_set']); | ||
} | ||
|
||
/** | ||
* @return boolean | ||
*/ | ||
public function isPasswordSet() | ||
{ | ||
return $this->forceChangePassword || (boolean) $this['password_new']->getValue(); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getValue() | ||
{ | ||
return $this['password_set']->getValue(); | ||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -12,15 +12,12 @@ | |
namespace Venne\Security\DefaultType; | ||
|
||
use Nette\Forms\Form; | ||
use Nette\Utils\Random; | ||
use Venne\Forms\IFormFactory; | ||
use Venne\Security\ILoginProvider; | ||
use Venne\Security\IRegistrationForm; | ||
|
||
/** | ||
* @author Josef Kříž <[email protected]> | ||
*/ | ||
class RegistrationFormFactory extends \Nette\Object implements IRegistrationForm, IFormFactory | ||
class RegistrationFormFactory extends \Nette\Object implements IFormFactory | ||
{ | ||
|
||
/** @var \Venne\Forms\IFormFactory */ | ||
|
@@ -43,25 +40,9 @@ public function create() | |
$user->addText('email', 'E-mail') | ||
->addRule(Form::EMAIL, 'Enter email'); | ||
|
||
$user->addPassword('password', 'Password') | ||
->addRule(Form::FILLED, 'Enter password') | ||
->addRule(Form::MIN_LENGTH, 'Password is short', 5); | ||
$user->addPassword('password_confirm', 'Confirm password') | ||
->addRule(Form::EQUAL, 'Invalid re password', $user['password']); | ||
$user['password'] = new PasswordContainer(); | ||
|
||
return $form; | ||
} | ||
|
||
/** | ||
* @param Form $form | ||
* @param ILoginProvider $loginProvider | ||
*/ | ||
public function connectWithLoginProvider(Form $form, ILoginProvider $loginProvider) | ||
{ | ||
$loginProviderEntity = $loginProvider->getLoginProviderEntity(); | ||
|
||
$form['user']['email']->setValue($loginProviderEntity->email); | ||
$form['user']['password_confirm']->value = $form['user']['password']->value = Random::generate(); | ||
} | ||
|
||
} |
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
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.