fix: 修复移动端登录500错误
1. loginIn() 改用 ci_admin 表验证(原查 ci_staff 表 passWord 字段不存在) 2. login() cookie自动登录同步修复 3. good() 页面增加登录态验证 4. login.php 表单 action 修正为 mobile/loginIn 5. login.js 修复 JSON 解析问题(responseType=json 在原生XHR无效) 6. 登录成功返回完整URL跳转地址
This commit is contained in:
@@ -10,15 +10,9 @@ class Mobile extends CI_Controller {
|
|||||||
$user = get_cookie('user');
|
$user = get_cookie('user');
|
||||||
$pwd = get_cookie('pwd');//die($user.$pwd);
|
$pwd = get_cookie('pwd');//die($user.$pwd);
|
||||||
if(!empty($user) && !empty($pwd)){
|
if(!empty($user) && !empty($pwd)){
|
||||||
$list = $this->getUser($user,$pwd);
|
// 2026-04-20 fix: 改用 ci_admin 表验证
|
||||||
if(count($list)>0){
|
$data = $this->mysql_model->get_rows('admin','(username="'.$user.'") or (mobile="'.$user.'") ');
|
||||||
$data = reset($list);
|
if(count($data)>0 && $data['status']==1 && $data['userpwd'] == md5($pwd)){
|
||||||
$this->input->set_cookie('user',$data['number'],3600000);
|
|
||||||
$this->input->set_cookie('pwd',$data['passWord'],3600000);
|
|
||||||
$this->input->set_cookie('userName',$data['name'],3600000);
|
|
||||||
$this->input->set_cookie('deptId',$data['deptId'],3600000);
|
|
||||||
$this->input->set_cookie('deptName',$data['deptName'],3600000);
|
|
||||||
$this->input->set_cookie('score',$data['score'],3600000);
|
|
||||||
redirect('mobile/good','refresh');
|
redirect('mobile/good','refresh');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -28,17 +22,15 @@ class Mobile extends CI_Controller {
|
|||||||
public function loginIn(){
|
public function loginIn(){
|
||||||
$user = str_enhtml($this->input->get_post('user',TRUE));
|
$user = str_enhtml($this->input->get_post('user',TRUE));
|
||||||
$pwd = str_enhtml($this->input->get_post('pwd',TRUE));
|
$pwd = str_enhtml($this->input->get_post('pwd',TRUE));
|
||||||
$list = $this->getUser($user,$pwd);
|
// 2026-04-20 fix: 改用 ci_admin 表登录(原 getUser() 查 ci_staff 表 passWord 字段不存在)
|
||||||
if(count($list)>0){
|
$data = $this->mysql_model->get_rows('admin','(username="'.$user.'") or (mobile="'.$user.'") ');
|
||||||
$data = reset($list);
|
if(count($data)>0 && $data['status']==1 && $data['userpwd'] == md5($pwd)){
|
||||||
$this->input->set_cookie('user',$data['number'],3600000);
|
$this->input->set_cookie('user',$user,3600000);
|
||||||
$this->input->set_cookie('pwd',$data['passWord'],3600000);
|
$this->input->set_cookie('pwd',$pwd,3600000);
|
||||||
|
$this->input->set_cookie('uid',$data['uid'],3600000);
|
||||||
$this->input->set_cookie('userName',$data['name'],3600000);
|
$this->input->set_cookie('userName',$data['name'],3600000);
|
||||||
$this->input->set_cookie('deptId',$data['deptId'],3600000);
|
|
||||||
$this->input->set_cookie('deptName',$data['deptName'],3600000);
|
|
||||||
$this->input->set_cookie('score',$data['score'],3600000);
|
|
||||||
$rtn['code'] = '200';
|
$rtn['code'] = '200';
|
||||||
$rtn['msg'] = 'good';
|
$rtn['msg'] = base_url().'index.php/mobile/good';
|
||||||
}else{
|
}else{
|
||||||
$rtn['code'] = '-1';
|
$rtn['code'] = '-1';
|
||||||
$rtn['msg'] = '账号或密码错误';
|
$rtn['msg'] = '账号或密码错误';
|
||||||
@@ -66,6 +58,11 @@ class Mobile extends CI_Controller {
|
|||||||
if(empty($user)||empty($pwd)){
|
if(empty($user)||empty($pwd)){
|
||||||
$this->load->view('mobile/login',NULL);return;
|
$this->load->view('mobile/login',NULL);return;
|
||||||
}
|
}
|
||||||
|
// 2026-04-20 fix: 改用 ci_admin 表验证
|
||||||
|
$data = $this->mysql_model->get_rows('admin','(username="'.$user.'") or (mobile="'.$user.'") ');
|
||||||
|
if(count($data)==0 || $data['status']!=1 || $data['userpwd'] != md5($pwd)){
|
||||||
|
$this->load->view('mobile/login',NULL);return;
|
||||||
|
}
|
||||||
$this->load->view('mobile/good',NULL);
|
$this->load->view('mobile/good',NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
<div class="login-title"><p>ERP进销存V8标准版</p>
|
<div class="login-title"><p>ERP进销存V8标准版</p>
|
||||||
<i></i>
|
<i></i>
|
||||||
</div>
|
</div>
|
||||||
<form method="post" action="<?php echo base_url()?>index.php/mobile/good">
|
<form method="post" action="<?php echo base_url()?>index.php/mobile/loginIn">
|
||||||
<div class="login-bar">
|
<div class="login-bar">
|
||||||
<ul>
|
<ul>
|
||||||
<li><img src="<?php echo base_url()?>statics/mobile/login/images/login_user.png"><input type="text" class="text" placeholder="请输入用户名" /></li>
|
<li><img src="<?php echo base_url()?>statics/mobile/login/images/login_user.png"><input type="text" class="text" placeholder="请输入用户名" /></li>
|
||||||
|
|||||||
@@ -1,153 +1,136 @@
|
|||||||
window.onload=function(){
|
window.onload=function(){
|
||||||
var aInput=document.getElementsByTagName('input');
|
var aInput=document.getElementsByTagName('input');
|
||||||
var oUser=aInput[0];
|
var oUser=aInput[0];
|
||||||
var oPwd=aInput[1]
|
var oPwd=aInput[1]
|
||||||
var aI=document.getElementsByTagName('i')[0];
|
var aI=document.getElementsByTagName('i')[0];
|
||||||
var sub = document.getElementById("submit");
|
var sub = document.getElementById("submit");
|
||||||
sub.onclick = function(){
|
sub.onclick = function(){
|
||||||
if(oUser.value==""){
|
if(oUser.value==""){
|
||||||
aI.innerHTML='账号不可为空';
|
aI.innerHTML='账号不可为空';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(oPwd.value==""){
|
if(oPwd.value==""){
|
||||||
aI.innerHTML='密码不可为空';
|
aI.innerHTML='密码不可为空';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
/*Ajax.post("loginIn",
|
ajax({
|
||||||
"user=1&pwd=2",
|
type:"POST",
|
||||||
function(rtn){
|
url:"loginIn",
|
||||||
alert(rtn);
|
dataType:"json",
|
||||||
}
|
data:{user:oUser.value,pwd:oPwd.value},
|
||||||
);*/
|
beforeSend:function(){
|
||||||
ajax({
|
//some js code
|
||||||
type:"POST",
|
},
|
||||||
url:"loginIn",
|
success:function(rtn){
|
||||||
dataType:"json",
|
if(rtn.code != '200' && rtn.code != 200)
|
||||||
data:{user:oUser.value,pwd:oPwd.value},
|
aI.innerHTML= rtn.msg;
|
||||||
beforeSend:function(){
|
else
|
||||||
//some js code
|
location.href = rtn.msg;
|
||||||
},
|
},
|
||||||
success:function(rtn){
|
error:function(){
|
||||||
if(rtn.code !=200)
|
console.log("error")
|
||||||
aI.innerHTML= rtn.msg;
|
}
|
||||||
else
|
})
|
||||||
location.href = rtn.msg;
|
|
||||||
},
|
return false;
|
||||||
error:function(){
|
}
|
||||||
console.log("error")
|
|
||||||
}
|
oUser.onfocus=function(){
|
||||||
})
|
aI.innerHTML='';
|
||||||
|
oUser.removeAttribute("placeholder");
|
||||||
return false;
|
}
|
||||||
}
|
|
||||||
|
oUser.onkeyup=function(){}
|
||||||
|
|
||||||
|
oUser.onblur=function(){
|
||||||
//用户名检测
|
if(oUser.value==""){
|
||||||
|
oUser.setAttribute("placeholder","账号不可为空");
|
||||||
oUser.onfocus=function(){
|
}
|
||||||
aI.innerHTML='';
|
}
|
||||||
oUser.removeAttribute("placeholder");
|
|
||||||
}
|
oPwd.onfocus=function(){
|
||||||
|
oPwd.removeAttribute("placeholder");
|
||||||
oUser.onkeyup=function(){
|
}
|
||||||
|
oPwd.onblur=function(){
|
||||||
}
|
if(oPwd.value==""){
|
||||||
|
oPwd.setAttribute("placeholder","请输入确认密码");
|
||||||
oUser.onblur=function(){
|
}
|
||||||
if(oUser.value==""){
|
}
|
||||||
oUser.setAttribute("placeholder","账号不可为空");
|
}
|
||||||
}
|
|
||||||
/* var tel = /1[3|4|5|7|8][0-9]\d{8}$/;
|
var Ajax={
|
||||||
if(!tel.test(this.value)){
|
get: function(url, fn) {
|
||||||
aI.innerHTML='手机号不正确';
|
var obj = new XMLHttpRequest();
|
||||||
}else if(this.value==""){
|
obj.open('GET', url, true);
|
||||||
aI.innerHTML='手机号不可为空';
|
obj.onreadystatechange = function() {
|
||||||
}*/
|
if (obj.readyState == 4 && (obj.status == 200 || obj.status == 304)) {
|
||||||
}
|
fn.call(this, obj.responseText);
|
||||||
|
}
|
||||||
//密码检测
|
};
|
||||||
|
obj.send();
|
||||||
oPwd.onfocus=function(){
|
},
|
||||||
oPwd.removeAttribute("placeholder");
|
post: function (url, data, fn) {
|
||||||
}
|
var obj = new XMLHttpRequest();
|
||||||
oPwd.onblur=function(){
|
obj.open("POST", url, true);
|
||||||
if(oPwd.value==""){
|
obj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
||||||
oPwd.setAttribute("placeholder","请输入确认密码");
|
obj.onreadystatechange = function() {
|
||||||
}
|
if (obj.readyState == 4 && (obj.status == 200 || obj.status == 304)) {
|
||||||
}
|
fn.call(this, obj.responseText);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
obj.send(data);
|
||||||
var Ajax={
|
}
|
||||||
get: function(url, fn) {
|
}
|
||||||
var obj = new XMLHttpRequest(); // XMLHttpRequest对象用于在后台与服务器交换数据
|
|
||||||
obj.open('GET', url, true);
|
function ajax(){
|
||||||
obj.onreadystatechange = function() {
|
var ajaxData = {
|
||||||
if (obj.readyState == 4 && obj.status == 200 || obj.status == 304) { // readyState == 4说明请求已完成
|
type:arguments[0].type || "GET",
|
||||||
fn.call(this, obj.responseText); //从服务器获得数据
|
url:arguments[0].url || "",
|
||||||
}
|
async:arguments[0].async || "true",
|
||||||
};
|
data:arguments[0].data || null,
|
||||||
obj.send();
|
dataType:arguments[0].dataType || "text",
|
||||||
},
|
contentType:arguments[0].contentType || "application/x-www-form-urlencoded",
|
||||||
post: function (url, data, fn) { // datat应为'a=a1&b=b1'这种字符串格式,在jq里如果data为对象会自动将对象转成这种字符串格式
|
beforeSend:arguments[0].beforeSend || function(){},
|
||||||
var obj = new XMLHttpRequest();
|
success:arguments[0].success || function(){},
|
||||||
obj.open("POST", url, true);
|
error:arguments[0].error || function(){}
|
||||||
obj.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); // 添加http头,发送信息至服务器时内容编码类型
|
}
|
||||||
obj.onreadystatechange = function() {
|
ajaxData.beforeSend()
|
||||||
if (obj.readyState == 4 && (obj.status == 200 || obj.status == 304)) { // 304未修改
|
var xhr = createxmlHttpRequest();
|
||||||
fn.call(this, obj.responseText);
|
xhr.open(ajaxData.type,ajaxData.url,ajaxData.async);
|
||||||
}
|
xhr.setRequestHeader("Content-Type",ajaxData.contentType);
|
||||||
};
|
xhr.send(convertData(ajaxData.data));
|
||||||
obj.send(data);
|
xhr.onreadystatechange = function() {
|
||||||
}
|
if (xhr.readyState == 4) {
|
||||||
}
|
if(xhr.status == 200){
|
||||||
function ajax(){
|
var response = xhr.responseText;
|
||||||
var ajaxData = {
|
if(ajaxData.dataType === "json" && response){
|
||||||
type:arguments[0].type || "GET",
|
try { response = JSON.parse(response); } catch(e){}
|
||||||
url:arguments[0].url || "",
|
}
|
||||||
async:arguments[0].async || "true",
|
ajaxData.success(response);
|
||||||
data:arguments[0].data || null,
|
}else{
|
||||||
dataType:arguments[0].dataType || "text",
|
ajaxData.error()
|
||||||
contentType:arguments[0].contentType || "application/x-www-form-urlencoded",
|
}
|
||||||
beforeSend:arguments[0].beforeSend || function(){},
|
}
|
||||||
success:arguments[0].success || function(){},
|
}
|
||||||
error:arguments[0].error || function(){}
|
}
|
||||||
}
|
|
||||||
ajaxData.beforeSend()
|
function createxmlHttpRequest() {
|
||||||
var xhr = createxmlHttpRequest();
|
if (window.ActiveXObject) {
|
||||||
xhr.responseType=ajaxData.dataType;
|
return new ActiveXObject("Microsoft.XMLHTTP");
|
||||||
xhr.open(ajaxData.type,ajaxData.url,ajaxData.async);
|
} else if (window.XMLHttpRequest) {
|
||||||
xhr.setRequestHeader("Content-Type",ajaxData.contentType);
|
return new XMLHttpRequest();
|
||||||
xhr.send(convertData(ajaxData.data));
|
}
|
||||||
xhr.onreadystatechange = function() {
|
}
|
||||||
if (xhr.readyState == 4) {
|
|
||||||
if(xhr.status == 200){
|
function convertData(data){
|
||||||
ajaxData.success(xhr.response)
|
if( typeof data === 'object' ){
|
||||||
}else{
|
var convertResult = "" ;
|
||||||
ajaxData.error()
|
for(var c in data){
|
||||||
}
|
convertResult+= c + "=" + data[c] + "&";
|
||||||
}
|
}
|
||||||
}
|
convertResult=convertResult.substring(0,convertResult.length-1)
|
||||||
}
|
return convertResult;
|
||||||
|
}else{
|
||||||
function createxmlHttpRequest() {
|
return data;
|
||||||
if (window.ActiveXObject) {
|
}
|
||||||
return new ActiveXObject("Microsoft.XMLHTTP");
|
}
|
||||||
} else if (window.XMLHttpRequest) {
|
|
||||||
return new XMLHttpRequest();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function convertData(data){
|
|
||||||
if( typeof data === 'object' ){
|
|
||||||
var convertResult = "" ;
|
|
||||||
for(var c in data){
|
|
||||||
convertResult+= c + "=" + data[c] + "&";
|
|
||||||
}
|
|
||||||
convertResult=convertResult.substring(0,convertResult.length-1)
|
|
||||||
return convertResult;
|
|
||||||
}else{
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user