Signup Account Restrictions

Discussion in 'Customization & add-ons' started by weeklyoptions, Apr 2, 2012.

  1. weeklyoptions

    weeklyoptions aMember Pro Customer

    Joined:
    Nov 29, 2011
    Messages:
    3
    I want to impose a restriction during account signups when a user requests a specific product. The site allows an organization to purchase a membership, then all of their employees can sign up for free. The restriction being that the domain portion of the user's email address must match that provided by the organization when they registered.

    I can write the necessary SQL and PHP code; but I don't know where to put it, or even where to start trying to find where to go. Does anyone have any knowledge about where to start here?

    Thanks.

    Leonard Daly
  2. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    Create file amember/application/configs/site.php

    PHP:
    <?php
    function checkSignup(Am_Event $event)
    {
         
    $invoice $event->getInvoice();
         
    $restrictedProducts = array(1,2,44);
         
    $found 0;
         foreach (
    $invoite->getProducts() as $product)
               if (
    in_array($product->pk(), $restrictedProducts)) $found++;
         if (!
    $found) return; // no restricted products in invoice
         
    $user $invoice->getUser();
         
    $user->email// user email
         // a sample how to find a user, @see UserTable class
         
    Am_Di::getInstance()->userTable->findByEmail('email-address');
        
    Am_Di::getInstance()->userTable->findBy(array('login' => 'xxx''name_f'=>'Jon'));
        
    $user->getActiveProductIds(); // get product# of active subscriptions for user record @see User class
        // finally when conditions are not met, we can raise a not-loggable-exception
        
    throw new Am_Exception_InputError("You are not allowed to signup");
    }

    Am_Di::getInstance()->hook->add(Am_Event::INVOICE_CALCULATE'checkSignup');
  3. weeklyoptions

    weeklyoptions aMember Pro Customer

    Joined:
    Nov 29, 2011
    Messages:
    3
    Thanks for the code, Alex.

    I implemented as you said, but using my product IDs for '$restrictedProducts'.

    I get an error on the 'foreach' statement:
    PHP Fatal error: Call to protected method Invoice::getProducts() from context '' in .../amember/application/configs/site.php on line 18, referer: http://xxx/amember/signup/index

    [getProducts is a protected function (line 179) in the Invoice class]

    (also note I changed '$invoite' to '$invoice' in the same line).
  4. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Use this code to query products instead:
    PHP:
         foreach ($invoice->getItems() as $item)
               if (
    $item->item_type == 'product' && in_array($item->item_id$restrictedProducts)) $found++;
  5. weeklyoptions

    weeklyoptions aMember Pro Customer

    Joined:
    Nov 29, 2011
    Messages:
    3
    Your changes worked great. Thank you.
  6. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    A customer informed us that the sample above does not work correctly if e-mail address verification is enabled.
    So there is a new code sample attached.
    Upload it to amember/application/default/plugins/misc/
    then enable plugin at aMember Cp -> Setup -> Plugins : Misc : custom-email-validation-brick
    then go to aMember Cp -> Form Editor, remove E-Mail brick from the form, and insert "Email Validated" brick instead. You have to customize validation rule, of course!

    Attached Files:

  7. pcgaming

    pcgaming New Member

    Joined:
    Mar 28, 2012
    Messages:
    23
    If I do this, the form doesn't ask for an email address anymore. So now anyone can signup for an account regardless of email.
  8. pcgaming

    pcgaming New Member

    Joined:
    Mar 28, 2012
    Messages:
    23
    I should add, DO NOT use the first method above. It is not secure at all and lets anyone gain access to your system, regardless of their email address. Still waiting for a fix on the form brick plugin to see if it works.

Share This Page