软工每日总结28

今天我们决定对用户交互的不足进行修改,主要内容就是添加用户登录的功能。我的任务是完成数据在后台的处理,今天完成的是服务器的部分,使用php完成,主要部分是sql类,提供对用户表的各种操作,以及对错误信息的反馈,数据传输采用json完成。另外,今天也完成了一部分之前程序的修正,经过测试发现某次模块化改进之后的缓存系统并没有正常工作,于是经过检查,解决了问题。

主要代码:

function login($email,$pw)
{
global $DB_H;global $debug;
$sql = "SELECT * FROM {$DB_H}Users WHERE `email`="{$email}" AND `password`="{$pw}"";
if($debug==1)
{
echo $sql;
}
$result = $this->mysqli->query($sql);
$row = mysqli_fetch_array($result);
if ($row)
{
$this->json_out_error("true","login",$row['id']);
$_SESSION['id']=$this->get_id($email, $pw);
}else if(!$this->user_existed($email))
{
$this->json_out_error("false","email haven't registed!".$email);
}else
{
$this->json_out_error("false","login failed;um=".$email."pw:".$pw);
}
$result->close();
}

function insert_user($email,$pw)
{
//echo $email.$pw;
global $DB_H;
$re = $this->user_existed($email);
//echo $re;
if($re)
{
$this->json_out_error("false","email already existed!");
}
else
{
$sql = "INSERT INTO {$DB_H}Users (email, password) VALUES ("{$email}","{$pw}")";
$t=$this->mysqli->query($sql);
if ($t)
{
$this->json_out_error("true","registed",$this->get_id($email, $pw));
$_SESSION['id']=$this->get_id($email, $pw);
}
else
{
$this-> json_out_error("false",-1);
}
}
}
原文地址:https://www.cnblogs.com/evi10032/p/5628179.html