Jump to content

Limit Access For Unverified Accounts


sentq

Recommended Posts

These ActionHook functions will add some restrictions to unverified accounts.

 

Current features:

1) Prevent account from placing orders in WHMCS, and display error message guide them to activate first.

2) Change account status to Inactive after x days.

3) Change account status to Closed after x days.

 

Do not hesitate to share any ideas, requests or features to extend this functions.

 

 

Download

Link to comment
Share on other sites

  • 2 weeks later...

Thanks for sharing. I'm new to hooks - Do you know how I can check if email verification has been completed in an action hook? I'm not using capsule, so would this code still work?

 

if (!is_null($client) && $client->emailVerified!==true){

 

Also, a suggestion for you, rather than CLOSEACCOUNTAFTERXDAYS how about a resendverification afterxdays function (I don't think the system does that). I suppose you'd need to apply the resend only to newly created accounts.

Edited by sol2010
Link to comment
Share on other sites

Thanks for sharing. I'm new to hooks - Do you know how I can check if email verification has been completed in an action hook? I'm not using capsule, so would this code still work?

 

if (!is_null($client) && $client->emailVerified!==true){

you may use something like that


use WHMCS\View\Menu\Item as MenuItem;

$client = Menu::context("client");

if (!is_null($client) && $client->emailVerified===true){
   // Client email verified
}
else {
   // Client email not verified yet or not logged-in
}

 

Also, a suggestion for you, rather than CLOSEACCOUNTAFTERXDAYS how about a resendverification afterxdays function (I don't think the system does that). I suppose you'd need to apply the resend only to newly created accounts.

I will add it as optional function in the next update

 

Thank you :)

Link to comment
Share on other sites

  • 2 years later...
On 5/14/2016 at 3:28 AM, sentq said:

These ActionHook functions will add some restrictions to unverified accounts.

 

Current features:

1) Prevent account from placing orders in WHMCS, and display error message guide them to activate first.

2) Change account status to Inactive after x days.

3) Change account status to Closed after x days.

 

Do not hesitate to share any ideas, requests or features to extend this functions.

 

 

Download

Thanks, but i am not able to download it. I am receiving 404 Page Not Found Error.

Link to comment
Share on other sites

  • 1 month later...
On 5/14/2016 at 12:28 AM, sentq said:

These ActionHook functions will add some restrictions to unverified accounts.

 

Current features:

1) Prevent account from placing orders in WHMCS, and display error message guide them to activate first.

2) Change account status to Inactive after x days.

3) Change account status to Closed after x days.

 

Do not hesitate to share any ideas, requests or features to extend this functions.

 

 

Download

Can you please share a new URL? This one is broken, i get a 404 Not Found Page
http://nimb.ws/ohF17L

Link to comment
Share on other sites

  • 2 years later...
On 5/13/2016 at 5:28 PM, sentq said:

These ActionHook functions will add some restrictions to unverified accounts.

 

Current features:

1) Prevent account from placing orders in WHMCS, and display error message guide them to activate first.

2) Change account status to Inactive after x days.

3) Change account status to Closed after x days.

 

Do not hesitate to share any ideas, requests or features to extend this functions.

 

 

Download

after checking this. I see that it does not work. could you check the code? apparently stopped working for whmcs v8

I want them to not be able to order. (If the email is not verified then it will not allow you to place the order)

 

Link to comment
Share on other sites

On 1/18/2021 at 11:37 AM, brian! said:

going by the v8 class docs, I assume it should now be $client->isEmailAddressVerified rather than $client->emailVerified

 

after checking $client with a var_dump I realized that neither of the 2 options would work.

neither emailVerified nor isEmailAddressVerified

I had to use: email_verified_at

email_verified_at returns the value in bool, which is null or true.

here I leave the new code.

<?php
/**
 * Limit Access For Unverified Accounts
 * @package    WHMCS ActionHook
 * @author     Sentq <sales@whmcms.com> and JesusSuarz <info@cangurohosting.com>
 * @copyright  Copyright (c) CanguroHosting.com 2016-2021
 * @link       http://www.whmcms.com/
 */
if (!defined("WHMCS"))
    die("This file cannot be accessed directly");
use WHMCS\View\Menu\Item as MenuItem;
use Illuminate\Database\Capsule\Manager as Capsule;
# ¿Le gustaría evitar que las cuentas no verificadas realicen pedidos ?, configúrelo en falso para aceptar pedidos
define("PREVENTUNVERIFIEDORDERS", true);
# Cuántos días esperar antes de desactivar la cuenta no verificada, establezca 0 para desactivar esta función
define("DEACTIVATEACCOUNTAFTERXDAYS", 0);
# Cuántos días esperar antes de establecer la cuenta no verificada como cerrada, establecer 0 para deshabilitar esta función
define("CLOSEACCOUNTAFTERXDAYS", 0);
# No se completarán pedidos si el correo no esta verificado.
add_hook("ShoppingCartValidateCheckout", 1, function($vars){
    if (PREVENTUNVERIFIEDORDERS===true){
        $client = Menu::context("client");
        if (!is_null($client) && $client->email_verified_at!==true){
            return array("¡Primero debe verificar su dirección de correo electrónico antes de completar cualquier pedido!");
        }
    }
});
# Desactivar la cuenta no verificada después de x días
# http://docs.whmcs.com/Clients:Profile_Tab#Changing_a_Clients_Status
add_hook("DailyCronJob", 1, function($vars){
    if (intval(DEACTIVATEACCOUNTAFTERXDAYS)!==0){
        $dateCreated = date("Y-m-d", strtotime("now - ".intval(DEACTIVATEACCOUNTAFTERXDAYS)." days"));
        $getAccounts = Capsule::table("tblclients")->where("datecreated", "=", $dateCreated)->where("email_verified", "=", 0);
        foreach ($getAccounts->get() as $account){
            Capsule::table("tblclients")->where("id", $account->id)->update(array("status" => "Inactive"));
        }
    }
});
# Cerrar cuentas no verificadas después de X días
# http://docs.whmcs.com/Clients:Profile_Tab#Changing_a_Clients_Status
add_hook("DailyCronJob", 1, function($vars){
    if (intval(CLOSEACCOUNTAFTERXDAYS)!==0){
        $dateCreated = date("Y-m-d", strtotime("now - ".intval(CLOSEACCOUNTAFTERXDAYS)." days"));
        $getAccounts = Capsule::table("tblclients")->where("datecreated", "=", $dateCreated)->where("email_verified", "=", 0);
        foreach ($getAccounts->get() as $account){
            Capsule::table("tblclients")->where("id", $account->id)->update(array("status" => "Closed"));
        }
    }
});

This is executed after accepting the terms in the payment options in: your_whmcs.com/cart.php?a=checkout

screenshot

298469851_descarga-2021-01-22T101123_748.thumb.png.c1caa0dce9940ce9aa3069b761083795.png

Edited by JesusSuarz
Link to comment
Share on other sites

1 hour ago, JesusSuarz said:

 

after checking $client with a var_dump I realized that neither of the 2 options would work.

neither emailVerified nor isEmailAddressVerified

I had to use: email_verified_at

email_verified_at returns the value in bool, which is null or true.

here I leave the new code.


<?php
/**
 * Limit Access For Unverified Accounts
 * @package    WHMCS ActionHook
 * @author     Sentq <sales@whmcms.com> and JesusSuarz <info@cangurohosting.com>
 * @copyright  Copyright (c) CanguroHosting.com 2016-2021
 * @link       http://www.whmcms.com/
 */
if (!defined("WHMCS"))
    die("This file cannot be accessed directly");
use WHMCS\View\Menu\Item as MenuItem;
use Illuminate\Database\Capsule\Manager as Capsule;
# ¿Le gustaría evitar que las cuentas no verificadas realicen pedidos ?, configúrelo en falso para aceptar pedidos
define("PREVENTUNVERIFIEDORDERS", true);
# Cuántos días esperar antes de desactivar la cuenta no verificada, establezca 0 para desactivar esta función
define("DEACTIVATEACCOUNTAFTERXDAYS", 0);
# Cuántos días esperar antes de establecer la cuenta no verificada como cerrada, establecer 0 para deshabilitar esta función
define("CLOSEACCOUNTAFTERXDAYS", 0);
# No se completarán pedidos si el correo no esta verificado.
add_hook("ShoppingCartValidateCheckout", 1, function($vars){
    if (PREVENTUNVERIFIEDORDERS===true){
        $client = Menu::context("client");
        if (!is_null($client) && $client->email_verified_at!==true){
            return array("¡Primero debe verificar su dirección de correo electrónico antes de completar cualquier pedido!");
        }
    }
});
# Desactivar la cuenta no verificada después de x días
# http://docs.whmcs.com/Clients:Profile_Tab#Changing_a_Clients_Status
add_hook("DailyCronJob", 1, function($vars){
    if (intval(DEACTIVATEACCOUNTAFTERXDAYS)!==0){
        $dateCreated = date("Y-m-d", strtotime("now - ".intval(DEACTIVATEACCOUNTAFTERXDAYS)." days"));
        $getAccounts = Capsule::table("tblclients")->where("datecreated", "=", $dateCreated)->where("email_verified", "=", 0);
        foreach ($getAccounts->get() as $account){
            Capsule::table("tblclients")->where("id", $account->id)->update(array("status" => "Inactive"));
        }
    }
});
# Cerrar cuentas no verificadas después de X días
# http://docs.whmcs.com/Clients:Profile_Tab#Changing_a_Clients_Status
add_hook("DailyCronJob", 1, function($vars){
    if (intval(CLOSEACCOUNTAFTERXDAYS)!==0){
        $dateCreated = date("Y-m-d", strtotime("now - ".intval(CLOSEACCOUNTAFTERXDAYS)." days"));
        $getAccounts = Capsule::table("tblclients")->where("datecreated", "=", $dateCreated)->where("email_verified", "=", 0);
        foreach ($getAccounts->get() as $account){
            Capsule::table("tblclients")->where("id", $account->id)->update(array("status" => "Closed"));
        }
    }
});

This is executed after accepting the terms in the payment options in: your_whmcs.com/cart.php?a=checkout

screenshot

298469851_descarga-2021-01-22T101123_748.thumb.png.c1caa0dce9940ce9aa3069b761083795.png

 

after doing hundreds of tests I was able to identify that emailVerified does work. therefore the original script did work.

my problem was the user I was using, it was modified directly in my database. therefore the @Sentq script works fine.

I apologize for posting wrongly.

Link to comment
Share on other sites

  • 2 weeks later...
On 1/18/2021 at 11:37 AM, brian! said:

going by the v8 class docs, I assume it should now be $client->isEmailAddressVerified rather than $client->emailVerified

you were right, although it was $client->isEmailAddressVerified() the () were missing at the end.

here is a new version of the code written.

the texts are in Spanish, sorry. 🙂

Quote

<?php
if (!defined("WHMCS"))
die("No se puede acceder al archivo directamente!");

use WHMCS\View\Menu\Item as MenuItem;
use Illuminate\Database\Capsule\Manager as Capsule;

# ¿Le gustaría evitar que las cuentas no verificadas realicen pedidos ?, configúrelo en falso para aceptar pedidos
define("PREVENTUNVERIFIEDORDERS", true);
# Cuántos días esperar antes de desactivar la cuenta no verificada, establezca 0 para desactivar esta función
define("DEACTIVATEACCOUNTAFTERXDAYS", 365);
# Cuántos días esperar antes de establecer la cuenta no verificada como cerrada, establecer 0 para deshabilitar esta función
define("CLOSEACCOUNTAFTERXDAYS", 0);

# No se completarán pedidos si el correo no esta verificado.
add_hook("ShoppingCartValidateCheckout", 1, function($vars){
    if (PREVENTUNVERIFIEDORDERS===true){
        // obtiene los datos del client
        $client = Menu::context("client");
        // verifica si el cliente esta logeado y si se encuentra
         if (!is_null($client) && $client) {
             // verifica si el email no esta verificado
            if ($client->isEmailAddressVerified()==false)
            {
                // mensaje
                return array("<b>¡Primero debe verificar su dirección de correo electrónico antes de completar cualquier pedido!</b>");
            }
         }
    }
});

# Desactivar la cuenta no verificada después de x días
# http://docs.whmcs.com/Clients:Profile_Tab#Changing_a_Clients_Status
add_hook("DailyCronJob", 1, function($vars){
    if (intval(DEACTIVATEACCOUNTAFTERXDAYS)!==0){
        $dateCreated = date("Y-m-d", strtotime("now - ".intval(DEACTIVATEACCOUNTAFTERXDAYS)." days"));
        $getAccounts = Capsule::table("tblclients")->where("datecreated", "=", $dateCreated)->where("email_verified", "=", 0);
        foreach ($getAccounts->get() as $account){
            Capsule::table("tblclients")->where("id", $account->id)->update(array("status" => "Inactive"));
        }
    }
});

# Cerrar cuentas no verificadas después de X días
# http://docs.whmcs.com/Clients:Profile_Tab#Changing_a_Clients_Status
add_hook("DailyCronJob", 1, function($vars){
    if (intval(CLOSEACCOUNTAFTERXDAYS)!==0){
        $dateCreated = date("Y-m-d", strtotime("now - ".intval(CLOSEACCOUNTAFTERXDAYS)." days"));
        $getAccounts = Capsule::table("tblclients")->where("datecreated", "=", $dateCreated)->where("email_verified", "=", 0);
        foreach ($getAccounts->get() as $account){
            Capsule::table("tblclients")->where("id", $account->id)->update(array("status" => "Closed"));
        }
    }
});

 

 

Link to comment
Share on other sites

  • 9 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated