/** * Execute a command and return a response. Does not render * @param IRequest $Request * @throws \Exception * @return IResponse the execution response */ function execute(IRequest $Request) { $SessionRequest = $Request; if (!$SessionRequest instanceof ISessionRequest) { throw new \Exception("Session required"); } $Form = new HTMLForm(self::FORM_METHOD, $Request->getPath(), self::FORM_NAME, new HTMLMetaTag(HTMLMetaTag::META_TITLE, self::TITLE), new HTMLHeaderScript(__DIR__ . '/assets/account.js'), new HTMLHeaderStyleSheet(__DIR__ . '/assets/account.css'), new HTMLElement('fieldset', 'fieldset-create-account', new HTMLElement('legend', 'legend-account', self::TITLE), new HTMLElement('label', null, "Choose a Account Type<br/>", new HTMLInputField(self::PARAM_ACCOUNT_NAME, new RequiredValidation())), "<br/><br/>", new HTMLElement('label', null, "Status<br/>", new HTMLInputField(self::PARAM_ACCOUNT_PASSWORD, null, 'password', new RequiredValidation())), "<br/><br/>Login:<br/>", new HTMLButton('submit', 'Login', 'submit')), "<br/>"); $Form->setFormValues($Request); if (!$Request instanceof IFormRequest) { return $Form; } $Form->validateRequest($Request); $AccountEntry = AccountEntry::search($Request[self::PARAM_ACCOUNT_NAME]); $Account = $AccountEntry->getAccount(); $Account->assertPassword($Request[self::PARAM_ACCOUNT_PASSWORD]); $Account->startSession($SessionRequest); return new RedirectResponse(ManageAccount::getRequestURL($AccountEntry->getID()), "Logged in successfully. Redirecting...", 5); }
/** * Execute a command and return a response. Does not render * @param IRequest $Request * @throws RequestException * @throws \CPath\Request\Validation\Exceptions\ValidationException * @throws \Exception * @return IResponse the execution response */ function execute(IRequest $Request) { $SessionRequest = $Request; if (!$SessionRequest instanceof ISessionRequest) { throw new \Exception("Session required"); } $Account = AbstractAccountType::loadFromSession($SessionRequest); $AccountEntry = AccountEntry::get($Account->getID()); $AffiliateQuery = AccountAffiliationEntry::queryAccountAffiliates($Account->getID()); $AffiliateListTable = new HTMLPDOQueryTable($AffiliateQuery); $AffiliateListTable->addColumn('affiliate'); $AffiliateListTable->addColumn('type'); $Form = new HTMLForm(self::FORM_METHOD, $Request->getPath(), self::FORM_NAME, new HTMLMetaTag(HTMLMetaTag::META_TITLE, self::TITLE), new HTMLHeaderScript(__DIR__ . '/assets/account.js'), new HTMLHeaderStyleSheet(__DIR__ . '/assets/account.css'), new HTMLElement('fieldset', 'fieldset-info inline', new HTMLElement('legend', 'legend-info', self::TITLE), new MapRenderer($AccountEntry)), new HTMLElement('fieldset', 'fieldset-manage inline', new HTMLElement('legend', 'legend-manage', "Manage Account"), $Account->getFieldSet($Request)->addClass('inline'), "<br/><br/>", new HTMLButton(self::PARAM_SUBMIT, 'Update', 'update')), new HTMLElement('fieldset', 'fieldset-affiliates inline', new HTMLElement('legend', 'legend-affiliates', "Add affiliation"), "Account ID:<br/>", new HTMLInputField(self::PARAM_AFFILIATE_ID), "<br/><br/>Affiliation Type:<br/>", $TypeSelect = new HTMLSelectField(self::PARAM_AFFILIATE_TYPE, array("Request New Affiliate" => AccountAffiliationEntry::TYPE_REQUEST_AFFILIATE, "Request New Reseller" => AccountAffiliationEntry::TYPE_REQUEST_RESELLER, "Request New Processor" => AccountAffiliationEntry::TYPE_REQUEST_PROCESSOR)), "<br/><br/>", new HTMLButton(self::PARAM_SUBMIT, 'Request', 'request')), new HTMLElement('fieldset', 'fieldset-affiliate-list inline', new HTMLElement('legend', 'legend-affiliate-list', "Affiliates"), $AffiliateListTable), new HTMLElement('fieldset', 'fieldset-affiliate-approve inline', new HTMLElement('legend', 'legend-affiliate-approve', "Approve Affiliates"), $ApproveSelect = new HTMLSelectField(self::PARAM_APPROVE_AFFILIATE_ID, array('Pending affiliate approvals' => null)), "<br/><br/>", new HTMLButton(self::PARAM_SUBMIT, 'Approve', 'approve'))); $AffiliateQuery->addRowCallback(function (AccountAffiliationEntry $Affiliation) use($Account, $ApproveSelect) { if ($Affiliation->isAwaitingApproval()) { $ApproveSelect->addOption($Affiliation->getAffiliateID(), "Approve '" . $Affiliation->getTypeText() . "' - " . $Affiliation->getAffiliateID()); } }); if (!$Request instanceof IFormRequest) { return $Form; } $submit = $Request[self::PARAM_SUBMIT]; switch ($submit) { case 'update': $status = $Form->validateField($Request, self::PARAM_ACCOUNT_STATUS); $AccountEntry->update($Request, $Account, $status); return new RedirectResponse(AccountHome::getRequestURL(), "Account updated successfully. Redirecting...", 5); case 'approve': $affiliateID = $Form->validateField($Request, self::PARAM_APPROVE_AFFILIATE_ID); AccountAffiliationEntry::approveAffiliation($Request, $Account->getID(), $affiliateID); return new RedirectResponse(AccountHome::getRequestURL(), "Account deleted successfully. Redirecting...", 5); case 'request': $affiliateID = $Form->validateField($Request, self::PARAM_AFFILIATE_ID); $type = $Form->validateField($Request, self::PARAM_AFFILIATE_TYPE); AccountAffiliationEntry::setAffiliate($Request, $Account->getID(), $affiliateID, $type); return new RedirectResponse(AccountHome::getRequestURL(), "Affiliation requested successfully. Redirecting...", 5); } throw new \InvalidArgumentException($submit); }
static function setAffiliate(IRequest $Request, $accountID, $affiliateID, $type = self::TYPE_AFFILIATE, $orUpdate = false) { AccountEntry::get($accountID); AccountEntry::get($affiliateID); $Table = self::table(); $Insert = $Table->insert(AccountAffiliationTable::COLUMN_ACCOUNT_ID, AccountAffiliationTable::COLUMN_AFFILIATE_ID, AccountAffiliationTable::COLUMN_TYPE)->values($accountID, $affiliateID, $type); if ($orUpdate) { $Insert->onDuplicateKeyUpdate(AccountAffiliationTable::COLUMN_TYPE, $type); } $Insert->execute($Request); }
/** * Execute a command and return a response. Does not render * @param IRequest $Request * @throws \Exception * @return IResponse the execution response */ function execute(IRequest $Request) { $SessionRequest = $Request; if (!$SessionRequest instanceof ISessionRequest) { throw new \Exception("Session required"); } $Account = AbstractAccountType::loadFromSession($SessionRequest); if ($Account instanceof ResellerAccount) { } else { if ($Account instanceof AdministratorAccount) { } else { throw new RequestException("Only resellers may create a new Account"); } } $accountOptions = array("Choose a Account Type" => null); /** @var AbstractAccountType[] $AccountTypes */ $AccountTypes = array(); $AccountForms = array(); foreach (Types\AbstractAccountType::loadAllAccountTypes() as $AccountType) { $AccountTypes[$AccountType->getTypeName()] = $AccountType; $FieldSet = $AccountType->getFieldSet($Request); $FieldSet->addClass($AccountType::CLS_FIELDSET_CHOOSE_ACCOUNT); $FieldSet->setAttribute('disabled', 'disabled'); $AccountForms[] = $FieldSet; $accountOptions[ucfirst($AccountType->getTypeName())] = $AccountType->getTypeName(); } $Form = new HTMLForm(self::FORM_METHOD, $Request->getPath(), self::FORM_NAME, new HTMLMetaTag(HTMLMetaTag::META_TITLE, self::TITLE), new HTMLHeaderScript(__DIR__ . '/assets/account.js'), new HTMLHeaderStyleSheet(__DIR__ . '/assets/account.css'), new HTMLElement('fieldset', 'fieldset-create-account', new HTMLElement('legend', 'legend-account', self::TITLE), new HTMLElement('label', null, "Choose a Account Type<br/>", new HTMLSelectField(self::PARAM_ACCOUNT_TYPE, $accountOptions, new RequiredValidation())), "<br/><br/>", $AccountForms, "<br/><br/>Submit:<br/>", new HTMLButton('submit', 'Submit', 'submit')), "<br/>"); if (!$Request instanceof IFormRequest) { return $Form; } // $status = $Form->validateField($Request, self::PARAM_ACCOUNT_STATUS); $accountType = $Form->validateField($Request, self::PARAM_ACCOUNT_TYPE); $ChosenAccount = $AccountTypes[$accountType]; $ChosenAccount->validateRequest($Request, $Form); $id = AccountEntry::create($Request, $ChosenAccount); AccountAffiliationEntry::setAffiliate($Request, $Account->getID(), $id, AccountAffiliationEntry::TYPE_RESELLER); return new RedirectResponse(ManageAccount::getRequestURL($id), "Account created successfully. Redirecting...", 5); }