diff --git a/class/Sql.php b/class/Sql.php index afec125..b0be535 100644 --- a/class/Sql.php +++ b/class/Sql.php @@ -5,12 +5,22 @@ * https://www.x-lf.com/ */ +/** + * 数据库模块 + * + * @since v1.0.0-Alpha + * @author 筱锋xiao_lfeng + */ class Sql { /** + * 数据库连接模块 + * * @return false|mysqli + * @author 筱锋xiao_lfeng + * @since v1.0.0-Alpha */ - protected static function MySqlConn() + private static function MySqlConn() { // 从文件获取数据 $Array_ConfigData = null; @@ -27,15 +37,18 @@ protected static function MySqlConn() } /** - * MySQL查找库 | + * MySQL查找库 + *
+ * 激活码为 50 位固定字符,其合法性规定按照下列正则表达式确定 + * + * @author 筱锋xiao_lfeng + * @since v1.0.0-Alpha * @var Array $Json_Data 最终数据编译输出 * @var array $Array_ConfigData 配置文件 */ @@ -55,45 +62,41 @@ // 邮件发送 if ($ClassMailer->PostMail($PostData['email'], 1, $Data_Captcha)) Normal::Output(200); - else Normal::Output(201); - } else Normal::Output(300); - } else Normal::Output(500); - } else Normal::Output(301); - } else Normal::Output(300); - } else Normal::Output(600); - } else Normal::Output(401); - } else Normal::Output(400); + else { + Normal::Output(201); + } + } else { + Normal::Output(300); + } + } else { + Normal::Output(500); + } + } else { + Normal::Output(301); + } + } else { + Normal::Output(300); + } + } else { + Normal::Output(600); + } + } else { + Normal::Output(401); + } + } else { + Normal::Output(400); + } } else { // 数据库查找用户是否存在 $AResult_User = Sql::SELECT("SELECT * FROM `index`.xf_user WHERE `uid`='{$_COOKIE['user']}'"); if ($AResult_User['output'] == 'Success') { - $Json_Data = [ - 'output' => "AlReadyLogin", - 'code' => 403, - 'data' => [ - 'message' => "您已登录", - ], - ]; + Normal::CustomOutput("AlReadyLogin", 403, "您已登录"); } else if ($AResult_User['output'] == 'EmptyResult') { - $Json_Data = [ - 'output' => "IllegalLogin", - 'code' => 403, - 'data' => [ - 'message' => "非法登录", - ], - ]; + Normal::CustomOutput("IllegalLogin", 403, "非法登录"); } else { - $Json_Data = [ - 'output' => $AResult_User['output'], - 'code' => 403, - 'data' => [ - 'message' => "数据库搜索类型错误", - ], - ]; + Normal::CustomOutput($AResult_User['output'], 403, "数据库搜索类型错误"); } - echo json_encode($Json_Data, JSON_UNESCAPED_UNICODE); } } else { Normal::Output(100); -} -End: \ No newline at end of file +} \ No newline at end of file diff --git a/public/api/auth/registerCheck/index.php b/public/api/auth/registerCheck/index.php index 49370c1..8f02c68 100644 --- a/public/api/auth/registerCheck/index.php +++ b/public/api/auth/registerCheck/index.php @@ -6,6 +6,13 @@ */ /** + * 此页面为注册验证页面 + * 当用户执行注册后(register 模块)执行完毕之后,会给用户发送邮件激活,相对应的激活码会发送至指定邮箱,用户需要根据邮箱内容进入此位置进行激活操作 + *
+ * 激活码为 50 位固定字符,其合法性规定按照下列正则表达式确定 + * + * @author 筱锋xiao_lfeng + * @since v1.0.0-Alpha * @var array $Json_Data 最终数据编译输出 * @var array $Array_ConfigData 配置文件 */ @@ -22,16 +29,49 @@ // 函数构建 if ($Array_ConfigData['Session'] == $_SERVER['HTTP_SESSION']) { /* 检查通讯密钥是否正确 */ + // check user login if (!empty($_COOKIE['user'])) { - + // check user cookie for user + if (preg_match("/^[0-9]+$/", $_COOKIE['user'])) { + // check the user code is true + if (!empty($GetData['code'])) { + // check user verify code have right input + if (preg_match("/^[0-9A-Za-z]{50}/", $GetData['code'])) { + // put user verify code into sql to select + $AResult_Code = Sql::SELECT("SELECT * FROM `index`.`xf_email_verify` WHERE `code`='{$GetData['code']}'"); + // check sql data not empty + if ($AResult_Code['output'] = "Success") { + if ($_COOKIE['user'] == $AResult_Code['data']->uid) { + // update this user info in sql (update xf_user.email_verify) + if (Sql::UPDATE("UPDATE `index`.xf_user SET `email_verify`=1 WHERE `uid`='{$_COOKIE['user']}'")) { + // delete the email_verify + if (Sql::DELETE("DELETE FROM `index`.xf_email_verify WHERE `id`='{$AResult_Code['data']->id}'")) { + Normal::Output(200); + } else { + Normal::Output(303); + } + } else { + Normal::Output(302); + } + } else { + Normal::CustomOutput("CodeNotYour", 403, "这个验证码不是你"); + } + } else { + // SqlSelectFail__CodeEmpty + Normal::Output(301, null, "CodeEmpty"); + } + } else { + Normal::CustomOutput("CodeFormat", 403, "激活码格式错误"); + } + } else { + Normal::CustomOutput("NoCode", 403, "请提供激活码"); + } + } else { + // userFormat + Normal::Output(402); + } } else { - $Json_Data = [ - 'output' => 'NoLogin', - 'code' => 502, - 'data' => [ - 'message' => '需要登陆', - ], - ]; + Normal::CustomOutput("NoLogin", 502, "需要登录"); } } else { // 编译输出