Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add PasswordApi #3289

Merged
merged 14 commits into from
Dec 12, 2016
1 change: 1 addition & 0 deletions CHANGELOG-1.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ CHANGELOG - ZIKULA 1.4.x
- Fetch Webshim (vendor) using composer (#3271, #3262).
- Removed custom JS compression from Jenkins build in favor of AssetMerger service (#3272, #3250).
- Template overrides are also considered in sub requests (e.g. embedding a Formicula form into a Content page) (#3234).
- Implement PasswordApi in ZAuthModule (#3175, #3289)

- Vendor updates:
- afarkas/webshim installed at 1.16.0
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"vierbergenlars/php-semver": "~3.0",
"zikula/wizard": "dev-master",
"zikula/filesystem": "dev-master",
"ircmaxell/random-lib": "1.*",


"zikula/jquery-bundle": "dev-master",
Expand Down
105 changes: 103 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions src/docs/Core-2.0/Api/PasswordApi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
PasswordApi
===========

classname: \Zikula\ZAuthModule\Api\PasswordApi

service id="zikula_zauth_module.api.password"

This class is used to manage passwords.

The class makes the following methods available:

- getHashedPassword($unhashedPassword, $hashMethodCode = self::DEFAULT_HASH_METHOD_CODE)
- generatePassword($length = self::MIN_LENGTH)
- passwordsMatch($unhashedPassword, $hashedPassword)

The class is fully tested.
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ private function updateAdmin()
$mapping->setUname($userEntity->getUname());
$mapping->setEmail($userEntity->getEmail());
$mapping->setVerifiedEmail(true);
$mapping->setPass(\UserUtil::getHashedPassword($params['password'], \UserUtil::getPasswordHashMethodCode(ZAuthConstant::DEFAULT_HASH_METHOD))); // @todo
$mapping->setPass($this->container->get('zikula_zauth_module.api.password')->getHashedPassword($params['password']));
$mapping->setMethod(ZAuthConstant::AUTHENTICATION_METHOD_UNAME);
$entityManager->persist($mapping);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ services:

zikula_core_installer_bundle.validator.constraints.authenticate_admin_login_validator:
class: %zikula_core_installer_bundle.validator.constraints.authenticate_admin_login_validator.class%
arguments: ["@zikula_permissions_module.api.permission", "@doctrine.dbal.default_connection", "@translator.default"]
arguments:
- "@zikula_permissions_module.api.permission"
- "@doctrine.dbal.default_connection"
- "@translator.default"
- "@zikula_zauth_module.api.password"
tags:
- { name: validator.constraint_validator, alias: zikula.core_installer.authenticate_admin_login.validator }
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Zikula\Common\Translator\TranslatorInterface;
use Zikula\Common\Translator\TranslatorTrait;
use Zikula\PermissionsModule\Api\PermissionApi;
use Zikula\ZAuthModule\Api\PasswordApi;

class AuthenticateAdminLoginValidator extends ConstraintValidator
{
Expand All @@ -32,17 +33,24 @@ class AuthenticateAdminLoginValidator extends ConstraintValidator
*/
private $databaseConnection;

/**
* @var PasswordApi
*/
private $passwordApi;

/**
* AuthenticateAdminLoginValidator constructor.
* @param PermissionApi $permissionApi
* @param Connection $connection
* @param TranslatorInterface $translator
* @param PasswordApi $passwordApi
*/
public function __construct(PermissionApi $permissionApi, Connection $connection, TranslatorInterface $translator)
public function __construct(PermissionApi $permissionApi, Connection $connection, TranslatorInterface $translator, PasswordApi $passwordApi)
{
$this->permissionApi = $permissionApi;
$this->databaseConnection = $connection;
$this->setTranslator($translator);
$this->passwordApi = $passwordApi;
}

public function setTranslator($translator)
Expand All @@ -68,7 +76,7 @@ public function validate($object, Constraint $constraint)
;
}

if (empty($user) || ($user['uid'] <= 1) || (!\UserUtil::passwordsMatch($object['password'], $user['pass']))) { // @todo
if (empty($user) || ($user['uid'] <= 1) || (!$this->passwordApi->passwordsMatch($object['password'], $user['pass']))) {
$this->context->buildViolation($this->__('Error! Could not login with provided credentials. Please try again.'))
->addViolation();
} else {
Expand Down
Loading