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
Create file amember/application/configs/site.php PHP: <?phpfunction 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');
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).
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++;
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!
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.
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.