예제 #1
0
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/** Permette di cercare il nome di un utente da una parte del nome
    method: POST
    params:
      name : parte del nome da cercare
      num_records : numero massimo di nomi che deve ritornare (limite di 50 per evitare di dare troppe informazioni)
    returns:
      results : array con nomi degli utenti
  */
require_once "__inc__.php";
$response = new RestfulResponse("json");
if (isset($_POST['term'])) {
    $term = Charset::Utf8ToDB($_POST['term']);
    $num_records = @$_POST['num_records'];
    // Validazione
    if (!isset($num_records)) {
        $num_records = 20;
    }
    if ($num_records > 50) {
        $num_records = 50;
    }
    $results = UserSearch::Find($term, $num_records);
    $response->set('results', $results);
    $response->setSuccess(true);
} else {
    $response->setError("Missing term param");
}
$response->send();
예제 #2
0
        // Username libero?
        if (!DB::FindOne("SELECT 1 FROM users WHERE user = \"{$username}\"")) {
            // Legacy: Un timestamp sarebbe stato meglio, ma non dobbiamo fare nulla con questo dato, quindi va bene cosi'
            $data = date("d/m/Y G:i");
            $description = "Normal User";
            $md5 = LoginUtils::Md5FromCredentials($username, $password);
            // Tutto a posto
            exequery(sprintf('INSERT INTO users (user, mail, ip, os_browser, date, description, permission, verified, md5, last_login_timestamp, last_login_ip, newsletter)
                  VALUES ("%s", "%s", "%s", "%s", "%s", "%s", %s, %s, "%s", %s, "%s", %s)', $username, $email, get_ip(), db_escape(purify($_SERVER["HTTP_USER_AGENT"])), $data, $description, User::PERMISSION_USER, 1, $md5, time(), get_ip(), 1));
            // Logga l'utente
            $currentUser = UserFactory::CreateFromCredentials($username, $password);
            if ($currentUser->isLogged()) {
                $response->setSuccess(true);
                // Logga
                Log::Info(sprintf("%s si e' registrato", $currentUser['username']));
                $_SESSION['login_hash'] = $currentUser['md5'];
                setcookie('login_hash', $currentUser['md5'], time() + 60 * 60 * 24 * 7, '/');
            } else {
                // Questo non dovrebbe succedere
                $response->setError("E' successo un imprevisto durante la registrazione. Per favore segnala questo incidente ad un amministratore.");
            }
        } else {
            $response->setError("L'username e' stato gia' preso. Scegline un'altro.");
        }
    } else {
        $response->setError("Captcha non valido.");
    }
} else {
    $response->setError($av->getLastError());
}
$response->send();
예제 #3
0
    if ($topic->isPoll() && $topic->isViewableBy($currentUser)) {
        $poll_data = $topic->getPollData();
        if (!$poll_data['user_has_voted']) {
            // Voto valido?
            $valid_vote = false;
            foreach ($poll_data['choices'] as $choice) {
                if ($choice['id'] == $_POST['vote']) {
                    $valid_vote = true;
                    break;
                }
            }
            if ($valid_vote) {
                // OK. Inseriamo il voto
                exequery("INSERT INTO forum_poll (topic_id, user_id, vote)\n            VALUES ({$topic['id']}, {$currentUser['id']}, {$_POST['vote']})");
                // Ricarica il topic
                $topic = new Topic($_POST['topic_id']);
                $response->set("results_html", $topic->renderPollResults());
                $response->setSuccess(true);
            } else {
                $response->setError("Voto non valido.");
            }
        } else {
            $response->setError("Hai gia' votato.");
        }
    } else {
        $response->setError("Non hai i permessi per votare questo sondaggio.");
    }
} else {
    $response->setError("Non sei loggato.");
}
$response->send();
예제 #4
0
$important = isset($_POST['important']) ? $_POST['important'] : false;
//boolean
$multiple = isset($_POST['multiple']) ? $_POST['multiple'] : false;
//boolean
$av = new AutoValidator("message-write", $_POST);
if ($av->validate()) {
    //Controllo solo multiple, to e important (gli altri due vengono controllati in MessageService)
    $important = $currentUser->isAdmin() && $important ? 1 : 0;
    $multiple = $multiple == "true";
    if ($multiple != 1) {
        $to = db_escape($to);
        $to = DB::FindOne("SELECT id FROM users WHERE user='******' LIMIT 1");
        $to = (int) $to['id'];
    }
    $ms = new MessageService($currentUser['id']);
    if ($multiple) {
        $ms->sendToAllMembers($subject, $message, $important);
        $response->setSuccess(true);
    } else {
        //Prendo l'id dell'utente a cui spedire il messaggio
        if (DB::Count("users", "id='{$to}' LIMIT 1") == 0) {
            $response->setError("Destinatario inesistente");
        } else {
            $ms->sendToOne($subject, $message, $to, $important);
            $response->setSuccess(true);
        }
    }
} else {
    $response->setError($av->getLastError());
}
$response->send();
예제 #5
0
<?php

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/** Ricava il contenuto raw di un post (o topic) del forum
      La richiesta dev'essere effettuata da un utente che ha i permessi per editare il post/topic
    method: GET
    params: 
      id: id del post/topic
    returns:
      informazioni del post/topic, inclusi:
      - messaggio, username del postatore
  */
require_once "__inc__.php";
$response = new RestfulResponse("json");
validate_num($_GET['id']);
if ($currentUser->isLogged()) {
    $post = new ForumPost($_GET['id']);
    if ($post->isViewableBy($currentUser)) {
        $response->set('message', $post['message']);
        $response->set('username', $post['user']);
    } else {
        $response->setError("Non hai i permessi per leggere queste informazioni.");
    }
} else {
    $response->setError("Non loggato");
}
echo $response->send();
예제 #6
0
    if ($currentUser->isLogged()) {
        // Valida i campi di input
        validate_num($_POST['topic_id']);
        $topic = new Topic($_POST['topic_id']);
        $message = db_escape(Charset::Utf8ToDB($_POST['message']));
        if (!Forum::IsUserFlooding($currentUser)) {
            if (!$topic['locked']) {
                // Trova il forum_id
                $values = DB::FindOne("SELECT argument FROM forum_posts WHERE id = {$_POST['topic_id']}");
                $forum_id = $values['argument'];
                exequery(sprintf("INSERT INTO forum_posts (user_id, root_topic, argument, message, type, post_date, last_post_date, ip) \n                          VALUES(%d, %d, %d, '%s', %d, %d, %d, '%s')", $currentUser['id'], $_POST['topic_id'], $forum_id, $message, Forum::TYPE_POST, time(), time(), get_ip()));
                $id = DB::LastId();
                $post = new ForumPost($id);
                Forum::UpdateTopicAfterReply($_POST['topic_id']);
                Forum::IncPostCountForUser($currentUser);
                Forum::AddReplyNotifications($post['id']);
                $response->set("post_html", $post->render("forum/post.html"));
                $response->setSuccess(true);
            } else {
                $response->setError("Il topic e' stato chiuso dal moderatore.");
            }
        } else {
            $response->setError("Attendi almeno " . Forum::FLOOD_SECONDS_LIMIT . " secondi tra un post e l'altro.");
        }
    } else {
        $response->setError("Non sei loggato.");
    }
} else {
    $response->setError($av->getLastError());
}
$response->send();
예제 #7
0
        $message = db_escape(Charset::Utf8ToDB($_POST['message']));
        $is_poll = isset($_POST['poll']);
        // Le domande del sondaggio vengono memorizzate nel campo
        // "poll" come array serializzato. Se "poll" e' null, allora
        // vuol dire che il topic non e' un sondaggio
        if ($is_poll) {
            $poll_questions = explode("\n", trim(purify(Charset::Utf8ToDB($_POST['poll']))));
            if (count($poll_questions) >= 2) {
                $poll_data = db_escape(serialize($poll_questions));
            } else {
                // Numero di domande nel sondaggio non valido (< 2)
                $poll_data = null;
            }
        }
        if (!Forum::IsUserFlooding($currentUser)) {
            exequery(sprintf("INSERT INTO forum_posts (user_id, argument, subject, message, type, post_date, last_post_date, ip, poll, replies) \n                        VALUES(%d, %d, '%s', '%s', %d, %d, %d, '%s', \"%s\", 0)", $currentUser['id'], $_POST['forum_id'], $subject, $message, Forum::TYPE_TOPIC, time(), time(), get_ip(), $poll_data));
            $id = DB::LastId();
            $topic = new Topic($id);
            Forum::IncPostCountForUser($currentUser);
            $response->set("topic_url", $topic->getUrl());
            $response->setSuccess(true);
        } else {
            $response->setError("Attendi almeno " . Forum::FLOOD_SECONDS_LIMIT . " secondi tra un post e l'altro.");
        }
    } else {
        $response->setError("Non sei loggato.");
    }
} else {
    $response->setError($av->getLastError());
}
$response->send();
예제 #8
0
        $response->set('to_field_name', 'Da');
        $to_field = 'from_id';
        $folder = MessageService::INBOX;
        break;
    case 'sent':
        $response->set('to_field_name', 'A');
        $to_field = 'to_id';
        $folder = MessageService::SENT;
        break;
    case 'trash':
        $response->set('to_field_name', 'Da');
        $to_field = 'from_id';
        $folder = MessageService::DELETED;
        break;
    default:
        $response->setError("Errore: parametro folder non valido");
        $response->send();
        exit;
}
//Controllo di order
$order_by = $order_type = '';
switch ($order) {
    case 'date_asc':
        $order_by = MessageService::DATE;
        $order_type = "ASC";
        break;
    case 'from_asc':
        $order_by = MessageService::NAME;
        $order_type = "ASC";
        break;
    case 'from_desc':
예제 #9
0
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/** Ricava il contenuto raw di un post (o topic) del forum
      La richiesta dev'essere effettuata da un utente che ha i permessi per editare il post/topic
    method: GET e POST combinato
    params: 
      id (GET): id del post/topic
      value (POST): nuovo contenuto
    returns:
      success => true|false
      value => HTML contenente il nuovo post
  */
require_once "__inc__.php";
$response = new RestfulResponse("json");
validate_num($_GET['id']);
if ($currentUser->isLogged()) {
    $q = exequery("SELECT argument, user_id FROM forum_posts WHERE id = {$_GET['id']}");
    $values = mysqli_fetch_array($q);
    // Puo' editare?
    if ($currentUser->isModOfForum($values['argument']) || $currentUser["id"] == $values['user_id']) {
        $message = db_escape(Charset::Utf8ToDB($_POST['value']));
        exequery("UPDATE forum_posts SET message = '{$message}', edit_date = " . time() . ", edit_by = {$currentUser['id']}\n              WHERE id = {$_GET['id']}");
        $post = new ForumPost($_GET['id']);
        $response->set("value", $post->getParsedMessage());
        $response->setSuccess(true);
    } else {
        $response->setError("Non hai i permessi per modificare questo post");
    }
} else {
    $response->setError("Non loggato");
}
echo $response->send();
예제 #10
0
  */
require_once "__inc__.php";
$response = new RestfulResponse("json");
$hash = $_POST['hash'];
if (isset($hash)) {
    $currentUser = UserFactory::CreateFromLoginHash($hash);
    if ($currentUser->isLogged()) {
        $response->setSuccess(true);
        // Aggiorna ip, data ultimo login
        exequery(sprintf("UPDATE users SET previous_login_timestamp = '%d', \n                                 last_login_timestamp = '%d', \n                                 last_login_ip = '%s' \n                        WHERE id = %d", $currentUser['last_login_timestamp'], time(), get_ip(), $currentUser['id']));
        // Logga
        Log::Info(sprintf("%s effettua il login", $currentUser['username']));
        $_SESSION['login_hash'] = $currentUser['md5'];
        if ($_POST['usecookie']) {
            setcookie('login_hash', $currentUser['md5'], time() + 60 * 60 * 24 * 7, '/');
        }
    } else {
        if ($currentUser->isBanned()) {
            $response->set("banned_message", utf8_encode("Il tuo account è stato disattivato fino al " . date("d/m/y - H:i", $currentUser->banned) . " per il seguente motivo: {$currentUser->banned_reason}.\n\nUna volta scaduto il ban il tuo account sarà automaticamente riattivato."));
            $response->setError("Bannato!");
        } else {
            setcookie('login_hash', '', 0, '/');
            unset($_SESSION['login_hash']);
            $response->setError("Username o password invalidi.");
        }
    }
} else {
    $response->setError("Hash mancante");
}
$response->send();
예제 #11
0
/** Si occupa di recuperare la password dell'utente
    method: POST
    params: 
      hash: obscured username and password (see /js/site.js Login.encrypt) 
      usecookie: "0" => do not set cookie, "1" => set cookie
    returns:
      success: "0" => error happened, "1" => OK
      banned_message (optional): a ban message if the user is currently banned
      
  */
require_once "__inc__.php";
$response = new RestfulResponse("json");
$username = db_escape(Charset::Utf8ToDB($_POST['user']));
$userObj = new User("user = \"{$username}\"");
if ($userObj->isValid()) {
    $ip = get_ip();
    $url = $site_url . "/p/login/resetPassword.php?token={$userObj['md5']}&uid={$userObj['id']}";
    $message = $userObj['username'] . ",<br/>\nè stata inoltrata una richiesta da [{$ip}] per resettare la tua password su <a href=\"{$site_url}\">www.pierotofy.it</a>.<br/>\n<br/>\nPer continuare la procedura visita il link qui sotto riportato:<br/><br/>\n\n<a href=\"{$url}\">{$url}</a>\n";
    try {
        if (Mailer::SendEmail("*****@*****.**", "*****@*****.**", "Recupero password", $message)) {
            $response->setSuccess(true);
        } else {
            $response->setError("E' successo un errore durante l'invio dell'e-mail.");
        }
    } catch (Exception $e) {
        $response->setError("Eccezione: " . $e->getMessage());
    }
} else {
    $response->setError("L'utente non e' valido.");
}
$response->send();