Esempio n. 1
0
//     'dbname' => 'adapi',
//     'user' => 'root',
//     'password' => '1qazXSW@',
//     'host' => '192.168.99.100',
//     'driver' => 'pdo_mysql',
//     'charset' => 'utf8'
// );
$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
$em = EntityManager::create($connectionParams, $config);
$app = new \Slim\Slim(array("debug" => true, "templates.path" => "./admin/templates"));
$check_auth = function ($em) {
    return function () use($em) {
        $app = \Slim\Slim::getInstance();
        $token = $app->request->headers("Auth-Token");
        $user = $em->getRepository('App\\Model\\User')->findOneBy(array('token' => $token));
        if (!$user) {
            $app->response->headers->set('Content-Type', 'application/json');
            echo Util::resPonseJson($app, 4003, "Authenation denied", array());
            exit;
        }
        $app->flashNow('user_id', $user->getId());
    };
};
//require routes files
require_once './routes/user.php';
require_once './routes/auth.php';
require_once './routes/account.php';
//require admin routes files
require_once './admin/routes/index.php';
require_once './admin/routes/ad.php';
$app->run();
Esempio n. 2
0
        $em->persist($user_info);
        $em->flush($user_info);
        $app->response->headers->set('Content-Type', 'application/json');
        echo Util::resPonseJson($app, 200, "", array());
        exit;
    } catch (Exception $e) {
        $app->response->headers->set('Content-Type', 'application/json');
        echo Util::resPonseJson($app, 500, "System error.", array());
        exit;
    }
    exit;
});
$app->get('/userinfo/:user_id', $check_auth($em), function ($user_id) use($app, $em) {
    $user = $em->getRepository('App\\Model\\User')->find($user_id);
    if (!$user) {
        $app->response->headers->set('Content-Type', 'application/json');
        echo Util::resPonseJson($app, 4004, "User not exists.", array());
        exit;
    }
    $userInfo = $em->getRepository('App\\Model\\UserInfo')->find($user_id);
    if (!$userInfo) {
        $userInfo = new UserInfo();
    }
    $allInfo = array_merge($user->toArray(), $userInfo->toArray());
    unset($allInfo['password_hash']);
    unset($allInfo['payment_password']);
    unset($allInfo['user_id']);
    $app->response->headers->set('Content-Type', 'application/json');
    echo Util::resPonseJson($app, 200, "", array("user" => $allInfo));
    exit;
});
Esempio n. 3
0
    $user = $em->getRepository('App\\Model\\User')->findOneBy(array('phone' => $phone));
    if (!$user) {
        $app->response->headers->set('Content-Type', 'application/json');
        echo Util::resPonseJson($app, 4004, "User not found", array());
        exit;
    }
    if (password_verify($password, $user->getPassword_hash())) {
        $token = password_hash(strval(time()), PASSWORD_BCRYPT);
        $user->setToken($token);
        $em->flush($user);
        $app->response->headers->set('Content-Type', 'application/json');
        echo Util::resPonseJson($app, 200, "Login success.", array('token' => $token));
        exit;
    } else {
        $app->response->headers->set('Content-Type', 'application/json');
        echo Util::resPonseJson($app, 4001, "Authenation failed.", array());
        exit;
    }
});
$app->get('/auth/logout', $check_auth($em), function () use($app, $em) {
    $user = $em->getRepository('App\\Model\\User')->find($_SESSION['user_id']);
    $user->setToken('');
    $em->persist($user);
    $em->flush();
    $app->response->headers->set('Content-Type', 'application/json');
    echo Util::resPonseJson($app, 200, "Login success.", array('token' => $token));
    exit;
});
$app->get('/phpinfo', function () use($app) {
    echo phpinfo();
});
Esempio n. 4
0
    } catch (Exception $e) {
        $app->response->headers->set('Content-Type', 'application/json');
        echo Util::resPonseJson($app, 500, "System Error", array());
        exit;
    }
});
$app->post('/account/payment_password/check', $check_auth($em), function () use($app, $em) {
    $payment_password = $app->request->params('payment_password');
    if ($payment_password == '' || $payment_password == null) {
        $app->response->headers->set('Content-Type', 'application/json');
        echo Util::resPonseJson($app, 40000, "Invalid Param", array());
        exit;
    }
    $flash = $app->flashData();
    $user_id = isset($flash['user_id']) ? $flash['user_id'] : '';
    $user = $em->getRepository('App\\Model\\User')->find($user_id);
    if (!$user) {
        $app->response->headers->set('Content-Type', 'application/json');
        echo Util::resPonseJson($app, 40004, "User not exists.", array());
        exit;
    }
    if (password_verify($payment_password, $user->getPayment_password())) {
        $app->response->headers->set('Content-Type', 'application/json');
        echo Util::resPonseJson($app, 200, "OK", array());
        exit;
    } else {
        $app->response->headers->set('Content-Type', 'application/json');
        echo Util::resPonseJson($app, 200, "Password Not Match", array());
        exit;
    }
});