1

I need to change expiration time of reset link.

Got the setting to change the expiration time from Admin panel . "Recovery Link Expiration Period (Hours)" But it's in hours and i want to change it to minutes Similar question had been raised on Magento 1.7 but i am unable to find similar resolution for magento 2.

Change expiration time of password reset link

insoftservice
  • 311
  • 2
  • 11
  • Did you try like this: 0.30 for 30mins or 0.01 for 1 minute. Try this. – Akash Feb 06 '19 at 10:44
  • You need to create your own module for that in which you need to provide hours and minutes option in admin configuration. Then you need to override isResetPasswordLinkTokenExpired() method of Magento\Customer\Model\AccountManagement class. Put your customized code inside this method. I haven't tried this thing, but tips may help you. – Dhara Bhatti Feb 06 '19 at 10:53
  • You can use around plugin for function override isResetPasswordLinkTokenExpired function – Suman-PHP4U Feb 06 '19 at 10:55
  • @John thx it works but if did from core_config_data and not via panel. – insoftservice Feb 06 '19 at 10:57
  • you mean you added it in core_config_data table? for which key you have added it? – Akash Feb 06 '19 at 11:00
  • @Suman for creating plugin we have to override the function but same function is written in 3 different models .hence it's creating confusion as Label (Hours ) was changed to minutes in vendor/magento/magento-backend/i18n/en_Us.csv but after changing the code in isResetPasswordLinkTokenExpired() it did not worked. – insoftservice Feb 06 '19 at 11:01
  • @John customer/password/reset_link_expiration_period just SELECT * FROM core_config_data WHERE path LIKE '%customer/password/reset_link_expiration_period%' . – insoftservice Feb 06 '19 at 11:01
  • Hope after changing vendor or overriding model i have execute 1> bin/magento setup:di:compile 2> bin/magento setup:static-content:deploy – insoftservice Feb 06 '19 at 11:04
  • gotcha! that was the same field which got updated from admin section, you make direct entry in table which is not good. If its not updating then something went wrong. Anyways, its good that it works for you. – Akash Feb 06 '19 at 11:09
  • Ya , but how to update it from admin panel that's my main question by overriding which module – insoftservice Feb 06 '19 at 11:18
  • see my answer. Hope it helps. – Akash Feb 06 '19 at 11:44

2 Answers2

0

From admin panel, it doesn't allow user to add a number less than 1, for example if someone wants to add time in minutes. This was the file from where it comes from

/var/www/html/projectName/vendor/magento/module-customer/etc/adminhtml/system.xml

<field id="reset_link_expiration_period" translate="label comment" type="text" sortOrder="60" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
                    <label>Recovery Link Expiration Period (hours)</label>
                    <comment>Please enter a number 1 or greater in this field.</comment>
                    <validate>required-entry validate-digits validate-digits-range digits-range-1-</validate>
                    <backend_model>Magento\Customer\Model\Config\Backend\Password\Link\Expirationperiod</backend_model>
                </field>

As you can see, it has

<validate>required-entry validate-digits validate-digits-range digits-range-1-</validate>

which validate the field, to not to accept number less than one. To achieve this, first you need to override this system.xml file by How to override system.xml core file in magento2

and update validate by this

                <validate>required-entry validate-digits</validate>

Hope it helps.

Akash
  • 618
  • 7
  • 17
  • thx @john I changed it to required-entry integer validate-greater-than-zero Path app/code/hpol/customer/etc/adminhtml/system.xml and executed 3 command 1> bin/magento setup:upgrade 2> bin/magento setup:static-content:deploy 3> bin/magento setup:di:compile But its not reflecting on admin panel. Hope i am doing some silly mistake . Could you please help me in this – insoftservice Feb 06 '19 at 16:34
  • In your this module, add in your module.xml file. See this link for more reference https://magento.stackexchange.com/questions/141077/how-to-override-system-xml-core-file-in-magento2 Also i have noticed that you are adding validation of greater than zero, it will also not allow you to add time in minutes. – Akash Feb 07 '19 at 05:30
  • it works but in backend it does not saves as 0.5 i.e 30 min. Instead it saves a 1 by default. – insoftservice Feb 08 '19 at 06:00
  • yes, because you have added validate-greater-than-zero this validation. remove it and try it again. – Akash Feb 08 '19 at 08:01
  • it works but in backend it does not saves as 0.5 i.e 30 min. Instead it saves a 1 by default. Script which does this Magento\Customer\Model\Config\Backend\Password\Link\Expirationperiod – insoftservice Feb 08 '19 at 09:41
0

I have chosen to override function which save config value Create a Folder Customer Path : App/code/Desiredname/Customer create folders etc,i18n,Model and file registration.php

Path/etc/module.xml

    <?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Desiredname_Customer" setup_version="1.1.6">
        <sequence>
            <module name="Magento_Customer"/>
        </sequence>
    </module>
</config>

Path/app/etc/adminhtml/system.xml

<?xml version="1.0"?>
<!--
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
    <system>
<group id="password" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">

            <field id="reset_link_expiration_period" translate="label comment" type="text" sortOrder="60" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
                <label>Recovery Link Expiration Period (hours)</label>
                <comment>Please enter a number 1 or greater in this field.</comment>
                <validate>required-entry validate-greater-than-zero</validate>
                <backend_model>Desiredname\Customer\Plugin\Model\Config\Backend\Password\Link\Expirationperiod</backend_model>
            </field>
            </group>
   </system>
</config>

This two lines are important

<validate>required-entry validate-greater-than-zero</validate>
                <backend_model>Desiredname\Customer\Plugin\Model\Config\Backend\Password\Link\Expirationperiod</backend_model>

Path\Plugin\Model\Config\Backend\Password\Link\Expirationperiod

Above will allow to insert value in decimals but while saving there is PHP validation to check decimal values and value below 1. Hence had to override this functionality

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Desiredname\Customer\Plugin\Model\Config\Backend\Password\Link;

/**
 * Customer Reset Password Link Expiration period backend model
 *
 * @author     Magento Core Team <core@magentocommerce.com>
 */


class Expirationperiod extends \Magento\Framework\App\Config\Value
{
    /**
     * Validate expiration period value before saving
     *
     * @return $this
     */
     public function beforeSave()
    {
        parent::beforeSave();
        $resetPasswordLinkExpirationPeriod = (float)$this->getValue();
        $this->setValue((string)$resetPasswordLinkExpirationPeriod);
        return $this;
    }
}

To change Label at admin level

Path/i18n/en_US.csv

"Please enter a number 1 or greater in this field.","Please enter a number 0 or greater in this field."
insoftservice
  • 311
  • 2
  • 11