http://dev."xxxxxyyyyy".com/xxxxx-community/register.html?&invite=5000
I need to store this id ($invite=5000) in a variable called $fromid using session.There are two functions in /components/com_community/controllers/register.php
Where should I call this and how??
class CommunityRegisterController extends CommunityBaseController
{
public function register()
{
}
another one
public function register_save()
{
$mainframe =& JFactory::getApplication();
$modelRegister = CFactory::getModel('register');
// Check for request forgeries
$mySess =& JFactory::getSession();
if(! $mySess->has('JS_REG_TOKEN'))
{
echo '<div class="error-box">' . JText::_('COM_COMMUNITY_INVALID_SESSION') . '</div>';
return;
}
$token = $mySess->get('JS_REG_TOKEN','');
$ipAddress = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
$authKey = $modelRegister->getAssignedAuthKey($token, $ipAddress);
$formToken = JRequest::getVar( 'authkey', '', 'REQUEST');
if(empty($formToken) || empty($authKey) || ($formToken != $authKey))
{
//echo $formToken .'|'. $authKey;
echo '<div class="error-box">' . JText::_('COM_COMMUNITY_INVALID_TOKEN') . '</div>';
return;
}
//update the auth key life span to another 180 sec.
$modelRegister->updateAuthKey ($token, $authKey, $ipAddress);
// Get required system objects
$config = CFactory::getConfig();
$post = JRequest::get('post');
// If user registration is not allowed, show 403 not authorized.
$usersConfig = &JComponentHelper::getParams( 'com_users' );
if ($usersConfig->get('allowUserRegistration') == '0')
{
//show warning message
$view =& $this->getView('register');
$view->addWarning(JText::_( 'COM_COMMUNITY_REGISTRATION_DISABLED' ));
echo $view->get('register');
return;
}
Can i access that $fromid in components/com_users/controllers/registration.php that uses the class
class UsersControllerRegistration extends UsersController
{
}
You can use GET method to get the value , then store it in session variable,
Eg:
$_SESSION['fromid'] = $_GET['invite'];
$fromid = $_SESSION['fromid'];
Related
I' am trying this from yesterday but can't find any resources to help me out. I' am building my own custom MVC for learning purpose. I' am stuck at a point where when a uri is not registered in the router class, it should throw in a 404 error message. I have tried a lot of tricks but nothing worked for me.
router.php
$router->get('', 'homeController#index', 'home');
$router->get('contact', 'contactController#index', 'contact');
$router->get('contact/locations', 'contactController#locations', 'contact');
controller.class.php
class Controller{
public function controller($ContollerMethod = null){
$contoller = explode('#', $ContollerMethod);
if( !empty($contoller[0]) ){
return $contoller[0];
}
}
public function method($ContollerMethod = null){
$method = explode('#', $ContollerMethod);
if( !empty($method[1]) ){
return $method[1];
}
}
public function view($view = null){
if( empty($view) ){
$view = 'page';
}
$file = site_path() . '/app/views/' . $view . '.php';
require_once($file);
}
public function render($ContollerMethod = null, $view = null, $data = array() ){
$controller = $this->controller($ContollerMethod);
$method = $this->method($ContollerMethod);
if( file_exists(site_path() . '/app/controllers/' . $controller . '.php') ){
require_once(site_path() . '/app/controllers/' . $controller . '.php');
if( !method_exists($controller, $method) ){
die('No method \'<em>' . $method . '</em>\' exists on Controller \'<em>' . $controller . '</em>\'');
}
$params = array();
call_user_func_array( [$controller, $method], $params );
$master = site_path() . '/app/views/master.php';
if( file_exists($master) ){
require_once( site_path() . '/app/views/master.php');
}
} else {
die('Controller \'<em>' . $controller . '</em>\' doesn\'t exists');
}
}
}
router.class.php
class Router extends Controller{
public function get($uri = null, $ContollerMethod = null, $view = null){
$permalink = get_permalink();
if( $permalink == $uri and strtolower($_SERVER['REQUEST_METHOD']) == 'get' ){
$this->render($ContollerMethod, $view);
}
}
public function post($uri = null, $ContollerMethod = null, $view = null){
$permalink = get_permalink();
if( $permalink == $uri and strtolower($_SERVER['REQUEST_METHOD']) == 'post' ){
}
}
public function ajax($uri = null, $ContollerMethod = null, $view = null){
$permalink = get_permalink();
if( $permalink == $uri and !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){
}
}
}
$router = new Router;
Example:
contact, contact/locations are registed in the router.class.php so there is no problem and everything works fine, but the uri errorexample is not registered and it should show 404 error message from the views.
Please any help.
basic solution (but not the best) is add a return value (boolean) for Router::get(). The value returned is true if the route was handled and false if the route is not handled
router.php
// route handlers found
$founded = 0;
if( $router->get('', 'homeController#index', 'home') ){
$founded++;
}
if( $router->get('contact', 'contactController#index', 'contact') ){
$founded++;
}
if( $router->get('contact/locations', 'contactController#locations', 'contact') ){
$founded++;
}
// no handlers found... the route is handled by error controller
if( $founded <= 0 ){
$router->get('404', 'errorController#index', '404');
}
controller.class.php
class Router extends Controller{
/**
* Return true if a controller is found for handle the route
* #return boolean
*/
public function get($uri = null, $ContollerMethod = null, $view = null){
$permalink = get_permalink();
if( $permalink == $uri and strtolower($_SERVER['REQUEST_METHOD']) == 'get' ){
return $this->render($ContollerMethod, $view); // return true if a controller and a view are found
}
return false; // added this line
}
//.............
implement same loginc in controller::render()
controller.class.php
class Controller{
/**
* Return true if a controller is found
* #return boolean
*/
public function render($ContollerMethod = null, $view = null, $data = array() ){
$controller = $this->controller($ContollerMethod);
$method = $this->method($ContollerMethod);
if( file_exists(site_path() . '/app/controllers/' . $controller . '.php') ){
require_once(site_path() . '/app/controllers/' . $controller . '.php');
if( !method_exists($controller, $method) ){
die('No method \'<em>' . $method . '</em>\' exists on Controller \'<em>' . $controller . '</em>\'');
}
$params = array();
call_user_func_array( [$controller, $method], $params );
$master = site_path() . '/app/views/master.php';
if( file_exists($master) ){
require_once( site_path() . '/app/views/master.php');
}
return true; // add this line
} else {
die('Controller \'<em>' . $controller . '</em>\' doesn\'t exists');
}
return false; // add this line
}
// .....................................
now... my two cents
in your logic each router was called every time even if a controller is found. One optimization is stop this process if a controller was found, eg.:
router.php
if( $router->get('', 'homeController#index', 'home') ){
exit;
}
if( $router->get('contact', 'contactController#index', 'contact') ){
exit;
}
if( $router->get('contact/locations', 'contactController#locations', 'contact') ){
exit;
}
// no handlers found... the route is handled by error controller
$router->get('404', 'errorController#index', '404');
Side note: this a "spaghetti code" solution and sorry for my very bad english :(
This is my code
class WcfClient {
public $wcfClient = null;
public $user = null;
public function __construct(){
if(isset($_SESSION['APIClient']) && $_SESSION['APIClient'] != null){
$this->wcfClient = $_SESSION['APIClient'];
}
}
public function __destruct(){
}
// Authanticate
private function Authenticate(){
global $_sogh_soapUrl, $_isDebug, $_sogh_header;
$wcargs = array();
$consumerAuthTicket = null;
if($this->wcfClient == null){
$args = array(
'clubname'=>'Wellness Institute at Seven Oaks',
'consumerName'=>'api',
'consumerPassword'=>'api'
);
try{
$wcargs = array(
'soap_version'=>SOAP_1_2
);
if($_isDebug){
$wcargs = array(
'soap_version'=>SOAP_1_2,
'proxy_host'=>"192.168.0.1",
'proxy_port'=>8080
);
}
// Connect to the API with soapclient
$soapAPIClient = new SoapClient($_sogh_soapUrl, $wcargs);
$response = $soapAPIClient->AuthenticateClubConsumer($args);
if(isset($response->AuthenticateClubConsumerResult)){
if(isset($response->AuthenticateClubConsumerResult->IsException) && $response->AuthenticateClubConsumerResult->IsException == true){
// some error occur
$this->wcfClient = null;
$_SESSION['APIClient'] = $this->wcfClient;
} else{
// set consumer ticket
$consumerAuthTicket = $response->AuthenticateClubConsumerResult->Value->AuthTicket;
// $loginData = $responseCode->ReturnValueOfConsumerLoginData;
$headers = array();
$headers[] = new SoapHeader($_sogh_header, "ConsumerAuthTicket", $consumerAuthTicket);
$soapAPIClient->__setSoapHeaders($headers);
// add to session
$this->wcfClient = $soapAPIClient;
$_SESSION['APIClient'] = $this->wcfClient;
}
}
} catch(SoapFault $fault){
$this->error('Fault: ' . $fault->faultcode . ' - ' . $fault->faultstring);
} catch(Exception $e){
$this->error('Error: ' . $e->getMessage());
}
}
return $this->wcfClient;
}
I store the soap client object in $_SESSION['APIClient'], but second times when run some data has been changed in session, I am use this class in drupal 7, I want to save the time using session, because authenticating takes long time.
Please help
Thank in advance
This is my code: I want to update the User information and risk factors.
public function getUserById($id)
{
$user = $this->_xml->xpath('//user[#id="' . $id . '"]');
return $user[0];
}
public function updateUser($post)
{
$user = $this->_xml->xpath('//user[#id="' . $post['id'] . '"]');
$user[0]->name= $post["name"];
$user[0]->date_of_birth= $post["date_of_birth"];
$user[0]->sex= $post["sex"];
$user[0]->age= $post["age"];
$this->_xml->asXML($this->path);
}
public function updateFactors($post)
{
$user = $this->_xml->xpath('//user[#id="' . $post['id'] . '"]');
//$user=new stdClass();
$user[0]->alcohol= $post["alcohol"]; // error here!
$user[0]->percentage= $post["percentage"];
$this->_xml->asXML($this->path);
}
if ($param == "edit") {
$id = $arr[1];
$user = $process->getUserById($id);
include 'myuser2.php';
if ($param == "update") {
$post = $_POST;
$process->updateUser($post);
include 'mylistar.php';
$process->listUsers();
}
if ($param == "editfactors") {
$id = $arr[1];
$user = $process->getUserById($id);
include'factors.php';
}
if($param == "updatefactors"){
$post = $_POST;
$process->updateFactors($post);
include 'mylistar.php';
$process->listUsers();
}
So, the "update", "edit", the updateUser function is working... But the Factors part is not! The code is pretty much the same and I donĀ“t know what I'm doing wrong... Seems logic to me.
Error : Creating default object from empty value (in line
$user[0]->alcohol= $post["alcohol"]; )
I've searched and tried $user=new stdClass(); but it doesn't work:
Error: Cannot use object of type stdClass as array
Can you help? :/
{"Dina-Kar":{"com":"available"},"DinaKarPool":{"com":"available"},"DinaKarStore":{"com":"available"},"DinaKarOnline":{"com":"available"},"DinaKarParts":{"com":"available"},"DinaKarJack":{"com":"available"},"DinaKarTunes":{"com":"available"},"DinaKarSmart":{"com":"available"},"DinaKarWash":{"com":"available"},"DinaKarRound":{"com":"available"}}
I need the out put as Dina-Kar.com is available.And need to run the loop Dynamically using PHP script for all the available values.
Can you please help me like that out put.
Live at codepad
The class:
class DomainChecker
{
private $domains;
public function __construct( $domainlist )
{
$this->domains = json_decode( $domainlist );
}
public function Exists( $domain, $tld )
{
return
isset($this->domains->$domain) &&
isset($this->domains->$domain->$tld) &&
$this->domains->$domain->$tld != 'available';
}
public function ListAll()
{
$result = '';
foreach($this->domains as $domainname => $domain)
foreach($domain as $tldname => $tld)
$result .= "$domainname.$tldname\t$tld\n";
return $result;
}
}
Usage:
$domainchecker = new DomainChecker('{"Dina-Kar":{"com":"available"},"DinaKarPool":{"com":"available"},"DinaKarStore":{"com":"available"},"DinaKarOnline":{"com":"available"},"DinaKarParts":{"com":"available"},"DinaKarJack":{"com":"available"},"DinaKarTunes":{"com":"available"},"DinaKarSmart":{"com":"available"},"DinaKarWash":{"com":"available"},"DinaKarRound":{"com":"available"}}');
$domain = 'Pome-Tek';
$tld = 'com';
if( $domainchecker->Exists( $domain, $tld ))
echo "$domain.$tld is not available\n\n";
else
echo "$domain.$tld is available\n\n";
echo $domainchecker->ListAll();
Output:
Pome-Tek.com is available
Dina-Kar.com available
DinaKarPool.com available
DinaKarStore.com available
DinaKarOnline.com available
DinaKarParts.com available
DinaKarJack.com available
DinaKarTunes.com available
DinaKarSmart.com available
DinaKarWash.com available
DinaKarRound.com available
I cant get this script to work, $users should hold the array data we take out of the database but it doesnt seem to work. Can anyone tell us what we are doing wrong? i posted the script bellow.
added
$users has to stay static becaus it gets used again later on in the script (this is just a small part)
$user1 does get the right data it just doesnt get passed on to $users
added
this is the intire script hope that helps
<?php
class SingleSignOn_Server
{
public $links_path;
protected $started=false;
protected static $brokers = array(
'FGPostbus' => array('secret'=>"FGPostbus123"),
);
protected static $users = array();
public function query_personen(){
mysql_connect('host','user','pass') or die("Kan helaas geen verbinding maken" . mysql_error());
mysql_select_db('db') or die("Kan geen database selecteren");
$sql = mysql_query('select p_gebruikersnaam, p_wachtwoord, p_id, p_md5 FROM personen');
while ($row_user = mysql_fetch_assoc($sql)) {
self::$users[] = $row_user;
}
}
protected $broker = null;
public function __construct()
{
if (!function_exists('symlink')) $this->links_path = sys_get_temp_dir();
}
protected function sessionStart()
{
if ($this->started) return;
$this->started = true;
$matches = null;
if (isset($_REQUEST[session_name()]) && preg_match('/^SSO-(\w*+)-(\w*+)-([a-z0-9]*+)$/', $_REQUEST[session_name()], $matches)) {
$sid = $_REQUEST[session_name()];
if (isset($this->links_path) && file_exists("{$this->links_path}/$sid")) {
session_id(file_get_contents("{$this->links_path}/$sid"));
session_start();
setcookie(session_name(), "", 1);
} else {
session_start();
}
if (!isset($_SESSION['client_addr'])) {
session_destroy();
$this->fail("Not attached");
}
if ($this->generateSessionId($matches[1], $matches[2], $_SESSION['client_addr']) != $sid) {
session_destroy();
$this->fail("Invalid session id");
}
$this->broker = $matches[1];
return;
}
session_start();
if (isset($_SESSION['client_addr']) && $_SESSION['client_addr'] != $_SERVER['REMOTE_ADDR']) session_regenerate_id(true);
if (!isset($_SESSION['client_addr'])) $_SESSION['client_addr'] = $_SERVER['REMOTE_ADDR'];
}
protected function generateSessionId($broker, $token, $client_addr=null)
{
if (!isset(self::$brokers[$broker])) return null;
if (!isset($client_addr)) $client_addr = $_SERVER['REMOTE_ADDR'];
return "SSO-{$broker}-{$token}-" . md5('session' . $token . $client_addr . self::$brokers[$broker]['secret']);
}
protected function generateAttachChecksum($broker, $token)
{
if (!isset(self::$brokers[$broker])) return null;
return md5('attach' . $token . $_SERVER['REMOTE_ADDR'] . self::$brokers[$broker]['secret']);
}
public function login()
{
$this->sessionStart();
if (empty($_POST['p_gebruikersnaam'])) $this->failLogin("No user specified");
if (empty($_POST['p_wachtwoord'])) $this->failLogin("No password specified");
if (!isset(self::$users[$_POST['p_gebruikersnaam']]) || self::$users[$_POST['p_gebruikersnaam']]['p_wachtwoord'] != md5($_POST['p_wachtwoord'])) $this->failLogin("Incorrect credentials");
$_SESSION['user'] = $_POST['p_gebruikersnaam'];
$this->info();
}
public function logout()
{
$this->sessionStart();
unset($_SESSION['user']);
echo 1;
}
public function attach()
{
$this->sessionStart();
if (empty($_REQUEST['broker'])) $this->fail("No broker specified");
if (empty($_REQUEST['token'])) $this->fail("No token specified");
if (empty($_REQUEST['checksum']) || $this->generateAttachChecksum($_REQUEST['broker'], $_REQUEST['token']) != $_REQUEST['checksum']) $this->fail("Invalid checksum");
if (!isset($this->links_path)) {
$link = (session_save_path() ? session_save_path() : sys_get_temp_dir()) . "/sess_" . $this->generateSessionId($_REQUEST['broker'], $_REQUEST['token']);
if (!file_exists($link)) $attached = symlink('sess_' . session_id(), $link);
if (!$attached) trigger_error("Failed to attach; Symlink wasn't created.", E_USER_ERROR);
} else {
$link = "{$this->links_path}/" . $this->generateSessionId($_REQUEST['broker'], $_REQUEST['token']);
if (!file_exists($link)) $attached = file_put_contents($link, session_id());
if (!$attached) trigger_error("Failed to attach; Link file wasn't created.", E_USER_ERROR);
}
if (isset($_REQUEST['redirect'])) {
header("Location: " . $_REQUEST['redirect'], true, 307);
exit;
}
header("Content-Type: image/png");
readfile("empty.png");
}
public function info()
{
$this->sessionStart();
if (!isset($_SESSION['user'])) $this->failLogin("Not logged in");
header('Content-type: text/xml; charset=UTF-8');
echo '<?xml version="1.0" encoding="UTF-8" ?>', "\n";
echo '<user identity="' . htmlspecialchars($_SESSION['user'], ENT_COMPAT, 'UTF-8') . '">';
echo ' <p_id>' . htmlspecialchars(self::$users[$_SESSION['user']]['p_id'], ENT_COMPAT, 'UTF-8') . '</p_id>';
echo ' <p_md5>' . htmlspecialchars(self::$users[$_SESSION['user']]['p_md5'], ENT_COMPAT, 'UTF-8') . '</p_md5>';
echo '</user>';
}
protected function fail($message)
{
header("HTTP/1.1 406 Not Acceptable");
echo $message;
exit;
}
protected function failLogin($message)
{
header("HTTP/1.1 401 Unauthorized");
echo $message;
exit;
}
}
if (realpath($_SERVER["SCRIPT_FILENAME"]) == realpath(__FILE__) && isset($_GET['cmd'])) {
$ctl = new SingleSignOn_Server();
$ctl->$_GET['cmd']();
}
At the very least you probably want to:
self::$users[] = $users1[$row_user['p_gebruikersnaam']] = $row_user;
Since as is you where replacing the record every time and keeping only one.
You're building an array as a property of an object, but not using an instance of the object. You need to build a new instance ($usersObject = new ObjectName;), drop the static keywords, and instead of self::, use $this->. You also need square brackets after self::$users, like this: self::$users[].
Shouldn't this self::$users = $users1[$row_user['p_gebruikersnaam']] = $row_user; be:
array_push($this->users, $row_user)
You could put directly the result into the array:
while (false === ($row_user = mysql_fetch_array($sql, MYSQL_ASSOC)))
self::$users[$row_user['p_gebruikersnaam']] = $row_user;