示例#1
0
        $db = new MySqlDAO();
        $userMapper = new UserMapper($db);
        $userMapper->insert($user);
        die("User registration was successful!");
    } else {
        die("Input all params!");
    }
});
$rout_r->map('GET', '/api/user/login/', function () {
    session_start();
    global $GLOBALS;
    $query = $GLOBALS['query'];
    if (isset($query["username"]) || isset($query["password"])) {
        $db = new MySqlDAO();
        $userMapper = new UserMapper($db);
        $user = $userMapper->findByUserName($query["username"]);
        $userID = $user->getID();
        if (count($user) != 0 && isset($userID) && $userID != null) {
            if (md5($query["password"]) == $user->getPassword()) {
                $_SESSION['userID'] = $userID;
                (new ReportingFramework())->report(['condition' => "success", 'message' => $GLOBALS['url']]);
            } else {
                (new ReportingFramework())->report(['condition' => "failure", 'message' => "Wrong Password!"]);
            }
        } else {
            die("User not found!");
        }
    } else {
        die("Input all params!");
    }
});