Beispiel #1
0
function removeUserProject($id)
{
    $mongoCollection = getMongoCollection('project');
    $result = $mongoCollection->remove(array('_id' => new MongoId($id)));
    $app = \Slim\Slim::getInstance();
    if (!$result) {
        $app->flash('error', '削除できませんでした');
    } else {
        $app->flash('info', 'プロジェクトを削除しました');
    }
    $app->redirect($app->config('static_path') . '');
}
<?php

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../app/config.php';
require __DIR__ . '/../app/db.php';
$app = new \Slim\Slim($config);
$mongoCollection = getMongoCollection('tag');
$mongoCollection->drop();
$tags = $app->config('tag');
try {
    $mongoCollection->save(array('tag' => $tags));
} catch (RuntimeException $e) {
    echo $e->getMessage() . PHP_EOL;
    return;
}
echo 'Tag updated.' . PHP_EOL;
Beispiel #3
0
     $perpage = $app->config('perpage');
     $app->render('index.php', compact('list', 'results', 'count', 'creator', 'tag', 'license', 'keyword', 'path', 'perpage'));
 });
 $app->get('/complete', function () use($app) {
     $app->render('complete.php');
 });
 $app->get('/login', function () use($app) {
     $app->render('login.php');
 });
 $app->post('/login', function () use($app) {
     try {
         $post = $app->request->post();
         if (!(isset($post['email']) && is_string($post['email']) && isset($post['password']) && is_string($post['password']))) {
             throw new RuntimeException('メールアドレスまたはパスワードに誤りがあります');
         }
         $mongoCollection = getMongoCollection('user');
         foreach ($post as $key => $value) {
             $encode = mb_detect_encoding($value, array('UTF-8'));
             if ($encode !== 'UTF-8') {
                 throw new RuntimeException('メールアドレスまたはパスワードに誤りがあります');
             }
         }
         $result = $mongoCollection->find(array('email' => $post['email'], 'password' => getPasswordHash($post['email'], $post['password'], $app->config('salt'))));
         if ($result->count()) {
             session_regenerate_id(true);
             $user = $result->next();
             $_SESSION['user'] = $user;
             $_SESSION['expires'] = time() + (int) $app->config('timeout');
             $app->flash('info', 'ログインしました。');
             $app->getLog()->info('ユーザー名「' . $user['username'] . '」(メールアドレス"' . $user['email'] . '")がログインしました。');
             $app->redirect($app->config('static_path'));
<?php

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../app/config.php';
require __DIR__ . '/../app/db.php';
$app = new \Slim\Slim($config);
$mongoCollection = getMongoCollection('project');
try {
    $id = $argv[1];
    $result = $mongoCollection->find(array('_id' => new MongoId($id)));
    if (!$result->count()) {
        throw new RuntimeException('存在しないプロジェクトです');
    }
    $result = $mongoCollection->remove(array('_id' => new MongoId($id)));
} catch (RuntimeException $e) {
    echo $e->getMessage() . PHP_EOL;
    return;
}
echo 'Project:' . $id . ' removed.' . PHP_EOL;