/**
     * @anonym
     * @service
     * @param $fields
     * @return Gpf_Rpc_Form
     */
    public function add(Gpf_Rpc_Params $params) {
        $context = Pap_Contexts_Signup::getContextInstance();
        $context->debug('    Saving user started');
        $context->setParametersObject($params);

        $this->isFromApi = $params->get('isFromApi') == Gpf::YES;

        $form = $this->addUser($params);
        $context->setUserObject($this->getAffiliate());
        $context->setFormObject($form);

        if ((!$form->isSuccessful()) || ($this->getAffiliate() == null)) {
            $context->debug('        STOPPING, Error saving new user - did not pass the validation? Error message: '.$form->getErrorMessage());
            Gpf_Plugins_Engine::extensionPoint('PostAffiliate.signup.afterFail', $context);
        } else {
            $context->setUserObject($this->getAffiliate());
            $this->sendEmails($context);
            Gpf_Plugins_Engine::extensionPoint('PostAffiliate.signup.after', $context);
        }

        $context->debug("Signup processing ended");

        return $form;
    }
Exemple #2
0
    /**
     * @param $email
     * @param $context
     * @return Pap_Affiliates_User
     */
    private function createUserFromEmail($email, $context) {
        $context->debug('Loading affiliate by email');
        $emailValidator = new Gpf_Rpc_Form_Validator_EmailValidator();
        if (!$emailValidator->validate($email)) {
            if (!$emailValidator->validate(urldecode($email))) {
                $context->debug('    AutoRegisteringAffiliates - Creating affiliate stopped, not valid email address: ' . $email);
                return null;
            }
            $email = urldecode($email);
        }
        try {
            return Pap_Affiliates_User::loadFromUsername($email);
        } catch (Gpf_Exception $e) {
            if (!Pap_Common_User::isUsernameUnique($email)) {
                $context->debug('    AutoRegisteringAffiliates - Creating affiliate stopped, email address is used for another user: '******'');
            $user->setLastName(substr($email, 0, strpos($email, '@')));
            //$user->setSendNotification(false);
            $user->save();
            $signupForm->setDefaultEmailNotificationsSettings($user);

            $signupContext = Pap_Contexts_Signup::getContextInstance();
            $signupContext->setUserObject($user);
            $merchantNotificationEmails = new Pap_Signup_SendNotificationEmails();
            $merchantNotificationEmails->process($signupContext);

            $context->debug('    AutoRegisteringAffiliates - New Affiliate created successfully, email: ' . $email);

            Gpf_Db_Table_UserAttributes::setSetting(self::AUTO_REGISTERED_AFFILIATE, Gpf::YES, $user->getAccountUserId());
        }

        return Pap_Affiliates_User::loadFromUsername($email);
    }