コード例 #1
0
ファイル: register.php プロジェクト: pierotofy/pierotofy.it
    method: POST
    params: 
      hash: username e password oscurati (vedi /js/site.js Login.encrypt) 
    returns:
      success: false => errore, true => OK
      error: messaggio di errore se success e' false
  */
require_once "__inc__.php";
$response = new RestfulResponse("json");
$av = new AutoValidator("frm-register", $_POST);
if ($av->validate()) {
    if (isset($_POST['question']) && $_POST['question'] == "10") {
        $email = db_escape(purify(trim(Charset::Utf8ToDB($_POST['email']))));
        $creds = LoginUtils::HashToCredentials(db_escape($_POST['hash']));
        $username = db_escape(purify(trim(Charset::Utf8ToDB($creds['username']))));
        $password = db_escape(purify(trim(Charset::Utf8ToDB($creds['password']))));
        // 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']));
コード例 #2
0
ファイル: search.php プロジェクト: pierotofy/pierotofy.it
/* 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();
コード例 #3
0
ファイル: send.php プロジェクト: pierotofy/pierotofy.it
    method: POST
    params:
      to : nome dell'utente a cui inviare i messaggi
      subject : oggetto del messaggio
      message : testo del messaggio
      important : flag se il messaggio è importante o no
      multiple : flag se il messaggio è multiplo o no
    returns:
      success: false => errore, true => OK
  */
require_once "__inc__.php";
$response = new RestfulResponse();
//Salvo i parametri
$to = Charset::Utf8ToDB($_POST['to']);
$subject = Charset::Utf8ToDB($_POST['subject']);
$message = Charset::Utf8ToDB($_POST['message']);
$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']);
コード例 #4
0
ファイル: reply.php プロジェクト: pierotofy/pierotofy.it
    params: 
      topic_id: id del topic (base) su cui aggiungere una risposta
      message: messaggio
    returns:
      success: false => errore, true => OK
      post_html: html contenente il post appena inserito
  */
require_once "__inc__.php";
$response = new RestfulResponse("json");
$av = new AutoValidator("frm-forum-reply", $_POST);
if ($av->validate()) {
    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.");
コード例 #5
0
ファイル: newtopic.php プロジェクト: pierotofy/pierotofy.it
  */
require_once "__inc__.php";
$response = new RestfulResponse("json");
$av = new AutoValidator("frm-forum-post", $_POST);
if ($av->validate()) {
    if ($currentUser->isLogged()) {
        // Valida i campi di input
        validate_num($_POST['forum_id']);
        $subject = db_escape(Charset::Utf8ToDB($_POST['subject']));
        $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 {
コード例 #6
0
<?php

/** 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.");