public function searchUser($where) { global $dRep; $where = $this->sqlBuilder->createWhere($where, 'A', false); $sql = "SELECT A.* FROM ink_user A\n\t\t\t\tWHERE {$where};"; $row = $this->runSingleQuery($sql); if (!isset($row['userId'])) { throw new DataException('nouser_fromsql'); } $properties = array('id' => $row['userId'], 'username' => $row['username'], 'password' => $row['password'], 'email' => $row['email'], 'firstname' => $row['firstname'], 'lastname' => $row['lastname'], 'customer' => $dRep->getCustomer($row['customerId']), 'roles' => $dRep->getRoleCollection(array('userId' => $row['userId'])), 'sites' => $dRep->getSiteCollection(array('userId' => $row['userId'])), 'modules' => $dRep->getModuleCollection(array('userId' => $row['userId'], 'parent' => 0))); $user = new User(); $user->setProperties($properties); $user->setActive($row['active']); $this->users[$row['userId']] = $user; return $user; }
public function Signup() { global $varChecker; if ($varChecker->getValue('Password') != $varChecker->getValue('PasswordRepeat')) { throw new DataException('passwordnotmatching'); } $customerProperties = array('name' => $varChecker->getValue('Company'), 'timezone' => $varChecker->getValue('Timezone'), 'newsletter' => $varChecker->getValue('Newsletter') == 'on', 'subdomain' => $varChecker->getValue('Subdomain')); $userProperties = array('username' => $varChecker->getValue('Username'), 'password' => $varChecker->getValue('Password'), 'email' => $varChecker->getValue('Email'), 'firstname' => $varChecker->getValue('Firstname'), 'lastname' => $varChecker->getValue('Lastname'), 'active' => true); $unique = $this->CheckUniqueFields('subdomain', $customerProperties['subdomain']); if (!$unique['unique']) { throw new DataException('subdomainnotunique'); } $this->checkproperties($customerProperties); $this->checkproperties($userProperties); $customer = new Customer(); $customer->setProperties($customerProperties); $user = new User(); $userProperties['customer'] = $customer; $user->setProperties($userProperties); //create the user in whcms $whcms = new WHCMS("https://myaccount.inkagency.com.au/includes/api.php", "apiadmin", "p1x37cm5"); $whcmsId = $whcms->CreateClient($user); //save customer to get Id $customer = $this->dRep->saveCustomer($customer); //set customer again and whcmsid $userProperties['whcmsId'] = $whcmsId; $userProperties['customer'] = $customer; $user->setProperties($userProperties); //add the pixelcms whcms product to the user $result = $whcms->AddProducToCustomer($user); //save user $user = $this->dRep->saveUser($user); $users = array($user); $modules = $this->dRep->getModuleCollection(array('customer' => $customer->getId())); $group = new Role(); $properties = array('name' => 'Administrators', 'description' => 'Full Access Administrator role', 'customer' => $customer->getId(), 'users' => array($user->getId() => true)); $group->setProperties($properties); foreach ($modules as $module) { $group->setAccess($module, true); foreach ($module->getKids() as $index => $kid) { $group->setAccess($kid, true); } } $group = $this->dRep->saveRole($group); }
static function load() { if (!empty(self::$user)) { return self::$user; } elseif (!empty($_SESSION[self::SESSION_KEY])) { $pdo = DataSource::load(); $statement = 'SELECT * FROM User WHERE secret = :secret LIMIT 1'; $preparedStatement = $pdo->prepare($statement); $preparedStatement->execute(array('secret' => $_SESSION[self::SESSION_KEY])); $userData = $preparedStatement->fetch(); if (!empty($userData)) { $user = new User(); $user->setProperties($userData); self::$user = $user; return self::$user; } } return false; }
private function getUser() { global $varChecker; try { if ($varChecker->getValue('id') == 'new') { $user = new User(); $user->setProperties(array('id' => 'new')); return $user; } $user = $this->dRep->getUser($varChecker->getValue('id')); return $user; } catch (DataException $e) { return $this->INK_User; } }
/** * Updates a user * * @param int $intId The user ID * @param array $arrData The data array * @throws Exception * @return int The user ID */ public function do_update($intId = null, $arrData) { $user = null; $con = Propel::getConnection(); if (!$con->beginTransaction()) { throw new Exception('Could not start transaction.'); } try { $authUser = $this->requireUser(); $accountId = $authUser->getAccountId(); $validator = new KickstartValidator(); $locale = Localizer::getInstance(); if ($intId and (!isset($arrData['Password']) or $arrData['Password'] == '')) { unset($this->filter_basic['Password']); unset($arrData['Password']); unset($arrData['Password2']); } $warnings = $validator->filterErrors($arrData, $this->initFilter($this->filter_basic, $locale)); if ($warnings) { return array('result' => false, 'warnings' => $warnings); } if ($intId) { $user = $authUser->getSubordinate($intId); } else { $user = new User(); $user->setAccountId($accountId)->setDomainId($authUser->getDomainId()); } if (isset($arrData['Password'])) { $user->setPassword($arrData['Password']); } $allowedFields = array('Name' => true, 'Firstname' => true, 'Lastname' => true, 'Phone' => true, 'Email' => true, 'Number' => true); if ($authUser->getIsAdmin()) { $allowedFields += array('DomainId' => true, 'ManagerOf' => true, 'IsAdmin' => true); } $user->fromArray(array_intersect_key($arrData, $allowedFields)); // Fail if domain does not belong to authenticated account $domain = $user->getDomain($con); if ($domain === null or $domain->getAccountId() !== $accountId) { throw new Exception('Invalid domain ID #' . $user->getDomainId()); } $user->save($con); if (!empty($arrData['Properties'])) { $user->setProperties($arrData['Properties'], $con); } } catch (Exception $e) { $con->rollBack(); throw $e; } if (!$con->commit()) { throw new Exception('Could not commit transaction.'); } return $user->getId(); }
public function testSetAttributes() { $this->object->setProperties(array('info' => 'nearly nothing')); $this->assertThat($this->object->getProperties(), $this->equalTo(array('info' => 'nearly nothing'))); }