Skip to content

Commit

Permalink
Thêm chức năng đăng ký
Browse files Browse the repository at this point in the history
  • Loading branch information
tutv committed May 9, 2015
1 parent 24b5956 commit 0e9fd67
Show file tree
Hide file tree
Showing 321 changed files with 566 additions and 82,210 deletions.
35 changes: 35 additions & 0 deletions api/sign/signup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

include "../../config.php";
function checkUser($username) {
global $conn;
$sql = "select email from nguoidung where email = '$username'";
$result = mysqli_query( $conn, $sql);
if (mysqli_num_rows($result) > 0) {
return true;
}

return false;
}

function echoJson($result) {
echo json_encode(array("result" => $result));
}

if (isset($_POST['user']) and isset($_POST['pass'])) {
$check = checkUser($_POST['user']);
$username = $_POST['user'];
$password = $_POST['pass'];

if($check == true) {
echoJson(false);
} else {
$password = md5( $password );
$sql = "insert into nguoidung set email = '$username', pass = '$password'";
mysqli_query( $conn, $sql );
echoJson(true);
}
}
else {
echoJson(false);
}
13 changes: 6 additions & 7 deletions css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ body {
background-color: #eee;
}

.form-signin {
.form-signin, .form-signup {
max-width: 500px;
padding: 15px;
margin: 0 auto;
Expand All @@ -160,7 +160,7 @@ body {
.form-signin .checkbox {
font-weight: normal;
}
.form-signin .form-control {
.form-signin .form-control, .form-signup .form-control {
position: relative;
height: auto;
-webkit-box-sizing: border-box;
Expand All @@ -169,20 +169,19 @@ body {
padding: 10px;
font-size: 16px;
}
.form-signin .form-control:focus {
.form-signin .form-control:focus, .form-signup .form-control:focus {
z-index: 2;
}
.form-signin input[type="email"] {
margin-bottom: -1px;
.form-signin input[type="email"], .form-signup input[type="email"] {
margin-bottom: 10px;
border-bottom-right-radius: 0;
border-bottom-left-radius: 0;
}
.form-signin input[type="password"] {
.form-signin input[type="password"], .form-signup input[type="password"] {
margin-bottom: 10px;
border-top-left-radius: 0;
border-top-right-radius: 0;
}
/* Sign up */

#hello-user {
font-weight: bold;
Expand Down
7 changes: 3 additions & 4 deletions includes/form-signin.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
<div class="modal fade" id="form-signin" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<form class="form-signin" role="form">
<form class="form-signin" role="form" method="post">
<label for="inputEmail" class="sr-only">Email</label>
<input type="email" id="inputEmail" class="form-control" placeholder="Email address" required autofocus>
<input type="email" name="username" id="inputEmail" class="form-control" placeholder="Email address" required autofocus>
<label for="inputPassword" class="sr-only">Mật khẩu</label>
<input type="password" id="inputPassword" class="form-control" placeholder="Password" required>
<input type="password" name="password" id="inputPassword" class="form-control" placeholder="Password" required>
<div class="checkbox">
<label>
<input type="checkbox" value="remember-me"> Nhớ tôi
</label>
</div>
<button class="btn btn-lg btn-primary btn-block" type="button" id="btn-signin-submit">Đăng nhập</button>
<span id="result-signin"></span>
</form>
</div>
</div>
Expand Down
15 changes: 15 additions & 0 deletions includes/form-signup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div class="modal fade" id="form-signup" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<form class="form-signup" role="form" data-toggle="validator">
<label for="inputEmail" class="sr-only">Email</label>
<input type="email" id="inputEmail-up" class="form-control" placeholder="Email address" required autofocus>
<label for="inputPassword-up" class="sr-only">Mật khẩu</label>
<input type="password" data-minlength="6" id="inputPassword-up" class="form-control" placeholder="Password" required>
<span class="help-block">Minimum of 6 characters</span>
<input type="password" class="form-control" id="inputPasswordConfirm" data-match="#inputPassword-up" data-match-error="Whoops, these don't match" placeholder="Confirm" required>
<button class="btn btn-lg btn-primary btn-block" type="submit" id="btn-signup-submit">Đăng ký</button>
</form>
</div>
</div>
</div>
13 changes: 7 additions & 6 deletions includes/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@
<!-- <li><a href="#">Dashboard</a></li>-->
<li class="dropdown" id="tool-user"><a class="dropdown-toggle" data-toggle="dropdown" href="#">Công cụ <span class="caret"></span></a>
<ul class="dropdown-menu">
<li id="btn-save-table"><a href="javascript:void();" >Lưu lại</a></li>
<li id="btn-share-table"><a href="javascript:void();" >Chia sẻ</a></li>
<li id="btn-export-table"><a href="javascript:void();" >Xuất file</a></li>
<li id="btn-save-table"><a href="#" >Lưu lại</a></li>
<li id="btn-share-table"><a href="#" >Chia sẻ</a></li>
<li id="btn-export-table"><a href="#" >Xuất file</a></li>
</ul>
</li>
</ul>

<ul class="nav navbar-nav navbar-right">
<li class="dropdown" id="signined" style="display: none;" data-target="out"><a class="dropdown-toggle" data-toggle="dropdown" href="#">Xin chào <span id="hello-user"></span><span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Chỉnh sửa</a></li>
<li id="btn-signout"><a href="javascript:void();" >Đăng xuất</a></li>
<li id="btn-edit-profile"><a href="#">Chỉnh sửa</a></li>
<li id="btn-signout"><a href="#" >Đăng xuất</a></li>
</ul>
</li>
<li id="btn-signup" style="display: none;"><a href="#"><span class="glyphicon glyphicon-user"></span> Đăng kí</a></li>
<li id="btn-signup" style="display: none;"><a href="#" data-target="#form-signup" data-toggle="modal"><span class="glyphicon glyphicon-user"></span> Đăng kí</a></li>
<li id="btn-signin" style="display: none;"><a href="#" data-target="#form-signin" data-toggle="modal"><span class="glyphicon glyphicon-log-in"></span> Đăng nhập</a></li>
<li><a href="#" title="Xem hướng dẫn sử dụng ứng dụng"><span class="glyphicon glyphicon-bullhorn"></span> Trợ giúp</a></li>
</ul>
Expand All @@ -31,3 +31,4 @@
</nav>

<?php include "form-signin.php"; ?>
<?php include "form-signup.php"; ?>
4 changes: 3 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.tooltipster.min.js"></script>
<script src="js/jquery.noty.packaged.min.js"></script>
<script src="js/validator.js"></script>
</head>
<body>
<div id="page" style="padding-top: 13px">
Expand Down Expand Up @@ -160,8 +161,9 @@
</div>

<!--Lấy footer-->
<?php include("includes/footer.php"); ?>
<?php include "includes/footer.php"; ?>
</div>
<script src="js/sign.js"></script>
<script src="js/main.js"></script>
</body>
</html>
116 changes: 1 addition & 115 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,118 +365,4 @@ function removeMHformArr(id) {
//Kiểm tra có đăng ký trùng môn không?
function ktTrungMon(id) {
return (monHocs.indexOf(id) >= 0);
}

//Thông báo cho người dùng biết họ gặp lỗi hay thông báo gì?
function thongBao(text, type) {
var n = noty({
text : text,
type : type,
dismissQueue: true,
closeWith : ['click', 'backdrop', 'hover', 'button'],
modal : false,
layout : 'topLeft',
theme : 'relax',
maxVisible : 10,
timeout: 200,
animation: {
open: 'animated bounceInUp', // Animate.css class names
close: 'animated bounceOutRight', // Animate.css class names
easing: 'swing', // unavailable - no need
speed: 500 // unavailable - no need
}
});
}

$("#btn-signin-submit").click(function () {
var user = $("#inputEmail").val();
var pass = $("#inputPassword").val();

$.ajax({
url : "api/sign/signin.php",
method : "POST",
dataType: "json",
data : {user: user, pass: pass},
success : function(data) {
var resultDOM = $("#result-signin");
if (data.result == true) {
$("#form-signin").modal("hide");
signin();
} else {
resultDOM.text("Đăng nhập thất bại");
resultDOM.addClass("bg-danger");
resultDOM.show();

}
}
});
});

$("#btn-signout").click(function() {
$.get("api/sign/signout.php");
signout();
});

function signout() {
var signinDOM = $("#signined");
signinDOM.hide();
signinDOM.attr("data-target", "out");
$("#btn-signup").show();
$("#btn-signin").show();
}

function signin() {
$.ajax({
url: "api/sign/getStatus.php",
method: "GET",
dataType: "json",
success: function(data) {
if (data.status == true) {
$("#hello-user").text(data.user);
var signinDOM = $("#signined");
signinDOM.show();
signinDOM.attr("data-target", "in");
$("#btn-signup").hide();
$("#btn-signin").hide();
}
}
});
}

function getStatusSign() {
var status = $("#signined").attr("data-target");
return (status == "in");
}

$("#btn-save-table").click(function () {
var sign = getStatusSign();
if (!sign) {
$("#form-signin").modal("show");
return;
}

//Nếu đã đăng nhập thì xử lý theo tool
alert("Chức năng đang hoàn thiện");
});

$("#btn-share-table").click(function () {
var sign = getStatusSign();
if (!sign) {
$("#form-signin").modal("show");
return;
}

//Nếu đã đăng nhập thì xử lý theo tool
alert("Chức năng đang hoàn thiện");
});

$("#btn-export-table").click(function () {
var sign = getStatusSign();
if (!sign) {
$("#form-signin").modal("show");
return;
}

//Nếu đã đăng nhập thì xử lý theo tool
alert("Chức năng đang hoàn thiện");
});
}
Loading

0 comments on commit 0e9fd67

Please sign in to comment.