diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..0ce0dcb --- /dev/null +++ b/.htaccess @@ -0,0 +1,3 @@ +RewriteEngine On + +RewriteRule ^([^.]+)$ index.php?param=$1 [QSA,L] \ No newline at end of file diff --git a/actions/user.php b/actions/user.php new file mode 100644 index 0000000..5de1a9e --- /dev/null +++ b/actions/user.php @@ -0,0 +1,42 @@ + $userid, + 'password' => $pass, + ] = $_POST; + + $user = fetch("SELECT * FROM users WHERE id = ? AND password = password(?)", [$userid, $pass]); + + access($user, "아이디 또는 비밀번호가 잘못되었습니다."); + + $_SESSION['user'] = $user; + alert('로그인 되었습니다.'); + move('/'); + + break; + + case 'join' : + [ + 'userid' => $userid, + 'password' => $pass, + 'password_chk' => $passchk, + 'username' => $username + ] = $_POST; + + access($userid !== "" && $pass !== "" && $username !== "", "빈칸이 존재합니다."); + access($pass == $passchk, "비밀번호 재입력의 값이 잘못되었습니다."); + + $sql = "INSERT INTO users(`id`, `name`, `password`) VALUES (?, ?, PASSWORD(?))"; + + access(execute($sql, [$userid, $username, $pass]), "DB 에러"); + + alert("회원가입 완료."); + move("./login"); + + break; + + default: break; +} \ No newline at end of file diff --git a/actions/userSearch.php b/actions/userSearch.php new file mode 100644 index 0000000..aa4182c --- /dev/null +++ b/actions/userSearch.php @@ -0,0 +1,14 @@ + $searchbox, + 'searchbtn' => $searchbtn, + ] = $_POST; + + $user = fetchAll("INSERT INTO users(`id`, `name`) VALUES(?,?)", [$searchbox]); + +} \ No newline at end of file diff --git a/api/search.php b/api/search.php new file mode 100644 index 0000000..a06ece8 --- /dev/null +++ b/api/search.php @@ -0,0 +1,3 @@ +alert('{$msg}');"; +} + +function move($url = false) +{ + echo ""; + exit; +} + +function access($bool, $msg, $url = false) +{ + if (!$bool) { + alert($msg); + move($url); + } +} + +function execute($sql, $data = []) +{ + $db = new PDO("mysql:host=localhost; dbname=member; charset=utf8mb4;", "root", ""); + $result = $db->prepare($sql); + $result->execute($data); + $db = null; + return $result; +} + +function fetch($sql, $data = []) +{ + return execute($sql, $data)->fetch(PDO::FETCH_OBJ); +} + +function fetchAll($sql, $data = []) +{ + return execute($sql, $data)->fetchAll(PDO::FETCH_OBJ); +} \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..044288f --- /dev/null +++ b/index.php @@ -0,0 +1,16 @@ + Array(6) + .fill(0) + .map(() => Math.floor(Math.random() * code.length)) + .map(index => code[index]) + .join(''); + +document.querySelector('#maincaptcha').value = getCaptchaString(); + +if(document.getElementById("maincaptcha").length < 7){ + document.getElementById("maincaptcha").empty(); +} +// document.oncontextmenu = function() {return false}; +// document.ondragstart = function() {return false}; +// document.onselectstart = function() {return false}; \ No newline at end of file diff --git a/js/profile.js b/js/profile.js new file mode 100644 index 0000000..61a1b8f --- /dev/null +++ b/js/profile.js @@ -0,0 +1,6 @@ +function friend_box(obj) { + let id = document.createElement("div"); + id.innerHTML = obj.id; + document.querySelector(".result").appendChild(id); + +}; \ No newline at end of file diff --git a/js/usersearch.js b/js/usersearch.js new file mode 100644 index 0000000..8c34f55 --- /dev/null +++ b/js/usersearch.js @@ -0,0 +1,20 @@ +const form = document.getElementsByTagName("form")[0]; +form.addEventListener("submit", function (e) { + e.preventDefault(); + + if (e.target.search.value != "" || e.target.search.value < -1) { + const url = `/api/search?q=${e.target.search.value}`; + + let result = document.getElementsByClassName("result"); + fetch(url) + .then(res => res.json()) + .then(data => { + data?.forEach(item => { + friend_box(item); + }) + }); + + } else alert("검색어를 입력해라"); + + // const box = document.getElementById("searchbox").value; +}) \ No newline at end of file diff --git a/view/template/footer.php b/view/template/footer.php new file mode 100644 index 0000000..a0a182b --- /dev/null +++ b/view/template/footer.php @@ -0,0 +1,5 @@ +
+ + +