示例#1
0
});
// PUT route
$app->get('/register', function () use($app) {
    $app->render('register.html');
});
$app->post('/register', function () use($app) {
    $clean = array();
    $name = $_POST['user'];
    $pass = $_POST['pass'];
    $mail = $_POST["mail"];
    if (strlen($name) > 3 && strlen($pass) > 3 && strlen($mail) > 4) {
        $name = trim($name);
        $pass = trim($pass);
        $mail = trim($mail);
        $clean['name'] = stripslashes($name);
        $clean['pass'] = stripslashes($pass);
        $clean['mail'] = stripslashes($mail);
        $oUser = new models\User();
        $result = $oUser->setUser($clean['name'], $clean['pass'], $clean['mail']);
        if ($result) {
            $success = "You are registered successfully! \n Now you can go back and log in";
            $app->render('serverMsg/serverResp.php', array('success' => $success));
        } else {
            $error = "You write wrong data, we cant confirm your registration";
            $app->render('serverMsg/serverResp.php', array('error_msg' => $error));
        }
    } else {
        $error = "The size of the name and password should be over 3 symbols";
        $app->render('serverMsg/serverResp.php', array('error_msg' => $error));
    }
});