function users_contact_post() { Pie_Session::start(); Pie_Valid::nonce(true); extract($_REQUEST); $user = Users::loggedInUser(); if (!$user) { throw new Users_Exception_NotLoggedIn(); } $app = Pie_Config::expect('pie', 'app'); $subject = "Welcome! Activate your email."; $view = "{$app}/email/setEmail.php"; $fields = array(); $p = array(); $p['subject'] =& $subject; $p['view'] =& $view; $p['fields'] =& $fields; Pie::event('users/setEmail', $p, 'before'); // may change the fields if (isset($first_name)) { $user->first_name = $first_name; } if (isset($last_name)) { $user->last_name = $last_name; } $user->addEmail($_REQUEST['email_address'], $subject, $view, true, $fields); // If no exceptions were throw, save this user row if (isset($first_name) or isset($last_name)) { $user->save(); } }
function users_activate_validate() { $email_address = Pie_Dispatcher::uri()->email_address; $mobile_number = Pie_Dispatcher::uri()->mobile_number; if ($email_address && !Pie_Valid::email($email_address)) { throw new Pie_Exception_WrongValue(array('field' => 'email', 'range' => 'a valid email address'), 'email_address'); } if ($mobile_number && !Pie_Valid::phone($mobile_number)) { throw new Pie_Exception_WrongValue(array('field' => 'mobile phone', 'range' => 'a valid phone number'), 'mobile_number'); } if ($email_address or $mobile_number) { if (empty($_REQUEST['code'])) { throw new Pie_Exception("The activation code is missing"); } } // This is one of the few places where we cheat, // and fill the $_POST array even though it probably wasn't filled. if ($email_address) { $_POST['email_address'] = $email_address; } else { if ($mobile_number) { $_POST['mobile_number'] = $mobile_number; } } }
function users_user_validate() { if (!isset($_REQUEST['email_address'])) { throw new Pie_Exception('email address is missing', array('email_address')); } if (!Pie_Valid::email($_REQUEST['email_address'])) { throw new Pie_Exception('a valid email address is required', array('email_address')); } }
function users_account_post() { Pie_Session::start(); Pie_Valid::nonce(true); extract($_REQUEST); // Implement the action $user = Users::loggedInUser(); if (!$user) { throw new Users_Exception_NotLoggedIn(); } /* if (!isset($gender) and isset($user->gender)) { $gender = $user->gender; } if (isset($orientation)) { if (isset($gender) and $orientation == 'straight') { $desired_gender = ($gender == 'male') ? 'female' : 'male'; } else if (isset($gender) and $orientation == 'gay') { $desired_gender = $gender; } else { $desired_gender = 'either'; } } if (isset($first_name)) $user->first_name = $first_name; if (isset($last_name)) $user->last_name = $last_name; if (isset($gender)) $user->gender = $gender; if (isset($desired_gender)) $user->desired_gender = $desired_gender; if (isset($username)) $user->username = $username; if (isset($relationship_status)) { $user->relationship_status = $relationship_status; } if (isset($birthday_year)) { $user->birthday = date("Y-m-d", mktime( 0, 0, 0, $birthday_month, $birthday_day, $birthday_year )); } if (isset($zipcode)) $user->zipcode = $zipcode; $user->save(true); */ // the $_SESSION['users']['user'] is now altered }
/** * Returns a <style> tag with the content of all the stylesheets included inline * * @param $styles * If not empty, this associative array contains styles which will be * included at the end of the generated <style> tag. * @param string $slot_name * Optional. If provided, returns only the stylesheets added while filling this slot. * * @return string * the style tags and their contents inline */ static function stylesheetsInline($styles = array(), $slot_name = null) { $styles = self::stylesInline($slot_name, false); if (empty($styles) and empty(self::$stylesheets)) { return ''; } $return = "<style type='text/css'>\n"; if (!empty(self::$stylesheets)) { foreach (self::$stylesheets as $stylesheet) { $href = ''; $media = 'screen, print'; $type = 'text/css'; extract($stylesheet, EXTR_IF_EXISTS); $ob = new Pie_OutputBuffer(); if (Pie_Valid::url($href)) { try { include $href; } catch (Exception $e) { } } else { list($href, $filename) = Pie_Html::themedUrlAndFilename($href); try { Pie::includeFile($filename); } catch (Exception $e) { } } $stylesheet = "\n/* Included inline from {$href} */\n" . $ob->getClean(); $return .= "{$stylesheet}\n"; } } $return .= "/* Included inline from Pie_Response::stylesInline() */\n"; $return .= $styles; $return .= "\n</style>"; return $return; }
/** * Gets the url and filename of a themed file * @param string $file_path * Basically the subpath of the file underneath the web or theme directory */ static function themedUrlAndFilename($file_path) { $filename = false; $theme_url = Pie_Uri::url(self::themeUrl()); $theme_urls = Pie_Config::get('pie', 'theme_urls', array(null)); if (!Pie_Valid::url($file_path)) { $c = count($theme_urls); if ($c > 1) { // At least two theme URLs have been loaded // Do the cascade for ($i = $c - 1; $i >= 0; --$i) { try { $filename = Pie_Uri::filenameFromUrl($theme_urls[$i] . '/' . $file_path); } catch (Exception $e) { continue; } if (file_exists($filename)) { $theme_url = $theme_urls[$i]; break; } } } $file_path = $theme_url . '/' . $file_path; } if (empty($filename)) { try { $filename = Pie_Uri::filenameFromUrl($file_path); } catch (Exception $e) { $filename = null; } } return array($file_path, $filename); }
/** * Starts the process of adding a mobile to a saved user object. * Also modifies and saves this user object back to the database. * @param string $mobile_number * The mobile number to add. * @param string $activation_mobile_view * The view to use for the body of the activation mobile to send. * @param boolean $html * Defaults to true. Whether to send as HTML mobile. * @param array $fields * An array of additional fields to pass to the mobile view. * @return boolean * Returns true on success. * Returns false if this mobile number is already verified for this user. * @throws Pie_Exception_WrongType * If the mobile number is in an invalid format, this is thrown. * @throws Users_Exception_AlreadyVerified * If the mobile number already exists and has been verified for * another user, then this exception is thrown. */ function addMobile($mobile_number, $activation_mobile_subject = null, $activation_mobile_view = null, $html = true, $fields = array()) { // TODO: Implement Users_Mobile::sendMessage if (!Pie_Valid::mobile($mobile_number)) { throw new Pie_Exception_WrongValue(array('field' => 'Mobile phone', 'range' => 'a valid number'), 'mobile_number'); } Pie::event('users/validate/mobile_number', array('mobile_number' => &$mobile_number)); $m = new Users_Mobile(); $m->number = $mobile_number; if ($m->retrieve() and $m->state !== 'unverified') { if ($m->user_id === $this->id) { return false; } // Otherwise, say it's verified for another user, // even if it unsubscribed or was suspended. throw new Users_Exception_AlreadyVerified(array('key' => $m->number, 'user_id' => $m->user_id), 'mobile_number'); } // If we are here, then the mobile record either // doesn't exist, or hasn't been verified yet. // In either event, update the record in the database, // and re-send the mobile. $minutes = Pie_Config::get('users', 'activationCodeExpires', 60 * 24 * 7); $m->state = 'unverified'; $m->user_id = $this->id; $m->activation_code = Pie_Utils::unique(5); $m->activation_code_expires = new Db_Expression("CURRENT_TIMESTAMP + INTERVAL {$minutes} MINUTE"); $m->auth_code = md5(microtime() + mt_rand()); $m->save(); if (!isset($activation_message_view)) { $activation_message_view = Pie_Config::get('users', 'activationMessageView', 'users/message/activation.php'); } $fields2 = array_merge($fields, array('user' => $this, 'message' => $m)); $m->sendMessage($activation_mobile_view, $fields2, array('html' => $html)); Pie::event('users/addMobile', compact('mobile_number'), 'after'); }
/** * Returns what the local filename of a local URL would typically be without any routing. * If not found under docroot, also checks various aliases. * * @param string $url * The url to translate, whether local or an absolute url beginning with the base URL * @return string * The complete filename of the file or directory. * It may not point to an actual file or directory, so use file_exists() or realpath();s */ static function filenamefromUrl($url) { if (Pie_Valid::url($url)) { // This is an absolute URL. Get only the part after the base URL // Run it through proxies first $url = self::proxyDestination($url); $local_url = Pie_Request::tail($url); } else { $local_url = $url; } $parts = explode('?', $local_url); $local_url = $parts[0]; if ($local_url == '' || $local_url[0] != '/') { $local_url = '/' . $local_url; } // Try various aliases first $aliases = Pie_Config::get('pie', 'aliases', array()); foreach ($aliases as $alias => $path) { $alias_len = strlen($alias); if (substr($local_url, 0, $alias_len) == $alias) { return $path . substr($local_url, $alias_len); } } // Otherwise, we should use the document root. $docroot_dir = self::documentRoot(); return $docroot_dir . $local_url; }