Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions .github/phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,6 @@ parameters:
count: 1
path: ../app/code/core/Mage/Admin/Model/Session.php

-
message: "#^Call to an undefined method Mage_Core_Helper_Abstract\\:\\:getHash\\(\\)\\.$#"
count: 1
path: ../app/code/core/Mage/Admin/Model/User.php

-
message: "#^Call to an undefined method Mage_Core_Helper_Abstract\\:\\:validateHash\\(\\)\\.$#"
count: 1
path: ../app/code/core/Mage/Admin/Model/User.php

-
message: "#^Call to an undefined method Varien_Data_Collection\\:\\:addFieldToFilter\\(\\)\\.$#"
count: 2
Expand Down Expand Up @@ -1955,11 +1945,6 @@ parameters:
count: 1
path: ../app/code/core/Mage/Api/Model/Server/Wsi/Adapter/Soap.php

-
message: "#^Call to an undefined method Mage_Core_Helper_Abstract\\:\\:getHash\\(\\)\\.$#"
count: 1
path: ../app/code/core/Mage/Api/Model/User.php

-
message: "#^Call to an undefined method SimpleXMLElement\\:\\:extendChild\\(\\)\\.$#"
count: 1
Expand Down
41 changes: 23 additions & 18 deletions app/code/core/Mage/Admin/Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
* @method string getNewPassword()
* @method $this setNewPassword(string $value)
* @method $this unsNewPassword()
* @method bool hasPassword()
* @method bool hasPasswordConfirmation()
* @method string getPasswordConfirmation()
* @method $this setPasswordConfirmation(string $value)
Expand Down Expand Up @@ -203,7 +204,7 @@ protected function getSession()
/**
* Save admin user extra data (like configuration sections state)
*
* @param array $data
* @param array|string $data
* @return $this
*/
public function saveExtra($data)
Expand All @@ -219,6 +220,7 @@ public function saveExtra($data)
* Save user roles
*
* @return $this
* @throws Mage_Core_Exception
*/
public function saveRelations()
{
Expand Down Expand Up @@ -425,9 +427,10 @@ public function authenticate($username, $password)
/**
* Login user
*
* @param string $username
* @param string $password
* @param string $username
* @param string $password
* @return $this
* @throws Mage_Core_Exception
*/
public function login($username, $password)
{
Expand All @@ -450,7 +453,7 @@ public function reload()
$this->setId(null);
$this->load($id);
$isUserPasswordChanged = $this->getSession()->getUserPasswordChanged();
if ($this->getPassword() !== $oldPassword && !$isUserPasswordChanged) {
if (!$isUserPasswordChanged && $this->getPassword() !== $oldPassword) {
$this->setId(null);
} elseif ($isUserPasswordChanged) {
$this->getSession()->setUserPasswordChanged(false);
Expand Down Expand Up @@ -489,7 +492,7 @@ public function hasAssigned2Role($user)
*/
protected function _getEncodedPassword($password)
{
return $this->_getHelper('core')->getHash($password, self::HASH_SALT_LENGTH);
return Mage::helper('core')->getHash($password, self::HASH_SALT_LENGTH);
}

/**
Expand Down Expand Up @@ -576,26 +579,27 @@ public function getStartupPageUrl()
* Validate user attribute values.
* Returns TRUE or array of errors.
*
* @return mixed
* @return array|true
* @throws Zend_Validate_Exception
*/
public function validate()
{
$errors = new ArrayObject();

if (!Zend_Validate::is($this->getUsername(), 'NotEmpty')) {
$errors[] = Mage::helper('adminhtml')->__('User Name is required field.');
$errors->append(Mage::helper('adminhtml')->__('User Name is required field.'));
}

if (!Zend_Validate::is($this->getFirstname(), 'NotEmpty')) {
$errors[] = Mage::helper('adminhtml')->__('First Name is required field.');
$errors->append(Mage::helper('adminhtml')->__('First Name is required field.'));
}

if (!Zend_Validate::is($this->getLastname(), 'NotEmpty')) {
$errors[] = Mage::helper('adminhtml')->__('Last Name is required field.');
$errors->append(Mage::helper('adminhtml')->__('Last Name is required field.'));
}

if (!Zend_Validate::is($this->getEmail(), 'EmailAddress')) {
$errors[] = Mage::helper('adminhtml')->__('Please enter a valid email.');
$errors->append(Mage::helper('adminhtml')->__('Please enter a valid email.'));
}

if ($this->hasNewPassword()) {
Expand All @@ -606,17 +610,17 @@ public function validate()
if (isset($password)) {
$minAdminPasswordLength = $this->getMinAdminPasswordLength();
if (Mage::helper('core/string')->strlen($password) < $minAdminPasswordLength) {
$errors[] = Mage::helper('adminhtml')
->__('Password must be at least of %d characters.', $minAdminPasswordLength);
$errors->append(Mage::helper('adminhtml')
->__('Password must be at least of %d characters.', $minAdminPasswordLength));
}

if (!preg_match('/[a-z]/iu', $password) || !preg_match('/[0-9]/u', $password)) {
$errors[] = Mage::helper('adminhtml')
->__('Password must include both numeric and alphabetic characters.');
$errors->append(Mage::helper('adminhtml')
->__('Password must include both numeric and alphabetic characters.'));
}

if ($this->hasPasswordConfirmation() && $password != $this->getPasswordConfirmation()) {
$errors[] = Mage::helper('adminhtml')->__('Password confirmation must be same as password.');
$errors->append(Mage::helper('adminhtml')->__('Password confirmation must be same as password.'));
}

Mage::dispatchEvent('admin_user_validate', array(
Expand All @@ -626,13 +630,14 @@ public function validate()
}

if ($this->userExists()) {
$errors[] = Mage::helper('adminhtml')->__('A user with the same user name or email already exists.');
$errors->append(Mage::helper('adminhtml')->__('A user with the same user name or email already exists.'));
}

if (count($errors) === 0) {
return true;
}
return (array)$errors;

return (array) $errors;
}

/**
Expand All @@ -649,7 +654,7 @@ public function validateCurrentPassword($password)

if (!Zend_Validate::is($password, 'NotEmpty')) {
$result[] = $this->_getHelper('adminhtml')->__('Current password field cannot be empty.');
} elseif (is_null($this->getId()) || !$this->_getHelper('core')->validateHash($password, $this->getPassword())) {
} elseif (is_null($this->getId()) || !Mage::helper('core')->validateHash($password, $this->getPassword())) {
$result[] = $this->_getHelper('adminhtml')->__('Invalid current password.');
}

Expand Down
46 changes: 27 additions & 19 deletions app/code/core/Mage/Api/Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@
* @method $this setEmail(string $value)
* @method string getUsername()
* @method $this setUsername(string $value)
* @method bool hasApiKey()
* @method string getApiKey()
* @method $this setApiKey(string $value)
* @method bool hasApiKeyConfirmation()
* @method string getApiKeyConfirmation()
* @method string getCreated()
* @method $this setCreated(string $value)
* @method string getModified()
Expand All @@ -51,6 +54,7 @@
* @method $this setIsActive(int $value)
* @method string getSessid()
* @method $this setSessid($sessId)
* @method bool hasNewApiKey()
* @method string getNewApiKey()
* @method string getUserId()
* @method string getLogdate()
Expand Down Expand Up @@ -127,6 +131,7 @@ public function save()
* Delete user
*
* @return $this|Mage_Core_Model_Abstract
* @throws Mage_Core_Exception
*/
public function delete()
{
Expand All @@ -140,6 +145,7 @@ public function delete()
* Save relations for users
*
* @return $this
* @throws Mage_Core_Exception
*/
public function saveRelations()
{
Expand Down Expand Up @@ -248,6 +254,7 @@ public function getAclRole()
* @param string $username
* @param string $apiKey
* @return boolean
* @throws Exception
*/
public function authenticate($username, $apiKey)
{
Expand All @@ -258,18 +265,19 @@ public function authenticate($username, $apiKey)
$auth = Mage::helper('core')->validateHash($apiKey, $this->getApiKey());
if ($auth) {
return true;
} else {
$this->unsetData();
return false;
}

$this->unsetData();
return false;
}

/**
* Login user
*
* @param string $username
* @param string $apiKey
* @return Mage_Api_Model_User
* @param string $username
* @param string $apiKey
* @return Mage_Api_Model_User
* @throws Exception
*/
public function login($username, $apiKey)
{
Expand Down Expand Up @@ -354,7 +362,7 @@ public function hasAssigned2Role($user)
*/
protected function _getEncodedApiKey($apiKey)
{
return $this->_getHelper('core')->getHash($apiKey, Mage_Admin_Model_User::HASH_SALT_LENGTH);
return Mage::helper('core')->getHash($apiKey, Mage_Admin_Model_User::HASH_SALT_LENGTH);
}

/**
Expand All @@ -371,27 +379,27 @@ protected function _getHelper($helperName)
/**
* Validate user attribute values.
*
* @return array|bool
* @return array|true
* @throws Zend_Validate_Exception
*/
public function validate()
{
$errors = new ArrayObject();

if (!Zend_Validate::is($this->getUsername(), 'NotEmpty')) {
$errors[] = $this->_getHelper('api')->__('User Name is required field.');
$errors->append($this->_getHelper('api')->__('User Name is required field.'));
}

if (!Zend_Validate::is($this->getFirstname(), 'NotEmpty')) {
$errors[] = $this->_getHelper('api')->__('First Name is required field.');
$errors->append($this->_getHelper('api')->__('First Name is required field.'));
}

if (!Zend_Validate::is($this->getLastname(), 'NotEmpty')) {
$errors[] = $this->_getHelper('api')->__('Last Name is required field.');
$errors->append($this->_getHelper('api')->__('Last Name is required field.'));
}

if (!Zend_Validate::is($this->getEmail(), 'EmailAddress')) {
$errors[] = $this->_getHelper('api')->__('Please enter a valid email.');
$errors->append($this->_getHelper('api')->__('Please enter a valid email.'));
}

if ($this->hasNewApiKey()) {
Expand All @@ -403,23 +411,23 @@ public function validate()
if (isset($apiKey)) {
$minCustomerPasswordLength = $this->_getMinCustomerPasswordLength();
if (strlen($apiKey) < $minCustomerPasswordLength) {
$errors[] = $this->_getHelper('api')
->__('Api Key must be at least of %d characters.', $minCustomerPasswordLength);
$errors->append($this->_getHelper('api')
->__('Api Key must be at least of %d characters.', $minCustomerPasswordLength));
}

if (!preg_match('/[a-z]/iu', $apiKey) || !preg_match('/[0-9]/u', $apiKey)) {
$errors[] = $this->_getHelper('api')
->__('Api Key must include both numeric and alphabetic characters.');
$errors->append($this->_getHelper('api')
->__('Api Key must include both numeric and alphabetic characters.'));
}

if ($this->hasApiKeyConfirmation() && $apiKey != $this->getApiKeyConfirmation()) {
$errors[] = $this->_getHelper('api')->__('Api Key confirmation must be same as Api Key.');
$errors->append($this->_getHelper('api')->__('Api Key confirmation must be same as Api Key.'));
}
}

if ($this->userExists()) {
$errors[] = $this->_getHelper('api')
->__('A user with the same user name or email already exists.');
$errors->append($this->_getHelper('api')
->__('A user with the same user name or email already exists.'));
}

if (count($errors) === 0) {
Expand Down