Add: maestro login php

This commit is contained in:
2018-06-26 18:07:15 +09:00
parent f3b51ae5a2
commit 77afebbb3a
7 changed files with 131 additions and 17 deletions
+3
View File
@@ -11,6 +11,9 @@
<script type="text/javascript" src="./../../../resources/jquery/jquery-3.3.1.min.js"></script> <script type="text/javascript" src="./../../../resources/jquery/jquery-3.3.1.min.js"></script>
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
if(sessionStorage.getItem("maestroID") !== null)
location.href = './../maestro/main_menu.html';
$("#home").click(function(event) { $("#home").click(function(event) {
console.log("home clicked"); console.log("home clicked");
}) })
+3 -1
View File
@@ -3,12 +3,14 @@
<a href="./../main/index.html" id="home" class="btn btn-orange" style="padding: 20px;">첫 화면</a> <a href="./../main/index.html" id="home" class="btn btn-orange" style="padding: 20px;">첫 화면</a>
</span> </span>
<div style="width: 100%; text-align: right;" >
<span class="col alignRight"> <span class="col alignRight">
<a href="./../maestro/login.html" id="login_maestro" class="btn btn-sea">마에스트로<br/>로그인</a> <a href="./../maestro/login.html" id="login_maestro" class="btn btn-sea">마에스트로<br/>로그인</a>
</span> </span>
<span class="col alignRight"> <span class="col alignRight">
<a href="./../client/login.html" target="_blank" id="login_player" class="btn btn-rouge" style="padding: 20px;">학생 연습</a> <a href="#" target="_blank" id="login_player" class="btn btn-rouge" style="padding: 20px;">학생 연습</a>
</span> </span>
</div>
</div> </div>
+12 -2
View File
@@ -1,11 +1,21 @@
<div class="container"> <script>
function logout() {
sessionStorage.clear();
location.href = './../main/index.html';
}
</script>
<div class="container">
<span class="col two"> <span class="col two">
<a href="./../main/index.html" id="home" class="btn btn-orange" style="padding: 1.1em;">첫 화면</a> <a href="./../main/index.html" id="home" class="btn btn-orange" style="padding: 1.1em;">첫 화면</a>
</span> </span>
<span class="col two" style="float: right;"> <span class="col two" style="float: right;">
<a href="#" id="logout_maestro" class="btn btn-sea">마에스트로<br/>로그아웃</a> <a href="#" id="logout_maestro" class="btn btn-sea" onClick="logout()">마에스트로<br/>로그아웃</a>
</span> </span>
<span class="col two" style="float: right;"> <span class="col two" style="float: right;">
+40 -12
View File
@@ -10,30 +10,58 @@
} }
</style> </style>
<script>
function login() {
let name = $("#maestro_name").val();
let password = $("#password").val();
let xhr = new XMLHttpRequest(); //new로 생성.
xhr.open('POST', './../server/maestro/login.php', true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send("maestro_name=" + name + "&password=" + password);
//응답
xhr.onload = function() {
if(xhr.readyState === 4 && xhr.status === 200) {
let replyJSON = JSON.parse(xhr.responseText);
// console.log(replyJSON);
// if(replyJSON !== null)
// console.log(replyJSON);
// if(replyJSON["MaestroID"] !== undefined)
// console.log(replyJSON["MaestroID"]);
if(replyJSON !== null && replyJSON["MaestroID"] !== undefined && replyJSON["MaestroID"] !== null) {
sessionStorage.setItem("maestroID", replyJSON["MaestroID"]);
location.href = './../maestro/main_menu.html';
} else {
$("#error_message").val(replyJSON["ERROR"]);
}
}
}
}
</script>
<div class="container"> <div class="container">
<div class="login"> <div class="login">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div> <div>
<form action="/action_page.php" method="get" id="maestro_login">
마에스트로 아이디 마에스트로 아이디
<input type="text" name="maestro_id"><br/> <input type="text" id="maestro_name" name="maestro_name"><br/>
암호 암호
<input type="password" name="maestro_id"><br/> <input type="password" id="password" name="password"><br/>
</form>
</div> </div>
<div class="col alignCenter"> <div class="col alignCenter">
<a href="./../maestro/main_menu.html" id="faq" class="btn btn-sea width400">로그인</a> <a id="login" class="btn btn-sea width400" onClick="login()">로그인</a>
</div> </div>
<textarea id="error_message">
</textarea>
</div> </div>
@@ -41,7 +69,7 @@
<div class="register"> <div class="register">
<div class="col alignCenter" style="float: center;"> <div class="col alignCenter" style="float: center;">
<a href="./../maestro/register.html" id="faq" class="btn btn-sea width400">마에스트로<br/>가입</a> <a href="./../maestro/register.html" id="register" class="btn btn-sea width400">마에스트로<br/>가입</a>
</div> </div>
<ol> <ol>
+71
View File
@@ -0,0 +1,71 @@
<?php
header('Content-Type: application/json');
$maestro_name = $_POST["maestro_name"];
$password = $_POST["password"];
/*
if(!is_numeric($enterCode)) {
send_error_code('생년월일이 숫자가 아닙니다. : '.$enterCode);
exit;
} else if(strlen($enterCode) != 6) {
send_error_code('6자리 숫자값을 정확히 입력하세요 : YYMMDD (예 : 120131) : '.$enterCode);
exit;
}
*/
include "./../setup/connect_db.php";
$maestro_id = get_maestro_id($maestro_name);
if($maestro_id === null) {
$replyJSON["ERROR"] = "마에스트로 아이디가 없습니다";
echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
$db_conn->close();
exit;
}
$replyJSON = login($maestro_name, $password);
if($replyJSON === null || $replyJSON[MaestroID] === null) {
$replyJSON["ERROR"] = "비밀번호를 잘못 입력하셨습니다.";
echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
$db_conn->close();
exit;
}
echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
$db_conn->close();
exit;
function get_maestro_id($maestro_name) {
global $db_conn;
$query = "SELECT MaestroID FROM moty_maestro WHERE Name=?";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('s', $maestro_name);
$stmt->execute();
$stmt->bind_result($maestro_id);
// while($stmt->fetch()) {
// ;
// }
$stmt->fetch();
$stmt->close();
return $maestro_id;
}
function login($maestro_name, $password) {
global $db_conn;
$query = "SELECT MaestroID FROM moty_maestro WHERE Name=? AND Password=?";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('ss', $maestro_name, $password);
$stmt->execute();
$stmt->bind_result($maestro_id);
// while($stmt->fetch())
$stmt->fetch();
$stmt->close();
$replyJSON["MaestroID"] = $maestro_id;
return $replyJSON;
}
?>
+1 -1
View File
@@ -24,8 +24,8 @@ $result = mysqli_query($db_conn, $query);
function send_error_message($replyJSON, $error_message) { function send_error_message($replyJSON, $error_message) {
$replyJSON["ERROR"] = $error_message; $replyJSON["ERROR"] = $error_message;
$db_conn->close();
echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE); echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
$db_conn->close();
} }
?> ?>
+1 -1
View File
@@ -1,7 +1,7 @@
CREATE TABLE moty_maestro ( CREATE TABLE moty_maestro (
MaestroID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, MaestroID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
Name CHAR(50) NOT NULL, Name CHAR(50) NOT NULL,
EnterCode CHAR(10) NOT NULL, Password CHAR(10) NOT NULL,
Email CHAR(50) NOT NULL, Email CHAR(50) NOT NULL,
AccountType INT UNSIGNED NOT NULL, AccountType INT UNSIGNED NOT NULL,
AccountStatus INT UNSIGNED NOT NULL, AccountStatus INT UNSIGNED NOT NULL,