Error when adding SOAP/XML-RPC users and roles - magento

I tried to upgrade Magento 1.9.0.1 to 1.9.1 via the Magento Connect facility and it seems to have stopped me being able to add users and roles for API access.
Here's the error:
Invalid method Mage_Admin_Model_User::validateCurrentPassword(Array
Has anyone ever come across this?

this issues can be solve
1) open the file app/code/core/Mage/Adminhtml/Controller/Action.php
2) After that see the function on line number 395 and comment the internel code into this.
protected function _validateCurrentPassword($password){
/*$user = Mage::getSingleton('admin/session')->getUser();
return $user->validateCurrentPassword($password);*/
}

I recently came across this same issue after upgrading Magento to a newer version of 1.9.
It should be noted that you should never modify core files, and the password validation should not necessarily be removed.
In my personal case, I restored the original function to the core file, however, you could just as easily extend the Mage_Admin_Model_User class.
The version of the function I used can be found below.
/**
* Validate password against current user password
* Returns true or array of errors.
*
* #return mixed
*/
public function validateCurrentPassword($password)
{
$result = array();
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())){
$result[] = $this->_getHelper('adminhtml')->__('Invalid current password.');
}
if (empty($result)) {
$result = true;
}
return $result;
}

Related

PHPBB 3.1.10 Dependency Injection of User Object only delivers Anonymous User in a live environment

The goal is to get the login status of a User in PHPBB 3.1.10 in an Extension Module using only AJAX calls.
I have succeded with this on XAMPP on my local machine. (meaning the problem described does not exist in that environment) I am now trying to roll that out to my online site by installing the extension on a live PHPBB Installation.
The problem now is that as opposed to my local environment the #user
object delivered by the dependency injection mechanism is always
"Anonymous", no matter if I am logged in or not.
"Anonymous" is the Username of a PHPBB User who is not logged in.
Both envrionments use PHPBB 3.1.10.
The Folder Structure is deviates only in the name of the PHPBB3 Root Folder name.
Both have functioning URL Rewrite now, after I had to manually set
the Live Environments RewriteBase in .htaccess.
Board Settings seem to be identical but for the domain.
As for PHP Server settings - I have no direct influence on PHP config on the live environmenht but for .htaccess and I have very little knowladge about what is possible in that regard.
Here is my Service Defintion, Routing Information and the Authorization class used to read the #user object.
ext/foo/bar/services.yml
services:
foo.bar.helper.auth:
class: foo\bar\helper\Auth
arguments:
- '#user'
- '%core.root_path%'
- '%core.php_ext%'
ext/foo/bar/config/routing.yml
foo_bar_getUserStatus:
path: /getUserStatus
defaults: { _controller: foo.bar.helper.Auth:getUserStatus }
ext/foo/bar/helper/Auth.php
<?php
namespace foo\bar\helper;
class Auth{
/* #var \phpbb\user */
protected $user;
/** #var string */
protected $root_path;
/** #var string */
protected $php_ext;
/**
* Constructor
*
* #param \phpbb\user $user
* #param string $root_path
* #param string $php_ext php ext
* #access public
*/
public function __construct(
\phpbb\user $user,
$root_path,
$php_ext)
{
$this->user = $user;
$this->root_path = $root_path;
$this->php_ext = $php_ext;
include_once($this->root_path
. 'includes/functions_user.'
. $this->php_ext);
}
// AUTHORIZATION
public function __getUserStatus(){
$userStatus = array( 'isLoggedIn' => false );
if ($this->user->data['is_registered'] && ! $user->data['is_bot']){
$userStatus['isLoggedIn'] = true;
$ADMINS_GROUP_ID = '5';
if(group_memberships($ADMINS_GROUP_ID, $this->user->data['user_id'], true)){
$userStatus['isAdmin'] = true;
}
}
return $userStatus;
}
public function getUserStatus(){
return new \Symfony\Component\HttpFoundation\JsonResponse(array(
'success' => $this->__getUserStatus()
));
}
}
update 11.01.17
I have managed to get the extension to run properly on a fresh Installation of PHPBB 3.2 (which was released very recently) and PHP 7.0. (running in the same server environment as the live one)
I still have no idea yet why the user object was not set properly.
Also I have not checked out yet if migrating data from PHPBB 3.1.10 to a fresh installation of PHPBB 3.2 is feasible for me.
It will take some time for me to figure things out as I'm not working full time on it.

Check line existence in laravel's trans()

Lets say in my lang/en/general.php there are multiple translation lines for example:
"token" => "This password reset token is invalid.",
"sent" => "Password reminder sent!",
"reset" => "Password has been reset!",
But in my lang/de/general.php these lines are missing.
So later, when I use the Lang::get('general.token') or simply trans('general.token')
The english version will return
This password reset token is invalid.
And the german (de) version will return
general.token
Is there any way I can handle a 'translation not found' function, like a filter but not creating a special class for it? For example, when a line has no translation, I want to throw an Exception.
Thanks in advance!
In Laravel 4 only, you can use Lang::has() as below, here is the doc
if (\Lang::has('general.token')) {
// line exists.
} else {
// line not exist.
}
In current Laravel versions you can just use trans helper like so:
#if (trans()->has('general.token'))
{{ trans('general.token') }}
#endif
This question is getting a little bit old but as per version 5.8 you can simply check as this :
array_key_exists('your-word-key', trans('your-file'))
or
array_key_exists('your-word-key', trans('your-file.array_key'))
for nested translations
You might want to write a helper similar to the one below to help with fallbacks:
/**
* Makes translation fall back to specified value if definition does not exist
*
* #param string $key
* #param null|string $fallback
* #param null|string $locale
* #param array|null $replace
*
* #return array|\Illuminate\Contracts\Translation\Translator|null|string
*/
function trans_fb(string $key, ?string $fallback = null, ?string $locale = null, ?array $replace = [])
{
if (\Illuminate\Support\Facades\Lang::has($key, $locale)) {
return trans($key, $replace, $locale);
}
return $fallback;
}
Note: The helper only works on PHP 7.1 (which has support nullable types). Adjust it to your PHP version if it's lower than 7.1.
You can create your own TranslationServiceProvider and Translator and override the get() method in translator to throw an exception when the parent::get() returns a translation string that is equal to the translation key that was passed in. Both #lang() and trans() functions call the get() method of the translator.
Seems like a whole lot of trouble only to get another reason for a "Whoops! something went wrong!" on your site. You will only get the exception when the translation is encountered.
Another solution: you can use the barryvdh/laravel-translation-manager package, it has a translation service provider that logs missing translation keys and a web interface for managing translations. It will log missing translation keys per locale and let you edit them through a web interface.
It is simple to setup and easy to modify. So you can replace the logging with throwing an exception.

Magento translations ok in online program but not run as cronjob

I created a module (extends Mage_Core_Model_Abstract) and an admin controller.
When I run this module online translations are going right.
When I run this module as cronjob, everything goes allright but translations are not done, I specified translation file in config.xml in as well frontend as adminhtml.
What I am doing wrong?
I see this is a very old question. I've posted here to future reference and others.
Quick and dirty solution
// Fix unitialized translator
Mage::app()->getTranslator()->init('frontend', true);
just after
$initialEnvironmentInfo = $appEmulation>startEnvironmentEmulation($storeId);
for instance. Or in a foreach loop of your own, which is called via cron/admin. Since you're talking about crons, I assume that you know what you are doing.
The real problem
In Magento 1.9 in Mage_Core_Model_App_Emulation (in app/code/core/Mage/Core/Model/App/Emulation.php), there's this function:
/**
* Apply locale of the specified store
*
* #param integer $storeId
* #param string $area
*
* #return string initial locale code
*/
protected function _emulateLocale($storeId, $area = Mage_Core_Model_App_Area::AREA_FRONTEND)
{
$initialLocaleCode = $this->_app->getLocale()->getLocaleCode();
$newLocaleCode = $this->_getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE, $storeId);
if ($initialLocaleCode != $newLocaleCode) {
$this->_app->getLocale()->setLocaleCode($newLocaleCode);
$this->_factory->getSingleton('core/translate')->setLocale($newLocaleCode)->init($area, true);
}
return $initialLocaleCode;
}
The $initialLocaleCode != $newLocaleCode seems to be the issue here. When iteration orders/customers/subscribers/*, the locale could stay the same, which then prevents executing the code in the statement. And the locale is thus not set in the Translator (Mage::app()->getTranslator()).
We've yet to fix the issue, but you could change if ($initialLocaleCode != $newLocaleCode) { to if (true) { straight in the core source. Off course, this is ugly. I suggest something like extending the class and then :
/**
* Apply locale of the specified store. Extended
* to fix Magento's uninitialized translator.
*
* #see http://stackoverflow.com/questions/19940733/magento-translations-ok-in-online-program-but-not-run-as-cronjob#
* #param integer $storeId
* #param string $area
*
* #return string initial locale code
*/
protected function _emulateLocale($storeId, $area = Mage_Core_Model_App_Area::AREA_FRONTEND)
{
$initialLocaleCode = $this->_app->getLocale()->getLocaleCode();
$newLocaleCode = $this->_getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE, $storeId);
$this->_app
->getLocale()
->setLocaleCode($newLocaleCode);
$this->_factory
->getSingleton('core/translate')
->setLocale($newLocaleCode)
->init($area, true);
return $initialLocaleCode;
}
Magento 2
I guess the developers became aware it was borked and they changed the code in Magento 2. The _emulateLocale() function is gone all together and they added this line to the startEnvironmentEmulation() function, without any conditional around it:
$this->_localeResolver->setLocale($newLocaleCode);
It's a bug even with CE 1.9.0.1!
See what I've done about it:
https://magento.stackexchange.com/questions/25612/cron-job-template-block-not-being-translated-but-testobserver-is/25920#25920

Magento - Forgotten password link generation is using incorrect store view

Does anybody know where I might find the functions for where a forgotten password reset link is generated in the email that is sent to the user?
For some odd reason mine is generating the reset password link with a different store view in the URL than the store view that was used to reset the password.
The link should be:
example.com/customer/account/resetpassword/?id=555&token=55555555555555555
But it is being generated as such:
example.com/otherStoreView/customer/account/resetpassword/?id=555&token=55555555555555555
To fix this, open the file "app\code\local\Mage\Customer\Model\Customer.php".
Look for the function sendPasswordResetConfirmationEmail(). It is near the line 685.
This function looks like this:
/**
* Send email with reset password confirmation link
*
* #return Mage_Customer_Model_Customer
*/
public function sendPasswordResetConfirmationEmail()
{
$storeId = $this->getStoreId();
if (!$storeId) {
$storeId = $this->_getWebsiteStoreId();
}
$this->_sendEmailTemplate(self::XML_PATH_FORGOT_EMAIL_TEMPLATE, self::XML_PATH_FORGOT_EMAIL_IDENTITY,
array('customer' => $this), $storeId);
return $this;
}
In this function, Magento is getting the store id where the user was registered, but we need the store id where he made the password reset request. We just need to remove some lines and add a new one:
public function sendPasswordResetConfirmationEmail()
{
# this will get the current store ID
$storeId = Mage::app()->getStore()->getStoreId();
$this->_sendEmailTemplate(self::XML_PATH_FORGOT_EMAIL_TEMPLATE, self::XML_PATH_FORGOT_EMAIL_IDENTITY,
array('customer' => $this), $storeId);
return $this;
}
This worked for me, I hope it helps.
The email template for that is:
app/locale/langcode_COUNRTYCODE/template/email/account_password_reset_confirmation.html
And the line that generates the URL is
{{store url="customer/account/resetpassword/" _query_id=$customer.id _query_token=$customer.rp_token}}

Magento - How I can Run Store by Country by GeoIP?

I want run store by IP of the customer.
In the backend of Magento, the user may configure the concret Store to load per country.
Taking a glance, I see the method at class Mage_Core_Model_App
public function run($params)
{
$options = isset($params['options']) ? $params['options'] : array();
$this->baseInit($options);
if ($this->_cache->processRequest()) {
$this->getResponse()->sendResponse();
} else {
$this->_initModules();
$this->loadAreaPart(Mage_Core_Model_App_Area::AREA_GLOBAL, Mage_Core_Model_App_Area::PART_EVENTS);
if ($this->_config->isLocalConfigLoaded()) {
//$scopeCode = isset($params['scope_code']) ? $params['scope_code'] : '';
//===============custom scope by country======================
$scopeCode = Mage::helper('custom/module')->getStoreByGeoip();
//===============custom scope by country======================
$scopeType = isset($params['scope_type']) ? $params['scope_type'] : 'store';
$this->_initCurrentStore($scopeCode, $scopeType);
$this->_initRequest();
Mage_Core_Model_Resource_Setup::applyAllDataUpdates();
}
$this->getFrontController()->dispatch();
}
return $this;
}
In my progress to get a good solution, I thought another alternative.
In the index.php write the next code:
Mage::app();
Mage::Helper('custom/helper')->getRunCodeByGeoio();
Mage::run($mageRunCode, $mageRunType);
I thinks this haven´t dangerous of performance because this method only create object if you not have before
/**
* Get initialized application object.
*
* #param string $code
* #param string $type
* #param string|array $options
* #return Mage_Core_Model_App
*/
public static function app($code = '', $type = 'store', $options = array())
{
if (null === self::$_app) {
self::$_app = new Mage_Core_Model_App();
self::setRoot();
self::$_events = new Varien_Event_Collection();
self::$_config = new Mage_Core_Model_Config();
Varien_Profiler::start('self::app::init');
self::$_app->init($code, $type, $options);
Varien_Profiler::stop('self::app::init');
self::$_app->loadAreaPart(Mage_Core_Model_App_Area::AREA_GLOBAL, Mage_Core_Model_App_Area::PART_EVENTS);
}
return self::$_app;
}
And my question is......
Are this the best approach for get the solution??
I think is very dangerous modify Mage_Core_Model_App even using rewrite
I don´t have any event at tier
Another option is made the business in the index.php but lost the management by the backend
Searching...., found a extension that cover many of my requirements,
http://www.mageworx.com/store-and-currency-auto-switcher-magento-extension.html
then I'll buy this or made a similar extension.
You shyould never touch any core files when developing with Magento, or any other application if you can avoid it.
Doing this will mean possible future upgrades will overwrite your changes and break your store.
The simplest way would be to do everything index.php as this is the entry point where the store is selected anyway, all you are doing is selecting the store on different criteria (ie IP address).
One simple way would be to use a free library, such as maxmind GeoLite: http://dev.maxmind.com/geoip/geolite
You can either load an apache module, or via a pecl extensions, or even plain PHP.
This will return you the iso country code for the country of your visitor.
You could then name your stores with a country iso code for the store code, and this will make it really simple to load the correct store depending on IP
something simple like this:
$countryCode = getUsersCountryCode(); // which ever method you use in here...
$stores = array(
'gb',
'us',
'fr',
);
if(in_array(countryCode, $stores)) {
Mage::run(countryCode, 'store');
}
else {
Mage::run($mageRunCode, $mageRunType);
}
You could of course make it into a Magento extensions, but this is by far the simplest way. You could even get a list of the countries/stores from Magento rather than hard coding them if you required.

Resources