我如何在代码点火器实现登录模式?



你好,我正在使用堆栈溢出,我想在我的POS方法中实现登录模式,所以我的计划是,每当我点击VOID按钮时,就会弹出一个登录模式来验证用户是否有权取消产品

edit.php下的代码空白产品

<div id="loginModal" class="modal fade" role="dialog">  
<div class="modal-dialog">  
<!-- Modal content-->  
<div class="modal-content">  
<div class="modal-header">  
<button type="button" class="close" data-dismiss="modal">&times;</button>  
<h4 class="modal-title">Login</h4>  
</div>  
<div class="modal-body">  
<label>Username</label>  
<input type="text" name="username" id="username" class="form-control" />  
<br />  
<label>Password</label>  
<input type="password" name="password" id="password" class="form-control" />  
<br />  
<button type="button" name="login_button" id="login_button" class="btn btn-warning">Login</button>  
</div>  
</div>  
</div>  
</div>  

效果如我所料这是我的ajax在edit。php

$(document).ready(function() {
$('#login_button').click(function(){  
var username = $('#username').val();  
var password = $('#password').val();  
if(username != '' && password != '')  
{  
$.ajax({  
url:"action.php",  
method:"POST",  
data: {username:username, password:password},  
success:function(data)  
{  
//alert(data);  
if(data == 'No')  
{  
alert("Wrong Data");  
}  
else  
{  
$('#loginModal').hide();  
location.reload();  
}  
}  
});
}
else {
alert("Both fields are required");
}
});
});

和我的问题是,我正在使用一个代码点火器框架,我不知道如何实现这行代码到我的程序

action.php

<?php  
session_start();  
$connect = mysqli_connect("localhost", "root", "", "bubblebee");  
if(isset($_POST["username"]))  
{  
$query = "  
SELECT * FROM admin_login  
WHERE admin_name = '".$_POST["username"]."'  
AND admin_password = '".$_POST["password"]."'  
";  
$result = mysqli_query($connect, $query);  
if(mysqli_num_rows($result) > 0)  
{  
$_SESSION['username'] = $_POST['username'];  
echo 'Yes';  
}  
else  
{  
echo 'No';  
}  
}  
if(isset($_POST["action"]))  
{  
unset($_SESSION["username"]);  
}  
?>  

当按下两个所需的文件是工作,但用户名和密码似乎有问题,我无法确定什么是我的错误在这里也许我不知道如何实现它在代码点火器?谁能教我一下。

我现在的文件夹结构action。php是这样的

  • 应用程序
    • 视图
      • 订单
        • action.php
        • create.php
        • edit。
        • index . php

edit.phpVoid Products下的代码

<!DOCTYPE html>
<html>
<head>
<title>Login</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
<!--[if lt IE 9]>
<script src="//oss.maxcdn.com/libs/html5shiv/r29/html5.min.js"></script>
<script src="//oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<button class="btn btn-primary" data-toggle="modal" data-target="#myModal">Login</button>
<div class="modal fade" id="myModal">
<div class="modal-dialog">
<div class="modal-content">
<form id="form" role="form">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
<h4 class="modal-title">Login</h4>
</div>
<div class="modal-body">
<div id="messages"></div>
YOUR FORM ELEMENTS HERE
Username: <input type="text" name="username">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Login</button>
</div>
</form>
</div>
</div>
</div>
</div>
<script src="http://code.jquery.com/jquery.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script>
$('#form').submit(function(e) {
var form = $(this);
var formdata = false;
if(window.FormData){
formdata = new FormData(form[0]);
}
var formAction = form.attr('action');
$.ajax({
type        : 'POST',
url         : "<?php echo base_url(); ?>/controllerName/FunctionName",
cache       : false,
data        : formdata ? formdata : form.serialize(),
contentType : false,
processData : false,
dataType: 'json',
success: function(response) {
//TARGET THE MESSAGES DIV IN THE MODAL
if(response.type == 'success') {
$('#messages').addClass('alert alert-success').text(response.message);
} else {
$('#messages').addClass('alert alert-danger').text(response.message);
}
}
});
e.preventDefault();
});
</script>
</body>
</html>

模型代码:

function get_user($username,$password)
{
$this->db->select('*');
$this->db->from('user');
$this->db->where('username',$username);
$this->db->where('password',$password);
$q = $this->db->get();
if ($q->num_rows() > 0) {
return $q->row();
} else
return FALSE;
}

控制器代码:

public function login()
{
$user_email = $this->input->post('user_email', true);
$user_pass = md5($this->input->post('user_pswd', true));
$user_result = $this->M_login->get_user($username,$password));
if ($user_result >0) //active user record is present
{
$this->session->set_userdata('user_session',$user_result);
$this->session->set_flashdata('login_message', '<div class="alert alert-success text-center">You are Successfully Login to your account!</div>');

$url = base_url('Login/billing');
redirect($url);

} else {
$this->session->set_flashdata('err_message', '<div class="alert alert-danger text-center">Invalid email and password!</div>');
redirect("Login/login");
}
}

可以在modal中添加表单

<div id="loginModal" class="modal fade" role="dialog">  
<div class="modal-dialog">  
<!-- Modal content-->  
<form method="post" accept-charset="utf-8" action="<?=url('controller/method')?>" class="email" id="myform">
<div class="modal-content">  
<div class="modal-header">  
<button type="button" class="close" data-dismiss="modal">&times;</button>  
<h4 class="modal-title">Login</h4>  
</div>  
<div class="modal-body">  
<label>Username</label>  
<input type="text" name="username" id="username" class="form-control" />  
<br />  
<label>Password</label>  
<input type="password" name="password" id="password" class="form-control" />  
<br />  
<button type="button" name="login_button" id="login_button" class="btn btn-warning">Login</button>  
</div>  
</div>  
</form>
</div>  
</div>

和创建函数捕获控制器

上的请求
##.../controller.php
function method(){
## create method to 
var_dump($this->input->post());
}

相关内容

  • 没有找到相关文章

最新更新