Example #1
0
File: Facade.php Project: rjha/sc
 function execute($endPoint, $params)
 {
     $command = NULL;
     $hash = md5($endPoint);
     if (!isset($this->map[$hash])) {
         // end point is not mapped
         $message = sprintf("end point [%s] is not mapped for session action", $endPoint);
         Logger::getInstance()->info($message);
         return;
     }
     //end point is mapped.
     $name = $this->map[$hash];
     switch ($name) {
         case "COMMENT":
             $command = new \com\indigloo\sc\command\Comment();
             break;
         case "BOOKMARK":
             $command = new \com\indigloo\sc\command\Bookmark();
             break;
         case "GRAPH":
             $command = new \com\indigloo\sc\command\SocialGraph();
             break;
         default:
             //coding error.
             $message = sprintf("Unknown session action  [%s] for endpoint [%s]", $name, $endPoint);
             trigger_error($message, E_USER_ERROR);
     }
     $response = $command->execute($params);
     return $response;
 }
Example #2
0
File: Graph.php Project: rjha/sc
 static function getIdOnName($name)
 {
     if (empty($name)) {
         return NULL;
     }
     $graphUrl = sprintf("https://graph.facebook.com/%s", $name);
     $response = @file_get_contents($graphUrl);
     $fbObject = json_decode($response);
     if ($fbObject === FALSE || $fbObject === TRUE || $fbObject == NULL) {
         $message = sprintf("Graph URL %s returned TRUE|FALSE|NULL", $graphUrl);
         Logger::getInstance()->error($message);
         return NULL;
     }
     if (property_exists($fbObject, "error")) {
         $message = sprintf("Graph URL %s returned error", $graphUrl);
         Logger::getInstance()->error($message);
         Logger::getInstance()->error($fbObject->error);
         return NULL;
     }
     if (property_exists($fbObject, "id")) {
         return $fbObject->id;
     } else {
         $message = sprintf("Graph URL %s returned No ID", $graphUrl);
         Logger::getInstance()->error($message);
         return NULL;
     }
 }
Example #3
0
 function destroy($sessionId)
 {
     if (Config::getInstance()->is_debug()) {
         $message = sprintf("session_destroy : %s ", $sessionId);
         Logger::getInstance()->debug($message);
     }
     $key = $this->makeKey($sessionId);
     $this->redis->del($key);
 }
Example #4
0
 private function initDataBase()
 {
     $this->mysqli = new \mysqli(Config::getInstance()->get_value("mysql.host"), Config::getInstance()->get_value("mysql.user"), Config::getInstance()->get_value("mysql.password"), Config::getInstance()->get_value("mysql.database"));
     if (mysqli_connect_errno()) {
         trigger_error(mysqli_connect_error(), E_USER_ERROR);
         exit(1);
     }
     $this->connxId = spl_object_hash($this->mysqli);
     if (Config::getInstance()->is_debug()) {
         $message = '>> mysql created connection_id ::' . $this->connxId;
         Logger::getInstance()->debug($message);
     }
 }
Example #5
0
 static function executeSQL($mysqli, $sql)
 {
     if (Config::getInstance()->is_debug()) {
         Logger::getInstance()->debug("execute SQL >> " . $sql);
     }
     $stmt = $mysqli->prepare($sql);
     if ($stmt) {
         $stmt->execute();
         $stmt->close();
     } else {
         throw new DBException($mysqli->error, $mysqli->errno);
     }
 }
Example #6
0
File: Post.php Project: rjha/sc
 /**
  * @error if links json is empty or spaces in DB column
  * @error if links json evaluates to NULL by json_decode
  * @error if links json is valid but not an array
  * @return an array of strings (links)
  *
  */
 function getLinkDataOnId($postId)
 {
     $row = mysql\Post::getLinkDataOnId($postId);
     $json = $row['json'];
     $links = NULL;
     if (!Util::tryEmpty($json)) {
         $links = json_decode($json);
     }
     if (is_null($links) || !is_array($links)) {
         $message = sprintf("Post %d has Bad json [ %s ] ", $postId, $json);
         Logger::getInstance()->error($message);
         $links = NULL;
     }
     $data = array('links' => $links, 'version' => $row['version']);
     return $data;
 }
Example #7
0
File: Google.php Project: rjha/sc
 function getOrCreate($googleId, $email, $name, $firstName, $lastName, $photo)
 {
     $loginId = NULL;
     //is existing record?
     $googleId = trim($googleId);
     $remoteIp = \com\indigloo\Url::getRemoteIp();
     $row = $this->getOnId($googleId);
     if (empty($row)) {
         $message = sprintf("Login::Google::create id %s, email %s ", $googleId, $email);
         Logger::getInstance()->info($message);
         $provider = \com\indigloo\sc\auth\Login::GOOGLE;
         $loginId = mysql\Google::create($googleId, $email, $name, $firstName, $lastName, $photo, $provider, $remoteIp);
     } else {
         //found
         $loginId = $row['login_id'];
     }
     return $loginId;
 }
Example #8
0
File: Twitter.php Project: rjha/sc
 function getOrCreate($twitterId, $name, $screenName, $location, $image)
 {
     $loginId = NULL;
     //is existing record?
     $twitterId = trim($twitterId);
     $remoteIp = \com\indigloo\Url::getRemoteIp();
     $row = $this->getOnTwitterId($twitterId);
     if (empty($row)) {
         $message = sprintf("Login::Twitter::create id %s ,name %s, screenname %s ", $twitterId, $name, $screenName);
         Logger::getInstance()->info($message);
         $provider = \com\indigloo\sc\auth\Login::TWITTER;
         $loginId = mysql\Twitter::create($twitterId, $name, $screenName, $location, $image, $provider, $remoteIp);
     } else {
         //found
         $loginId = $row['login_id'];
     }
     return $loginId;
 }
Example #9
0
File: Facebook.php Project: rjha/sc
 function getOrCreate($facebookId, $name, $firstName, $lastName, $link, $gender, $email, $access_token, $expires)
 {
     $loginId = NULL;
     //is existing record?
     $facebookId = trim($facebookId);
     $remoteIp = \com\indigloo\Url::getRemoteIp();
     $row = $this->getOnFacebookId($facebookId);
     if (empty($row)) {
         $message = sprintf("Login::Facebook::create id %s, email %s ", $facebookId, $email);
         Logger::getInstance()->info($message);
         //create login + facebook user
         $provider = \com\indigloo\sc\auth\Login::FACEBOOK;
         $loginId = mysql\Facebook::create($facebookId, $name, $firstName, $lastName, $link, $gender, $email, $provider, $access_token, $expires, $remoteIp);
     } else {
         //found
         $loginId = $row["login_id"];
     }
     return $loginId;
 }
Example #10
0
 function persist($prefix, $name, $sBlobData, $headers = array())
 {
     //create a unique name for s3 store
     $storeName = \com\indigloo\media\FileStore::getHashedName($name);
     $storeName = $prefix . $storeName;
     $bucket = Config::getInstance()->get_value("aws.bucket");
     $awsKey = Config::getInstance()->get_value("aws.key");
     $awsSecret = Config::getInstance()->get_value("aws.secret");
     if (Config::getInstance()->is_debug()) {
         Logger::getInstance()->debug(" s3 bucket is => {$bucket}");
         Logger::getInstance()->debug(" original name => {$name}");
         Logger::getInstance()->debug(" file path is => {$storeName} ");
     }
     $s3 = new \S3($awsKey, $awsSecret, false);
     $metaHeaders = array();
     //$input, $bucket, $uri, $acl , $metaHeaders, $requestHeaders
     $s3->putObject($sBlobData, $bucket, $storeName, \S3::ACL_PUBLIC_READ, $metaHeaders, $headers);
     return $storeName;
 }
Example #11
0
File: Site.php Project: rjha/sc
 static function getNoResult($message, $options = NULL)
 {
     $defaults = array("hkey" => NULL, "form" => "vanilla");
     $settings = Util::getSettings($options, $defaults);
     //get qparams from Url
     $qparams = \com\indigloo\Url::getRequestQueryParams();
     $gpage = -1;
     //hkey supplied - means show help on page #1.
     if (!empty($qparams) && isset($qparams["gpage"])) {
         $gpage = $qparams["gpage"];
         $gpage = intval($gpage);
     } else {
         $gpage = 1;
     }
     $html = NULL;
     $help_key = $settings["hkey"];
     if ($gpage <= 1 && !is_null($help_key)) {
         try {
             $html = self::getHelp($help_key);
             return $html;
         } catch (\Exception $ex) {
             $html = NULL;
             $errorMsg = $ex->getMessage();
             Logger::getInstance()->error($errorMsg);
             Logger::getInstance()->error($ex->getMessage());
         }
     }
     $view = new \stdClass();
     $template = NULL;
     $form = $settings["form"];
     switch ($form) {
         case "tile":
             $template = "/fragments/site/noresult/tile.tmpl";
             break;
         default:
             $template = "/fragments/site/noresult/vanilla.tmpl";
             break;
     }
     $view->message = $message;
     $html = Template::render($template, $view);
     return $html;
 }
Example #12
0
 function persist($prefix, $name, $sBlobData, $headers = array())
 {
     $storeName = self::getHashedName($name);
     $storeName = $prefix . $storeName;
     $fp = NULL;
     //system.upload.path has a trailing slash
     $path = Config::getInstance()->get_value('system.upload.path') . $storeName;
     if (!file_exists(dirname($path))) {
         mkdir(dirname($path), 0755, true);
     }
     if (Config::getInstance()->is_debug()) {
         Logger::getInstance()->debug(" file name = {$name}");
         Logger::getInstance()->debug(" storage path is => {$path} ");
     }
     //open file in write mode
     $fp = fopen($path, 'w');
     fwrite($fp, $sBlobData);
     fclose($fp);
     return $storeName;
 }
Example #13
0
function process_activities($mysqli)
{
    /* 
     * process activities data 
     * @imp activities should be brought in the order that they have happened
     * so sort on id ASC 
     */
    $sql = " select * from sc_activity where op_bit = 0 order by id limit 50";
    $rows = MySQL\Helper::fetchRows($mysqli, $sql);
    $activityDao = new \com\indigloo\sc\dao\Activity();
    foreach ($rows as $row) {
        try {
            $sql2 = " update sc_activity set op_bit = 1 where id = " . $row["id"];
            $feed = $activityDao->pushToRedis($row);
            $activityDao->sendMail($row, $feed);
            //flip the op_bit for this activity
            MySQL\Helper::executeSQL($mysqli, $sql2);
        } catch (\Exception $ex) {
            Logger::getInstance()->error($ex->getMessage());
        }
    }
}
Example #14
0
 /**
  *
  * @param $tos an array containing to addresses, is required.
  * @param from : sender's email address, is required
  * @param fromName : human friendly sender's name 
  * @param subject required
  * @param text - text content of mail, is required
  * @param html - html content of mail, is required 
  *
  * @return return value of zero indicates success
  * A non zero return value indicates failure.
  *
  */
 static function sendViaWeb($tos, $from, $fromName, $subject, $text, $html)
 {
     $mode = Config::getInstance()->get_value("sendgrid.mail.mode");
     if (strcmp($mode, "production") != 0) {
         $recipients = implode($tos, ",");
         $message = sprintf("\n\n  **** mail to %s ****  \n %s \n\n", $recipients, $text);
         Logger::getInstance()->info($message);
         return;
     }
     $login = Config::getInstance()->get_value("sendgrid.login");
     $password = Config::getInstance()->get_value("sendgrid.password");
     if (empty($login) || empty($password) || empty($tos) || empty($from) || empty($text) || empty($html)) {
         //bad input
         return self::BAD_INPUT_ERROR;
     }
     // SendGrid PHP LIB path should be included before
     // webgloo libraries for this to work
     $sendgrid = new \SendGrid($login, $password);
     $mail = new \SendGrid\Mail();
     $fromName = empty($fromName) ? $from : $fromName;
     $mail->setTos($tos)->setFrom($from)->setFromName($fromName)->setSubject($subject)->setText($text)->setHtml($html);
     /* 
      * response handling.
      * CURLOPT_RETURNTRANSFER option is set in SendGrid/Web#send()
      * that method will return the result on success, FALSE on failure
      *
      * @see http://docs.sendgrid.com/documentation/api/web-api/#responseserror
      * {"message":"error","errors":[]}
      *
      * @see http://docs.sendgrid.com/documentation/api/web-api/#responsessuccess
      * {"message":"success"}
      *
      */
     $response = $sendgrid->web->send($mail);
     if ($response === FALSE) {
         //problem with curl transport
         $message = " Error communicating with sendgrid mail endpoint";
         Logger::getInstance()->error($message);
         return self::CURL_ERROR;
     }
     //parse response json
     $responseObj = json_decode($response);
     if (!is_object($responseObj) || !property_exists($responseObj, "message")) {
         //bad json from sendgrid
         $message = sprintf("Sendgrid mail api response :: [[%s]] is malformed", $response);
         Logger::getInstance()->error($message);
         return self::MALFORMED_RESPONSE;
     }
     $message = $responseObj->message;
     if (strcasecmp($message, "error") == 0) {
         //sendgrid returned error.
         //get errors array
         $message = " Sendgrid mail api returned error";
         Logger::getInstance()->error($message);
         foreach ($responseObj->errors as $error) {
             Logger::getInstance()->error($error);
         }
         return self::SENDGRID_ERROR;
     }
     if (strcasecmp($message, "success") == 0) {
         //success
         return 0;
     }
     return self::UNKNOWN_ERROR;
 }
Example #15
0
File: Login.php Project: rjha/sc
 private static function completeSessionAction($loginId, $name, $provider)
 {
     $message = NULL;
     $action = NULL;
     try {
         $gWeb = \com\indigloo\core\Web::getInstance();
         $gSessionAction = $gWeb->find("global.session.action");
         if (empty($gSessionAction)) {
             return;
         }
         // base64_decode action
         $action = base64_decode($gSessionAction);
         if ($action === FALSE) {
             return;
         }
         //json_decode session action
         $actionObj = json_decode($action);
         $endPoint = $actionObj->endPoint;
         $params = $actionObj->params;
         $variables = get_object_vars($params);
         // associated array of name value pairs
         // undefines properties are returned as NULL
         //
         // @warning: the foreach value reference is maintained
         // after the loop. variable scope in PHP is at function level
         // so do not be too cute here and do not use $name => $value
         // inside loop as that conflicts with function argument "name"
         //
         // see if one of the parameters has "value" {loginId}
         // update this parameter value to actual loginId
         foreach ($variables as $prop => $value) {
             if ($params->{$prop} == "{loginId}") {
                 $params->{$prop} = $loginId;
             }
         }
         //inject loginId, name and provider into params
         $params->loginId = $loginId;
         $params->name = $name;
         $params->provider = $provider;
         //Facade for session action endpoint
         $facade = new \com\indigloo\sc\command\Facade();
         $response = $facade->execute($endPoint, $params);
         $message = $response["message"];
         if ($response["code"] == 200) {
             // success
             // set overlay message
             $gWeb->store("global.overlay.message", $message);
         } else {
             $message = sprintf("session action response code : %d", $response["code"]);
             throw new \Exception($message);
         }
     } catch (\Exception $ex) {
         $message = sprintf("session action %s failed \n ", $action);
         Logger::getInstance()->error($ex->getMessage());
     }
 }
Example #16
0
File: google2.php Project: rjha/sc
function processUser($user)
{
    $id = $user->id;
    if (empty($id)) {
        trigger_error("Could not retrieve google id : please try again.", E_USER_ERROR);
    }
    //rest of the properties may be missing
    $email = property_exists($user, 'email') ? $user->email : '';
    $name = property_exists($user, 'name') ? $user->name : '';
    $firstName = property_exists($user, 'given_name') ? $user->given_name : '';
    $lastName = property_exists($user, 'family_name') ? $user->family_name : '';
    $photo = property_exists($user, 'picture') ? $user->picture : '';
    // we consider id + auth to be good enough for a user
    if (empty($name) && empty($firstName)) {
        $name = "Anonymous";
    }
    $message = sprintf("Login:Google :: id %d ,email %s ", $id, $email);
    Logger::getInstance()->info($message);
    $googleDao = new \com\indigloo\sc\dao\Google();
    $loginId = $googleDao->getOrCreate($id, $email, $name, $firstName, $lastName, $photo);
    if (empty($loginId)) {
        $message = "Not able to create 3mik login for google user";
        Logger::getInstance()->error($message);
        raiseUIError();
    }
    //success - update login record
    // start 3mik session
    $remoteIp = \com\indigloo\Url::getRemoteIp();
    mysql\Login::updateIp(session_id(), $loginId, $remoteIp);
    $code = Login::startOAuth2Session($loginId, Login::GOOGLE);
    $location = $code == Login::FORBIDDEN_CODE ? AppConstants::ERROR_403_URL : AppConstants::DASHBOARD_URL;
    header("Location: " . $location);
}
Example #17
0
 function getErrors()
 {
     if ($this->hasErrors() && Config::getInstance()->is_debug()) {
         Logger::getInstance()->debug($this->fname . " :: posted errors ::");
         Logger::getInstance()->dump($this->ferrors);
     }
     return $this->ferrors;
 }
Example #18
0
File: Activity.php Project: rjha/sc
 function getList($key, $limit)
 {
     $feedDataObj = NULL;
     try {
         $redis = Redis::getInstance()->connection();
         $feeds = $redis->lrange($key, 0, $limit);
         //redis can return nil or empty array
         if (empty($feeds)) {
             $feeds = array();
         }
         $feedDataObj = new \stdClass();
         $feedDataObj->feeds = $feeds;
         $feedDataObj->type = "list";
     } catch (\Exception $ex) {
         $feedDataObj = new \stdClass();
         $feedDataObj->error = "Error retrieving activity feed!";
         $message = sprintf("Redis Exception %s ", $ex->getMessage());
         Logger::getInstance()->error($message);
     }
     return $feedDataObj;
 }
Example #19
0
File: Lists.php Project: rjha/sc
 static function deleteItems($loginId, $listId, $itemIds)
 {
     //input
     settype($loginId, "integer");
     settype($listId, "integer");
     if (empty($itemIds)) {
         return;
     }
     try {
         $dbh = PDOWrapper::getHandle();
         // *** Tx start ***
         $dbh->beginTransaction();
         // #1 : delete items
         $sqlt = " delete from sc_list_item where list_id = %d and item_id = %d ";
         foreach ($itemIds as $itemId) {
             settype($itemId, "integer");
             $sql = sprintf($sqlt, $listId, $itemId);
             //fire SQL statement
             $dbh->exec($sql);
         }
         // #2: get items_json within this Tx
         $sql2 = " select post.id, post.images_json from sc_post post, sc_list_item li ";
         $sql2 .= " where li.item_id = post.id  and li.list_id = %d  limit 4 ";
         $sql2 = sprintf($sql2, $listId);
         $stmt2 = $dbh->prepare($sql2);
         $stmt2->execute();
         $rows = $stmt2->fetchAll();
         $stmt2->closeCursor();
         $stmt2 = NULL;
         $bucket = array();
         foreach ($rows as $row) {
             $itemId = $row["id"];
             $json = $row["images_json"];
             $images = json_decode($json);
             if (!empty($images) && sizeof($images) > 0) {
                 $image = $images[0];
                 $imgv = \com\indigloo\sc\html\Post::convertImageJsonObj($image);
                 $view = new \stdClass();
                 $view->id = $row["id"];
                 $view->thumbnail = $imgv["thumbnail"];
                 array_push($bucket, $view);
             }
         }
         $items_json = json_encode($bucket);
         if ($items_json === FALSE || $items_json == NULL) {
             $items_json = '[]';
             $errorMsg = sprintf(" json encode error : list delete : id :: %d", $listId);
             Logger::getInstance()->error($errorMsg);
         }
         // #3 : update list.id.item_count and list.id.items_json
         $sql3 = " update sc_list set items_json = :items_json, ";
         $sql3 .= " item_count = (select count(id) from sc_list_item where list_id = :list_id)";
         $sql3 .= " where id = :list_id ";
         $stmt3 = $dbh->prepare($sql3);
         $stmt3->bindParam(":list_id", $listId);
         $stmt3->bindParam(":items_json", $items_json);
         $stmt3->execute();
         $stmt3 = NULL;
         // **** Tx end ****
         $dbh->commit();
         $dbh = null;
     } catch (\PDOException $e) {
         $dbh->rollBack();
         $dbh = null;
         throw new DBException($e->getMessage(), $e->getCode());
     } catch (\Exception $ex) {
         $dbh->rollBack();
         $dbh = null;
         throw new DBException($ex->getMessage(), $ex->getCode());
     }
 }
Example #20
0
 function gc($age)
 {
     if (Config::getInstance()->is_debug()) {
         $message = sprintf("session_gc : age  %d ", $age);
         Logger::getInstance()->debug($message);
     }
     $sql = "DELETE FROM sc_php_session WHERE updated_on < (now() - INTERVAL :age SECOND) ";
     $stmt = $this->dbh->prepare($sql);
     $stmt->bindParam(":age", $age, \PDO::PARAM_INT);
     $stmt->execute();
     return TRUE;
 }
Example #21
0
File: comment.php Project: rjha/sc
            $actionObj = new \stdClass();
            $actionObj->endPoint = "/qa/form/comment.php";
            $params = new \stdClass();
            $params->ownerId = $fvalues['owner_id'];
            $params->postId = $fvalues['post_id'];
            $params->title = $fvalues['post_title'];
            $params->comment = $fvalues['comment'];
            $params->action = UIConstants::ADD_COMMENT;
            $actionObj->params = $params;
            //base64 encode to transfer as payload in URL
            $gSessionAction = base64_encode(json_encode($actionObj));
            //encode again for user login page
            $fwd = "/user/login.php?q=" . base64_encode($fUrl) . "&g_session_action=" . $gSessionAction;
            header("Location: " . $fwd);
            exit;
        }
    } catch (UIException $ex) {
        $gWeb->store(Constants::STICKY_MAP, $fvalues);
        $gWeb->store(Constants::FORM_ERRORS, $ex->getMessages());
        header("Location: " . $fUrl);
        exit(1);
    } catch (\Exception $ex) {
        Logger::getInstance()->error($ex->getMessage());
        Logger::getInstance()->backtrace($ex->getTrace());
        $gWeb->store(Constants::STICKY_MAP, $fvalues);
        $message = "Error: looks bad. something went wrong!";
        $gWeb->store(Constants::FORM_ERRORS, array($message));
        header("Location: " . $fUrl);
        exit(1);
    }
}
Example #22
0
File: Post.php Project: rjha/sc
 static function getPagedOnCategory($start, $direction, $limit, $code)
 {
     $mysqli = MySQL\Connection::getInstance()->getHandle();
     //sanitize input
     $code = $mysqli->real_escape_string($code);
     $direction = $mysqli->real_escape_string($direction);
     settype($start, "integer");
     settype($limit, "integer");
     $sql = " select q.*,l.name as user_name from sc_post q,sc_login l ";
     $codeCondition = sprintf("cat_code = '%s'", $code);
     $q = new MySQL\Query($mysqli);
     $q->addCondition("l.id = q.login_id");
     $q->addCondition($codeCondition);
     $sql .= $q->get();
     $sql .= $q->getPagination($start, $direction, "q.id", $limit);
     if (Config::getInstance()->is_debug()) {
         Logger::getInstance()->debug("sql => {$sql} \n");
     }
     $rows = MySQL\Helper::fetchRows($mysqli, $sql);
     //reverse rows for 'before' direction
     if ($direction == 'before') {
         $results = array_reverse($rows);
         return $results;
     }
     return $rows;
 }
Example #23
0
<?php

include 'sc-app.inc';
include APP_WEB_DIR . '/inc/header.inc';
require WEBGLOO_LIB_ROOT . '/ext/twitteroauth/twitteroauth.php';
//set special error handler for twitter login script
include APP_WEB_DIR . '/callback/error.inc';
set_error_handler('login_error_handler');
use com\indigloo\Configuration as Config;
use com\indigloo\Logger;
$appId = Config::getInstance()->get_value("twitter.app.id");
$appSecret = Config::getInstance()->get_value("twitter.app.secret");
$connection = new TwitterOAuth($appId, $appSecret);
$host = "http://" . $_SERVER["HTTP_HOST"];
$callBackUrl = $host . '/callback/twitter.php';
//set explicit callback
$request_token = $connection->getRequestToken($callBackUrl);
// Saving them into the session
$_SESSION['oauth_token'] = $request_token['oauth_token'];
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
if ($connection->http_code == 200) {
    $url = $connection->getAuthorizeURL($request_token['oauth_token']);
    header('Location: ' . $url);
} else {
    Logger::getInstance()->error("Error in Twitter oauth :: connection dump ::");
    Logger::getInstance()->dump($connection);
    trigger_error("Could not connect to Twitter. Please try again later!", E_USER_ERROR);
}
?>
  
Example #24
0
File: index.php Project: rjha/sc
if ($pos !== false) {
    //remove the part after ? from Url
    // routing does not depends on query parameters
    $requestURI = substr($originalURI, 0, $pos);
    $qpart = substr($originalURI, $pos + 1);
}
$route = $router->getRoute($requestURI);
if (is_null($route)) {
    //No valid route for this path
    $message = sprintf("No route for path %s", $requestURI);
    Logger::getInstance()->error($message);
    $controller = new \com\indigloo\sc\controller\Http404();
    $controller->process();
    exit;
} else {
    $controllerName = $route["action"];
    //add path and query
    $options = array();
    $options["path"] = $requestURI;
    $options["query"] = $qpart;
    $route["options"] = $options;
    if (Config::getInstance()->is_debug()) {
        $message = sprintf("controller %s :: path is %s  ", $controllerName, $requestURI);
        Logger::getInstance()->debug($message);
        Logger::getInstance()->dump($route);
    }
    $controller = new $controllerName();
    $controller->process($route["params"], $route["options"]);
}
$e_time = microtime(true);
printf(" \n <!-- Request %s took %f milliseconds --> \n", $originalURI, ($e_time - $s_time) * 1000);
Example #25
0
File: fb2.php Project: rjha/sc
/**
 * 
 * @param access_token - access token returned by facebook for offline use
 * @param expires - time in seconds till the access_token expiry  
 * 
 * 
 */
function processUser($user, $access_token, $expires)
{
    // exisitng record ? find on facebook_id
    // New record - create login + facebook record
    // start login session
    $id = $user->id;
    if (empty($id)) {
        trigger_error("Could not retrieve facebook id : please try again.", E_USER_ERROR);
    }
    //rest of the properties may be missing
    $email = property_exists($user, 'email') ? $user->email : '';
    $name = property_exists($user, 'name') ? $user->name : '';
    $firstName = property_exists($user, 'first_name') ? $user->first_name : '';
    $lastName = property_exists($user, 'last_name') ? $user->last_name : '';
    $link = property_exists($user, 'link') ? $user->link : '';
    $gender = property_exists($user, 'gender') ? $user->gender : '';
    // do not know what facebook will return
    // we consider auth to be good enough for a user
    if (empty($name) && empty($firstName)) {
        $name = "Anonymous";
    }
    $message = sprintf("Login:Facebook :: id %d ,email %s ", $id, $email);
    Logger::getInstance()->info($message);
    $facebookDao = new \com\indigloo\sc\dao\Facebook();
    $loginId = $facebookDao->getOrCreate($id, $name, $firstName, $lastName, $link, $gender, $email, $access_token, $expires);
    if (empty($loginId)) {
        $message = "Not able to create 3mik login for facebook user";
        Logger::getInstance()->error($message);
        raiseUIError();
    }
    //success - update login record
    // start 3mik session
    $remoteIp = \com\indigloo\Url::getRemoteIp();
    mysql\Login::updateTokenIp(session_id(), $loginId, $access_token, $expires, $remoteIp);
    $code = Login::startOAuth2Session($loginId, Login::FACEBOOK);
    $location = $code == Login::FORBIDDEN_CODE ? AppConstants::ERROR_403_URL : AppConstants::DASHBOARD_URL;
    header("Location: " . $location);
}
Example #26
0
File: twitter.php Project: rjha/sc
function processUser($connection)
{
    $user_info = $connection->get('account/verify_credentials');
    if (isset($user_info->error)) {
        $message = "Error retrieving twitter user information";
        Logger::getInstance()->error($message);
        raiseUIError();
    } else {
        // get screenName, profile Pic
        // exisitng record ? find on twitter_id
        // New record - create login + twitter record
        // start login session
        $id = $user_info->id;
        if (empty($id)) {
            trigger_error("Could not retrieve twitter id : please try again.", E_USER_ERROR);
        }
        $image = $user_info->profile_image_url;
        $screenName = $user_info->screen_name;
        $name = $user_info->name;
        $location = $user_info->location;
        // do not know what twitter will return
        // we consider auth to be good enough for a user
        if (empty($name) && empty($screenName)) {
            $name = "Anonymous";
        }
        $message = sprintf("Login:Twitter :: id %d ,name %s ", $id, $name);
        Logger::getInstance()->info($message);
        $twitterDao = new \com\indigloo\sc\dao\Twitter();
        $loginId = $twitterDao->getOrCreate($id, $name, $screenName, $location, $image);
        if (empty($loginId)) {
            $message = "Not able to create 3mik login for twitter user";
            Logger::getInstance()->error($message);
            raiseUIError();
        }
        //success - update login record
        // start 3mik session
        $remoteIp = \com\indigloo\Url::getRemoteIp();
        mysql\Login::updateIp(session_id(), $loginId, $remoteIp);
        $code = Login::startOAuth2Session($loginId, Login::TWITTER);
        $location = $code == Login::FORBIDDEN_CODE ? AppConstants::ERROR_403_URL : AppConstants::DASHBOARD_URL;
        header("Location: " . $location);
    }
}
Example #27
0
File: register.php Project: rjha/sc
 $fvalues = array();
 $fUrl = \com\indigloo\Url::tryFormUrl("fUrl");
 try {
     $fhandler = new Form\Handler('web-form-1', $_POST);
     $fhandler->addRule('first_name', 'First Name', array('required' => 1, 'maxlength' => 32));
     $fhandler->addRule('last_name', 'Last Name', array('required' => 1, 'maxlength' => 32));
     $fhandler->addRule('email', 'Email', array('required' => 1, 'maxlength' => 64));
     $fhandler->addRule('password', 'Password', array('required' => 1, 'maxlength' => 32));
     //check security token
     $fhandler->checkToken("token", $gWeb->find("form.token", true));
     $fvalues = $fhandler->getValues();
     if (!empty($fvalues["adrisya_number"])) {
         $message = "unexpected error with form submission!";
         $fhandler->addError($message);
         $error = "Possible spam bot submission from IP :: " . $_SERVER["REMOTE_ADDR"];
         Logger::getInstance()->info($error);
     }
     if ($fhandler->hasErrors()) {
         throw new UIException($fhandler->getErrors());
     }
     //create a new login + user
     $loginDao = new \com\indigloo\sc\dao\Login();
     $loginDao->create($fvalues['first_name'], $fvalues['last_name'], $fvalues['email'], $fvalues['password']);
     //canonical email - all lower case
     $email = strtolower(trim($fvalues['email']));
     $password = trim($fvalues['password']);
     $loginId = NULL;
     try {
         $loginId = \com\indigloo\auth\User::login('sc_user', $email, $password);
     } catch (\Exception $ex) {
         $code = $ex->getCode();
Example #28
0
File: Web.php Project: rjha/webgloo
 function end()
 {
     //do not create a new instance
     $mysql = \com\indigloo\mysql\Connection::getInstance(false);
     if (!is_null($mysql)) {
         $mysql->closeHandle();
     }
     if (Config::getInstance()->is_debug()) {
         Logger::getInstance()->debug('web >> end >> hash is:: ' . spl_object_hash(self::$instance));
     }
 }
Example #29
0
File: Site.php Project: rjha/sc
 function processUrl($url)
 {
     $page = array();
     //empty url
     if (empty($url)) {
         return $page;
     }
     $scheme = \parse_url($url, PHP_URL_SCHEME);
     if (empty($scheme)) {
         $url = "http://" . $url;
     }
     $info = \parse_url($url);
     //host check
     if (!isset($info["host"])) {
         $message = sprintf("BAD_SITE_URL :: host not found [ %s ] ", $url);
         Logger::getInstance()->error($message);
         return $page;
     }
     if (Config::getInstance()->is_debug()) {
         $message = sprintf("parse_url Dump for Url %s \n", $url);
         Logger::getInstance()->debug($message);
         Logger::getInstance()->dump($info);
     }
     if (strcasecmp($info["host"], 'www.facebook.com') == 0) {
         $page = $this->processFBUrl($url, $info["path"]);
     } else {
         //canonical name
         $page["host"] = $info["host"];
         $page["hash"] = md5(strtolower($info["host"]));
         $page["url"] = $url;
         $page["canonicalUrl"] = "http://" . $info["host"];
     }
     return $page;
 }