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

11
  • Did you try like this: 0.30 for 30mins or 0.01 for 1 minute. Try this.
    – Akash
    Commented Feb 6, 2019 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. Commented Feb 6, 2019 at 10:53
  • You can use around plugin for function override isResetPasswordLinkTokenExpired function Commented Feb 6, 2019 at 10:55
  • @John thx it works but if did from core_config_data and not via panel. Commented Feb 6, 2019 at 10:57
  • you mean you added it in core_config_data table? for which key you have added it?
    – Akash
    Commented Feb 6, 2019 at 11:00

2 Answers 2

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.

5
  • thx @john I changed it to <validate>required-entry integer validate-greater-than-zero</validate> 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 Commented Feb 6, 2019 at 16:34
  • In your this module, add <module name="Magento_Customer"/> in your module.xml file. See this link for more reference magento.stackexchange.com/questions/141077/… 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
    Commented Feb 7, 2019 at 5:30
  • it works but in backend it does not saves as 0.5 i.e 30 min. Instead it saves a 1 by default. Commented Feb 8, 2019 at 6:00
  • yes, because you have added validate-greater-than-zero this validation. remove it and try it again.
    – Akash
    Commented Feb 8, 2019 at 8: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 Commented Feb 8, 2019 at 9: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 <[email protected]>
 */


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."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.