用户登录组件
This commit is contained in:
parent
4e0d4024db
commit
cc59903b29
|
@ -88,6 +88,14 @@ private static function OutputMessage(int $gType, int $bCode)
|
||||||
if ($bCode == 0) return 'emailFormat';
|
if ($bCode == 0) return 'emailFormat';
|
||||||
else if ($bCode == 1) return 405;
|
else if ($bCode == 1) return 405;
|
||||||
else return "邮箱格式不符合";
|
else return "邮箱格式不符合";
|
||||||
|
else if ($gType == 402)
|
||||||
|
if ($bCode == 0) return 'userFormat';
|
||||||
|
else if ($bCode == 1) return 405;
|
||||||
|
else return "用户格式不符合";
|
||||||
|
else if ($gType == 403)
|
||||||
|
if ($bCode == 0) return 'passwordIncorrect';
|
||||||
|
else if ($bCode == 1) return 403;
|
||||||
|
else return "密码不正确";
|
||||||
else if ($gType == 500)
|
else if ($gType == 500)
|
||||||
if ($bCode == 0) return 'CaptchaEffective';
|
if ($bCode == 0) return 'CaptchaEffective';
|
||||||
else if ($bCode == 1) return 200;
|
else if ($bCode == 1) return 200;
|
||||||
|
@ -96,6 +104,10 @@ private static function OutputMessage(int $gType, int $bCode)
|
||||||
if ($bCode == 0) return 'AlReadyUser';
|
if ($bCode == 0) return 'AlReadyUser';
|
||||||
else if ($bCode == 1) return 403;
|
else if ($bCode == 1) return 403;
|
||||||
else return "已经有这个用户";
|
else return "已经有这个用户";
|
||||||
|
else if ($gType == 601)
|
||||||
|
if ($bCode == 0) return 'NoUser';
|
||||||
|
else if ($bCode == 1) return 403;
|
||||||
|
else return "没有这个用户";
|
||||||
else
|
else
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,19 @@
|
||||||
# OutputMessage 标准对照表
|
# OutputMessage 标准对照表
|
||||||
|
|
||||||
| 序号 | output内容 | HTTP状态码 | 中文解释 |
|
| 序号 | output内容 | HTTP状态码 | 中文解释 |
|
||||||
|-----|------------------|---------|------------------------------|
|
|-----|-------------------|---------|------------------------------|
|
||||||
| 100 | SessionError | 502 | 通讯密钥错误 |
|
| 100 | SessionError | 502 | 通讯密钥错误 |
|
||||||
| 200 | Success | 200 | 操作成功 |
|
| 200 | Success | 200 | 操作成功 |
|
||||||
| 201 | SuccessButEmail | 200 | 操作成功但邮件发送失败 |
|
| 201 | SuccessButEmail | 200 | 操作成功但邮件发送失败 |
|
||||||
| 300 | SqlInsertFail | 400 | 数据表内容插入失败 |
|
| 300 | SqlInsertFail | 400 | 数据表内容插入失败 |
|
||||||
| 301 | SqlSelectFail | 400 | 数据表内容查询失败 |
|
| 301 | SqlSelectFail | 400 | 数据表内容查询失败 |
|
||||||
| 310 | TokenTooShort | 502 | Token长度过短 |
|
| 310 | TokenTooShort | 502 | Token长度过短 |
|
||||||
| 311 | TokenTooLong | 502 | Token长度过长 |
|
| 311 | TokenTooLong | 502 | Token长度过长 |
|
||||||
| 400 | usernameFormat | 405 | 用户名格式不符合 (格式允许0-9,A-Z,a-z及_) |
|
| 400 | usernameFormat | 405 | 用户名格式不符合 (格式允许0-9,A-Z,a-z及_) |
|
||||||
| 401 | emailFormat | 405 | 邮箱格式不符合 |
|
| 401 | emailFormat | 405 | 邮箱格式不符合 |
|
||||||
| 500 | CaptchaEffective | 200 | 激活码任然有效 |
|
| 402 | userFormat | 405 | 用户格式不符合 |
|
||||||
| 600 | AlReadyUser | 403 | 已经有这个用户 |
|
| 403 | passwordIncorrect | 403 | 密码不正确 |
|
||||||
| | | | |
|
| 500 | CaptchaEffective | 200 | 激活码任然有效 |
|
||||||
| | | | |
|
| 600 | AlReadyUser | 403 | 已经有这个用户 |
|
||||||
|
| 601 | NoUser | 403 | 没有这个用户 |
|
||||||
|
| | | | |
|
49
public/api/auth/login/index.php
Normal file
49
public/api/auth/login/index.php
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Copyright © 2016 - 2023 筱锋xiao_lfeng. All Rights Reserved.
|
||||||
|
* 开发开源遵循 MIT 许可,若需商用请联系开发者
|
||||||
|
* https://www.x-lf.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Array $Json_Data 最终数据编译输出
|
||||||
|
* @var array $Array_ConfigData 配置文件
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Mailer\SendMail;
|
||||||
|
|
||||||
|
session_start();
|
||||||
|
// 引入配置
|
||||||
|
include dirname(__FILE__, 5) . "/Modules/API/header.php";
|
||||||
|
require dirname(__FILE__, 5) . "/class/Sql.php";
|
||||||
|
require dirname(__FILE__, 5) . "/class/Token.php";
|
||||||
|
require dirname(__FILE__, 5) . "/class/Mailer/SendMail.php";
|
||||||
|
require dirname(__FILE__, 5) . "/class/Normal.php";
|
||||||
|
require dirname(__FILE__, 5) . "/class/Key.php";
|
||||||
|
|
||||||
|
// 类配置
|
||||||
|
$ClassToken = new Token(40);
|
||||||
|
$ClassMailer = new SendMail();
|
||||||
|
|
||||||
|
// 数据获取类型
|
||||||
|
$PostData = file_get_contents('php://input');
|
||||||
|
$PostData = json_decode($PostData, true);
|
||||||
|
|
||||||
|
// 逻辑构建
|
||||||
|
if ($Array_ConfigData['Session'] == $_SESSION['HTTP_SESSION']) {
|
||||||
|
// 检查用户提交数据
|
||||||
|
if (preg_match('/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/', $PostData['user']) || preg_match('/^[0-9A-Za-z_]]/', $PostData['user'])) {
|
||||||
|
// 数据库查找用户
|
||||||
|
$AResult_User = Sql::SELECT("SELECT * FROM `index`.xf_user WHERE `username`='{$PostData['user']}' OR `email`='{$PostData['user']}'");
|
||||||
|
if ($AResult_User == 'Success') {
|
||||||
|
// 判断密码是否正确
|
||||||
|
if (password_verify($PostData['password'], $AResult_User['data'][0]->password)) {
|
||||||
|
// 密码正确,操作结果
|
||||||
|
if (Sql::UPDATE("UPDATE `index`.xf_user SET `login_time`='" . time() . "',`login_ip`='" . $_SERVER['REMOTE_ADDR'] . "' WHERE `username`='{$PostData['user']}' OR `email`='{$PostData['user']}'")) {
|
||||||
|
// 输出结果
|
||||||
|
Normal::Output(200);
|
||||||
|
} else Normal::Output(300);
|
||||||
|
} else Normal::Output(403);
|
||||||
|
} else Normal::Output(601);
|
||||||
|
} else Normal::Output(402);
|
||||||
|
} else Normal::Output(100);
|
|
@ -17,7 +17,7 @@
|
||||||
include dirname(__FILE__, 5) . "/Modules/API/header.php";
|
include dirname(__FILE__, 5) . "/Modules/API/header.php";
|
||||||
require dirname(__FILE__, 5) . "/class/Sql.php";
|
require dirname(__FILE__, 5) . "/class/Sql.php";
|
||||||
require dirname(__FILE__, 5) . "/class/Token.php";
|
require dirname(__FILE__, 5) . "/class/Token.php";
|
||||||
require dirname(__FILE__, 5) . "/class/Mailer/Mailer\SendMail.php";
|
require dirname(__FILE__, 5) . "/class/Mailer/SendMail.php";
|
||||||
require dirname(__FILE__, 5) . "/class/Normal.php";
|
require dirname(__FILE__, 5) . "/class/Normal.php";
|
||||||
require dirname(__FILE__, 5) . "/class/Key.php";
|
require dirname(__FILE__, 5) . "/class/Key.php";
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user