static function create($values = array()) { $email_counter = self::$email_counter += 1; $values = array_merge(array('email' => "test-email-{$email_counter}@example.org", 'salt' => '1234abcd', 'pass' => '1234abcd', 'first_name' => 'John', 'last_name' => 'Connor', 'api_key' => '1234abcd'), $values); $dao = new Users_UserDao(Database::obtain()); $userStruct = new Users_UserStruct($values); return $dao->createUser($userStruct); }
/** * Class constructor * * @param bool $isAuthRequired */ public function __construct($isAuthRequired = false) { if (!parent::isRightVersion()) { header("Location: " . INIT::$HTTPHOST . INIT::$BASEURL . "badConfiguration", true, 303); exit; } //SESSION ENABLED parent::sessionStart(); //load Template Engine require_once INIT::$ROOT . '/inc/PHPTAL/PHPTAL.php'; $this->supportedBrowser = $this->isSupportedWebBrowser(); //try to get user name from cookie if it is not present and put it in session if (empty($_SESSION['cid'])) { //log::doLog(get_class($this)." requires check for login"); $username_from_cookie = AuthCookie::getCredentials(); if ($username_from_cookie) { $_SESSION['cid'] = $username_from_cookie['username']; $_SESSION['uid'] = $username_from_cookie['uid']; } } //even if no login in required, if user data is present, pull it out if (!empty($_SESSION['cid'])) { $userSearch = new Users_UserStruct(); $userSearch->email = $_SESSION['cid']; $userDao = new Users_UserDao(Database::obtain()); $userObject = $userDao->read($userSearch); /** * @var $userObject Users_UserStruct */ $userObject = $userObject[0]; // $this->logged_user = getUserData( $_SESSION[ 'cid' ] ); $this->logged_user = $userObject; } if ($isAuthRequired) { //if auth is required, stat procedure $this->doAuth(); } }
$options = getopt('h', array('email:', 'feature:')); if (array_key_exists('h', $options)) { usage(); } if (empty($options)) { usage(); } if (!array_key_exists('email', $options)) { usage(); } if (!array_key_exists('feature', $options)) { usage(); } if (!validateFeature($options['feature'])) { usage(); } $dao = new Users_UserDao(Database::obtain()); $result = $dao->read(new Users_UserStruct(array('email' => $options['email']))); $user = $result[0]; $dao = new OwnerFeatures_OwnerFeatureDao(Database::obtain()); $values = array('uid' => $user->uid, 'feature_code' => $options['feature'], 'options' => '{}', 'enabled' => true); $insert = $dao->create(new OwnerFeatures_OwnerFeatureStruct($values)); echo <<<END Record added for user {$user->email}: FEATURE CODE: {$insert->feature_code} ENABLED: {$insert->enabled} END ;
public function getUser() { $dao = new Users_UserDao(Database::obtain()); $user = $dao->getByUid($this->uid); return $user; }
private function loadUser() { $userStruct = new Users_UserStruct(); $userStruct->uid = $this->uid; $userDao = new Users_UserDao(Database::obtain()); $result = $userDao->read($userStruct); if (empty($result)) { throw new Exception("User not found by UID."); } $this->current_user = $result[0]; }