private function userFromCookie()
 {
     $cookie = SC::getCookie("sc_auth");
     if (!$cookie) {
         return false;
     }
     $cookie_array = explode("||", base64_decode($cookie));
     //echo (var_dump($cookie_array));
     $user_id = $cookie_array[0];
     $cookie_auth_token = $cookie_array[1];
     $sql = "SELECT user_password, user_email from users WHERE user_id=" . $user_id;
     $db = new SCDB();
     $result = $db->queryArray($sql);
     if (sizeof($result)) {
         //$auth_token = $this->createAuthToken($user_id, $result[0]["user_password"]);
         $auth_token = md5($result[0]["user_email"] . $result[0]["user_password"]);
         if (strcmp($cookie_auth_token, $auth_token) === 0) {
             $this->setSessionUser($user_id, SCUser::saltPassword($result[0]["user_password"]));
             return $this->getSessionUser();
         }
     }
     return false;
 }
Example #2
0
 public function save()
 {
     if (!$this->existing) {
         throw new Exception("This is not existing user... you must call create, not save", 401);
     }
     $update_array = $this->toArray(true);
     $db = new SCDB();
     $db->updateFromArray($update_array, "users", "WHERE user_id=" . $this->userid);
     if (mysql_error($db->conn) !== "") {
         throw new UserException(mysql_error($db->conn));
     }
     $user = new SCUser($this->userid);
     $this->fromArray($user->toArray());
     return $this;
 }
Example #3
0
 public function users_memberships_boardcounts($params = null)
 {
     // aka register
     if ($params && isset($params["__partial"])) {
         return null;
     }
     if ($params === null) {
         $this->requireRequestType("GET");
         $params = $_GET;
     }
     $current_user = $this->requireLogin("You must be logged in to view your memberships");
     $userid = $params["userid"];
     if (!$userid) {
         throw new APIException("No User id specified", 401);
     }
     if (intval($userid) != intval($current_user->userid)) {
         throw new APIException("You may only view your own memebrships", 403);
     }
     $user = new SCUser($userid);
     $user_memberships = array("memberships" => array());
     $mems = $user->loadMemberships()->memberships();
     foreach ($mems as $mem_id => $mem) {
         $user_memberships["memberships"][] = $this->boards_show(array("boardid" => $mem->boardid));
     }
     return $user_memberships;
 }
#!/usr/bin/php -q
<?php 
$from_email = true;
require_once 'sc_lib.php';
// read from stdin
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
    $email .= fread($fd, 1024);
}
fclose($fd);
$sc_email = new SCEmailParser($email);
try {
    if ($sc_email->boardid) {
        $board = new SCBoard($sc_email->boardid);
        $user = new SCUser($sc_email->from_address);
        $user_id = $user->userid;
        if ($user->isMemberOf($board->boardid)) {
            $message_array = array("authorid" => $user_id, "text" => $sc_email->body, "source" => "email");
            if ($sc_email->attachment) {
                $message_array["type"] = "image";
                $message_array["attachment"] = array("uploadmedia" => $sc_email->attachment);
            }
            if ($sc_email->threadid) {
                if ($board->hasMessage($sc_email->threadid)) {
                    $thread = new SCThread($sc_email->threadid);
                    $thread->addMessage($message_array);
                } else {
                    throw new Exception("thread " . $sc_email->threadid . " not in board " . $sc_email->boardid);
                }
            } else {