function handle($response)
{
    header('Content-type: application/json');
    $code = substr($response, 0, 4);
    $msg = substr($response, 4);
    if ($code === '0000') {
        SUCCESS($msg);
    } else {
        if ($msg == '') {
            switch (substr($code, 0, 2)) {
                case ERROR_SYSTEM:
                    $msg = 'System Error.';
                    break;
                case ERROR_INPUT:
                    $msg = '请检查输入!';
                    break;
                case ERROR_PERMISSION:
                    $msg = 'Permission Denied.';
                    break;
                default:
                    $msg = 'Error.';
                    break;
            }
        }
        ERROR($code, $msg);
    }
}
 public function testEditarUsuario()
 {
     $nick = "d" . time();
     $arg = array("email" => $nick . "@example.net", "password" => "foobar123123", "nick" => $nick, "ubicacion" => "celaya", "nombre" => "nombre");
     $result = c_usuario::nuevo($arg);
     $this->assertTrue(SUCCESS($result), "Crear usuario correcto");
     $result = c_usuario::editar($arg);
     $this->assertTrue(SUCCESS($result), "Editar sin cambiar datos");
     $arg["escuela"] = "Nueva escuela";
     $result = c_usuario::editar($arg);
     $this->assertTrue(SUCCESS($result));
     // Validar que se cambio en efecto la escuela
     $arg["escuela"] = "Universidad de Matanzas Camilo Cienfuegos (UMCC)";
     $result = c_usuario::editar($arg);
     $this->assertTrue(SUCCESS($result), "parentesis permitidos en escuela");
     $arg["escuela"] = "#file_links[E:\riwenkey.txt,1,S]";
     $result = c_usuario::editar($arg);
     $this->assertTrue(!SUCCESS($result), "editar a algo muy raro");
     $arg["escuela"] = "veryloooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong";
     $result = c_usuario::editar($arg);
     $this->assertTrue(!SUCCESS($result), "editar escuela texto largo");
     $arg["escuela"] = "\"\\'\n\r";
     $result = c_usuario::editar($arg);
     $this->assertTrue(!SUCCESS($result));
 }
function handle($response)
{
    $code = substr($response, 0, 4);
    $msg = substr($response, 4);
    if ($code === '0000') {
        SUCCESS($msg);
    } else {
        if ($msg == '') {
            switch (substr($code, 0, 2)) {
                case ERROR_SYSTEM:
                    $msg = 'System Error.';
                    break;
                case ERROR_INPUT:
                    $msg = 'Param Error.';
                    break;
                case ERROR_PERMISSION:
                    $msg = 'Permission Denied.';
                    break;
                default:
                    $msg = 'Error.';
                    break;
            }
        }
        ERROR($code, $msg);
    }
}
 public static function Nuevo($request)
 {
     try {
         self::ProblemaValido($request);
     } catch (InvalidArgumentException $e) {
         Logger::warn("imposible crear nuevo problema:" . $e->getMessage());
         return array("result" => "error", "reason" => $e->getMessage());
     }
     $usuarioActual = c_sesion::usuarioActual();
     if (!SUCCESS($usuarioActual)) {
         Logger::error("no hay permiso para crear nuevo problema");
         return array("result" => "error", "reason" => "No tienes permiso de hacer esto.");
     }
     $sql = "insert into Problema (titulo, problema, tiempoLimite, usuario_redactor) values (?,?,?,?)";
     $inputarray = array($request["titulo"], $request["problema"], $request["tiempoLimite"], $usuarioActual["userID"]);
     global $db;
     $res = $db->Execute($sql, $inputarray);
     if ($res === false) {
         Logger::error("TEDDY:" . $db->ErrorNo() . " " . $db->ErrorMsg());
         return array("result" => "error", "reason" => "Error interno.");
     }
     $id = $db->Insert_ID();
     if (!file_exists(PATH_TO_CASOS)) {
         Logger::error("TEDDY: " . PATH_TO_CASOS . " no existe");
         return array("result" => "error", "reason" => "Error interno.");
     }
     file_put_contents(PATH_TO_CASOS . "/" . $id . ".in", $request["entrada"]);
     file_put_contents(PATH_TO_CASOS . "/" . $id . ".out", $request["salida"]);
     Logger::info("Nuevo problema creado. ProbID: " . $id . " Titulo: " . $request["titulo"]);
     return array("result" => "ok", "probID" => $id);
 }
 public static function usuarioActual()
 {
     $user = null;
     $result = array("result" => "error");
     if (self::isLoggedIn()) {
         $result = c_usuario::getByNick(array("nick" => $_SESSION['userID']));
         if (SUCCESS($result)) {
             $result = array("result" => "ok", "user" => $result["user"], "userID" => $_SESSION['userID']);
         }
     }
     return $result;
 }
Exemple #6
0
 public function uninstall()
 {
     // company_node_entity DB Table 삭제.
     if ($this->exists()) {
         $this->uninit();
     }
     // company_category_meta_entity DB Table 삭제.
     $meta = meta('company_category');
     if ($meta->exists()) {
         $meta->uninit();
     }
     return SUCCESS();
 }
 public function testNuevoProblemaCorrecto()
 {
     $titulo = "a" . time();
     $rlistaprobs = array("public" => "NO");
     $res = c_problema::lista($rlistaprobs);
     $probs = $res["problemas"];
     $found = false;
     for ($i = 0; $i < sizeof($probs); $i++) {
         if ($probs[$i]["titulo"] == $titulo) {
             $found = true;
             break;
         }
     }
     $this->assertTrue(!$found);
     $contents = "";
     for ($i = 0; $i < 100; $i++) {
         $contents .= "a";
     }
     $arg = array("titulo" => $titulo, "problema" => $contents, "tiempoLimite" => 3456, "entrada" => "1 1\n1 2\n100 100\n", "salida" => "2\n3\n200\n");
     // crear un usuario e iniciar sesion
     $nick = "p" . time();
     $uarg = array("nombre" => "problem tester", "email" => $nick . "@example.net", "password" => "foobar23123", "nick" => $nick, "user" => $nick, "ubicacion" => "celaya");
     $result = c_usuario::nuevo($uarg);
     $result = c_sesion::login($uarg);
     $result = c_problema::nuevo($arg);
     $this->assertTrue(SUCCESS($result));
     $this->assertTrue(SUCCESS($result), "Crear un nuevo problema correctamente");
     $rlistaprobs = array("public" => "NO");
     $res = c_problema::lista($rlistaprobs);
     $probs = $res["problemas"];
     $found = false;
     $found_prob = null;
     for ($i = 0; $i < sizeof($probs); $i++) {
         if ($probs[$i]["titulo"] == $titulo) {
             $found = true;
             $found_prob = $probs[$i];
             break;
         }
     }
     $this->assertTrue($found);
     $this->assertEquals($found_prob["titulo"], $arg["titulo"]);
     $this->assertEquals($found_prob["problema"], $arg["problema"]);
     $this->assertEquals($found_prob["tiempoLimite"], $arg["tiempoLimite"]);
     $this->assertEquals($found_prob["usuario_redactor"], $argu["user"]);
 }
 /**
  *
  * @param para
  * @param msg
  * @param 
  *
  **/
 public static function Nuevo($request)
 {
     $apiresult = c_usuario::getByNick(array("user" => $request["para"]));
     global $db;
     if (SUCCESS($apiresult)) {
         $sql = "INSERT INTO Mensaje (de , para , mensaje, fecha ) VALUES (  ?, ?, ?, ?);";
         $inputarray = array($_SESSION['userID'], $request["para"], $request["msg"], date("Y-m-d H:i:s", time()));
         $result = $db->Execute($sql, $inputarray);
     }
     if (SUCCESS($apiresult)) {
         $mensaje = "Hola,\n\nTienes un nuevo mensaje en teddy de parte de " . $_SESSION['userID'] . ": https://" . $_SERVER['SERVER_NAME'] . "/inbox.php";
         // Ignorar el resultado
         $ignore_apiresult = c_mail::EnviarMail($mensaje, $apiresult["user"]["mail"], "Nuevo mensaje en Teddy");
         $apiresult = array('result' => "ok");
     }
     unset($apiresult["user"]);
     return $apiresult;
 }
Exemple #9
0
 /**
  *
  *
  * 데이터베이스 테이블이 존재하는지 하지 않는지 확인르 한다.
  *
  * @Attention 이 메소드는 언뜻 보기에는 해당 Entity 클래스가 존재하는지 확인하는 것 같지만, 사실은 데이터베이스 존재 여부만 확인을 한다.
  *
  *
  * @param $in
  * @return array
  *
  *
  * @usage php index.php "route=entity.Controller.exist&node=user"
  *
  */
 public function exist($in)
 {
     $tablename = null;
     if (isset($in['node'])) {
         $tablename = $in['node'] . "_node_entity";
     } else {
         if (isset($in['meta'])) {
             $tablename = $in['meta'] . "_meta_entity";
         } else {
             ERROR(-401, 'Wrong input');
         }
     }
     $re = parent::exists($tablename);
     if ($re) {
         return SUCCESS();
     } else {
         return ERROR(-402, "{$tablename} does not exists.");
     }
 }
Exemple #10
0
 /**
  *
  * Checks 'who am I' or gets the login username.
  *
  * @param $in
  * @return array
  *      - The input HTTP variable & login username in "data['login']"
  *
  *
  */
 public function who($in)
 {
     $re = $in;
     $user = user()->loginUser();
     if ($user) {
         $re['username'] = $user->username;
     }
     return SUCCESS($re);
 }
Exemple #11
0
 public function fileDelete()
 {
     sys()->log("ajaxFileDelete() : id=" . $this->in['id']);
     $data = data($this->in['id']);
     if ($data) {
         if ($code = $data->delete()) {
             return ERROR($code, "failed to delete file");
         } else {
             return SUCCESS(array('id' => $this->in['id']));
         }
     } else {
         return ERROR(-4333, "Entity does not exists.");
     }
 }
</div>

<div id="tab-concursos-pasados" class="post_blanco tab">
	<h2>Concursos Pasados</h2>
<?php 
$resultado = c_concurso::concursosPasados();
if (SUCCESS($resultado)) {
    $concursos = $resultado["concursos"];
    include "parcial_listadeconcursos.php";
}
?>
</div>

<div id="tab-concursos-futuros" class="post_blanco tab">

	<h2>Concursos Futuros</h2>
<?php 
$resultado = c_concurso::concursosFuturos();
if (SUCCESS($resultado)) {
    $concursos = $resultado["concursos"];
    include "parcial_listadeconcursos.php";
}
?>
</div>


<?php 
include_once "post_footer.php";
?>

Exemple #13
0
 /**
     public function countInformation() {
     return SUCCESS( array('count' => $this->count() ) );
     }
      * */
 public function getCategory($in)
 {
     $entities = $this->search();
     $list = [];
     if ($entities) {
         foreach ($entities as $entity) {
             $rec = $entity->getRecord();
             $list[] = $rec;
         }
     }
     return SUCCESS(['category' => $in['category'], 'list' => $list]);
 }
<?php

if (!c_sesion::isAdmin()) {
    $result = c_sesion::usuarioActual();
    if (SUCCESS($result)) {
        Logger::warn($result["userID"] . " quiso entrar a admin y no es admin");
    }
    ?>
		<div class="post_blanco">
			Necesitas ser administrador .
		</div>
		<?php 
    include_once "post_footer.php";
    exit;
}
<?php

if (c_sesion::isLoggedIn()) {
    ?>
	<div class="post">
		<div class="navcenter" align=center>
			<table border=0 style="width:100%">
				<tr class="navcenter">
					<td colspan=1>
						<a href="runs.php?user=<?php 
    echo $_SESSION['userID'];
    ?>
">
							<img id="avatar" src="https://secure.gravatar.com/avatar/<?php 
    $res = c_sesion::usuarioActual();
    if (SUCCESS($res)) {
        $user = $res["user"];
        echo md5($user['mail']);
    }
    ?>
?s=140" alt="" width="20" height="20"  />
						<b><?php 
    echo $_SESSION['userID'];
    ?>
</b> !<br>
						</a>
					</td>
					<td>
						<a href="editprofile.php"><img src="img/71.png" > Editar tu perfil</a>
					</td>
					<td id="mailbox_menu">
Exemple #16
0
 public function uninstall()
 {
     $this->uninit();
     return SUCCESS();
 }
 public static function RequestResetPass($request)
 {
     $request["nick"] = $request["user"];
     $result = self::getByNick($request);
     if (is_null($result["user"])) {
         return array("result" => "error", "reason" => "Este usuario no existe.");
     }
     $user = $result["user"];
     $foo = 55;
     $bar = "";
     while ($foo-- > 0) {
         $bar .= rand(5, 123);
     }
     $token = md5($bar);
     $sql = "INSERT INTO LostPassword (`userID` , `IP` , `Token` ) VALUES (?,?,?);";
     if (isset($_SERVER["REMOTE_ADDR"])) {
         $ip = $_SERVER["REMOTE_ADDR"];
     } else {
         $ip = "0.0.0.0";
     }
     $inputarray = array($user["userID"], $ip, $token);
     global $db;
     $res = $db->Execute($sql, $inputarray);
     $resetid = $db->Insert_ID();
     $content = "Hola,\n\nSigue este enlace para resetear tu password en Teddy: https://" . $_SERVER['SERVER_NAME'] . "/reset.php?token=" . $token;
     $result = c_mail::EnviarMail($content, $user["mail"], "Teddy Online Judge");
     if (!SUCCESS($result)) {
         return array("result" => "error", "reason" => "impsible enviar el correo electronico");
     }
     $sql = "update LostPassword set mailSent = 1 where id = ?";
     $inputarray = array($resetid);
     $res = $db->Execute($sql, $inputarray);
     return array("result" => "ok");
 }
<?php

// Revisar que el usuario exista
$param = array("nick" => $_GET["user"]);
$response = c_usuario::getByNick($param);
if (SUCCESS($response)) {
    if (is_null($response["user"])) {
        //User does not exist
        return;
    } else {
        $user = $response["user"];
        ?>
		<table border=0>
		<tr>
			<td>
			<span class="rounded_image" style="background-image:url(https://secure.gravatar.com/avatar/<?php 
        echo md5($user["mail"]);
        ?>
);">
				<img src="https://secure.gravatar.com/avatar/<?php 
        echo md5($user["mail"]);
        ?>
" style="opacity:0;">
			</span>
			</td>
			<td width='400px'>
				<h2><?php 
        echo $user["userID"];
        ?>
</h2>
				<b><?php