forked from XiaoLFeng/XF_Index
友链创建模块
This commit is contained in:
parent
b46297e71c
commit
4d498d0c65
|
@ -12,8 +12,8 @@
|
|||
|
||||
class MailTemplate
|
||||
{
|
||||
private static string $GCode;
|
||||
private static int $NowTime;
|
||||
protected static ?string $GCode;
|
||||
protected static string $NowTime;
|
||||
|
||||
/**
|
||||
* 检查使用邮件发送模板
|
||||
|
@ -24,12 +24,11 @@ public static function Templates(string $G_code = null): ?string
|
|||
{
|
||||
// 赋值给全局
|
||||
self::$GCode = $G_code;
|
||||
self::$NowTime = time();
|
||||
self::$NowTime = date("Y-m-d H:i");
|
||||
|
||||
// 判断发送内容
|
||||
if (SendMail::$EmailType == 1) return self::Register();
|
||||
|
||||
return null;
|
||||
else return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -45,7 +44,8 @@ private static function Register(): string
|
|||
$getEndTime = date("Y年m月d日 H:i:s", time() + SendMail::$ExpTime);
|
||||
$getExpTime = (double)SendMail::$ExpTime / 60;
|
||||
$getYear = date('Y');
|
||||
$getDomain = $_SERVER['SERVER_NAME'];
|
||||
$getDomain = SendMail::$getDomain;
|
||||
$GCode = self::$GCode;
|
||||
// 结果返回
|
||||
return <<<EOF
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
@ -74,10 +74,15 @@ private static function Register(): string
|
|||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 0px 5px 5px 0px;color: #000000; font-family: Arial, sans-serif; font-size: 20px;">
|
||||
<a href="$getDomain/account/activation.php"><button style="background-color: #008CBA;font-size: 16px;border-radius: 8px;">点击激活</button></a>
|
||||
<a href="http://$getDomain/account/activation.php?code=$GCode" style="margin: auto;width: 50%;text-align: center;text-decoration: none;">点击激活</a>
|
||||
<br/>
|
||||
您的身份激活 <strong>$getExpTime</strong> 分钟内有效,此身份激活为 <strong>账户注册</strong> 使用。<br/>
|
||||
有效期至:$getEndTime
|
||||
<br/>
|
||||
<br/>
|
||||
若链接无法点击,可直接复制 ↓
|
||||
<br/>
|
||||
http://$getDomain/account/activation.php?code=$GCode
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
|
|
@ -14,11 +14,15 @@ class Normal
|
|||
* @param array|null $OtherArray 其他需要附带,不属于标准Json输出内容部分
|
||||
* @return void
|
||||
*/
|
||||
public static function Output(int $gType, array $OtherArray = null)
|
||||
public static function Output(int $gType, array $OtherArray = null, string $OtherOutput = null)
|
||||
{
|
||||
if (self::OutputMessage($gType, 1) != null) {
|
||||
if (!empty($OtherOutput))
|
||||
$OtherOutput = '__' . $OtherOutput;
|
||||
else
|
||||
$OtherOutput = null;
|
||||
$Json_Data = [
|
||||
'output' => self::OutputMessage($gType, 0),
|
||||
'output' => self::OutputMessage($gType, 0) . $OtherOutput,
|
||||
'code' => self::OutputMessage($gType, 1),
|
||||
'data' => [
|
||||
'statusCode' => $gType,
|
||||
|
@ -44,6 +48,39 @@ public static function Output(int $gType, array $OtherArray = null)
|
|||
echo json_encode($Json_Data, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义生成标标准接口输出 | 样式举例
|
||||
*
|
||||
* - Json
|
||||
* - output( **$Json_Output** )
|
||||
* - code( **$Json_Code** )
|
||||
* - data
|
||||
* - [data]statusCode: 999
|
||||
* - [data]message( **$Json_Message** )
|
||||
* - [data]data( **$Json_Other** )
|
||||
* @param string $Json_Output 输出代码
|
||||
* @param int $Json_Code
|
||||
* @param string $Json_Message
|
||||
* @param array $Json_Other
|
||||
* @return void
|
||||
*/
|
||||
public static function CustomOutput(string $Json_Output, int $Json_Code, string $Json_Message, array $Json_Other = null)
|
||||
{
|
||||
$Json_Data = [
|
||||
'output' => $Json_Output,
|
||||
'code' => $Json_Code,
|
||||
'data' => [
|
||||
'statusCode' => 999,
|
||||
'message' => $Json_Message,
|
||||
],
|
||||
];
|
||||
if (!empty($Json_Other)) {
|
||||
$Json_Data['data']['data'] = $Json_Other;
|
||||
}
|
||||
header(self::HttpStatusCode($Json_Code));
|
||||
echo json_encode($Json_Data, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 输出状态监控
|
||||
* @param int $gType
|
||||
|
@ -96,6 +133,30 @@ private static function OutputMessage(int $gType, int $bCode)
|
|||
if ($bCode == 0) return 'passwordIncorrect';
|
||||
else if ($bCode == 1) return 403;
|
||||
else return "密码不正确";
|
||||
else if ($gType == 404)
|
||||
if ($bCode == 0) return 'typeFormat';
|
||||
else if ($bCode == 1) return 403;
|
||||
else return "类型不正确";
|
||||
else if ($gType == 405)
|
||||
if ($bCode == 0) return 'blog_nameFormat';
|
||||
else if ($bCode == 1) return 403;
|
||||
else return "博客名字格式不符合";
|
||||
else if ($gType == 406)
|
||||
if ($bCode == 0) return 'blog_introduceFormat';
|
||||
else if ($bCode == 1) return 403;
|
||||
else return "博客描述格式不符合";
|
||||
else if ($gType == 407)
|
||||
if ($bCode == 0) return 'internetFormat';
|
||||
else if ($bCode == 1) return 403;
|
||||
else return "地址格式错误";
|
||||
else if ($gType == 408)
|
||||
if ($bCode == 0) return 'booleanFormat';
|
||||
else if ($bCode == 1) return 403;
|
||||
else return "布尔值格式错误";
|
||||
else if ($gType == 409)
|
||||
if ($bCode == 0) return 'blog_hostFormat';
|
||||
else if ($bCode == 1) return 403;
|
||||
else return "主机格式不符合";
|
||||
else if ($gType == 500)
|
||||
if ($bCode == 0) return 'CaptchaEffective';
|
||||
else if ($bCode == 1) return 200;
|
||||
|
|
|
@ -29,6 +29,11 @@ protected static function MySqlConn()
|
|||
/**
|
||||
* MySQL查找库 |
|
||||
* [Tips] 在PHP中,Mysql查询语句一次只允许查询一次数据,不可多个代码进行连续查询
|
||||
*
|
||||
* [output] 反馈
|
||||
* - [Success] 查询记录成功
|
||||
* - [EmptyResult] 没有对应记录
|
||||
* - [TypeError] 类型错误,出现这个多半是自己开发的问题
|
||||
* @param string $Mysql_Query 输入Mysql查询语句
|
||||
* @return string[] 查找到结果返回结果
|
||||
*/
|
||||
|
|
|
@ -1,19 +1,25 @@
|
|||
# OutputMessage 标准对照表
|
||||
|
||||
| 序号 | output内容 | HTTP状态码 | 中文解释 |
|
||||
|-----|-------------------|---------|------------------------------|
|
||||
| 100 | SessionError | 502 | 通讯密钥错误 |
|
||||
| 200 | Success | 200 | 操作成功 |
|
||||
| 201 | SuccessButEmail | 200 | 操作成功但邮件发送失败 |
|
||||
| 300 | SqlInsertFail | 400 | 数据表内容插入失败 |
|
||||
| 301 | SqlSelectFail | 400 | 数据表内容查询失败 |
|
||||
| 310 | TokenTooShort | 502 | Token长度过短 |
|
||||
| 311 | TokenTooLong | 502 | Token长度过长 |
|
||||
| 400 | usernameFormat | 405 | 用户名格式不符合 (格式允许0-9,A-Z,a-z及_) |
|
||||
| 401 | emailFormat | 405 | 邮箱格式不符合 |
|
||||
| 402 | userFormat | 405 | 用户格式不符合 |
|
||||
| 403 | passwordIncorrect | 403 | 密码不正确 |
|
||||
| 500 | CaptchaEffective | 200 | 激活码任然有效 |
|
||||
| 600 | AlReadyUser | 403 | 已经有这个用户 |
|
||||
| 601 | NoUser | 403 | 没有这个用户 |
|
||||
| | | | |
|
||||
| 序号 | output内容 | HTTP状态码 | 中文解释 |
|
||||
|-----|----------------------|---------|---------------------------------|
|
||||
| 100 | SessionError | 502 | 通讯密钥错误 |
|
||||
| 200 | Success | 200 | 操作成功 |
|
||||
| 201 | SuccessButEmail | 200 | 操作成功但邮件发送失败 |
|
||||
| 300 | SqlInsertFail | 400 | 数据表内容插入失败 |
|
||||
| 301 | SqlSelectFail | 400 | 数据表内容查询失败 |
|
||||
| 310 | TokenTooShort | 502 | Token长度过短 |
|
||||
| 311 | TokenTooLong | 502 | Token长度过长 |
|
||||
| 400 | usernameFormat | 405 | 用户名格式不符合 (格式允许0-9,A-Z,a-z及_) |
|
||||
| 401 | emailFormat | 405 | 邮箱格式不符合 |
|
||||
| 402 | userFormat | 405 | 用户格式不符合 |
|
||||
| 403 | passwordIncorrect | 403 | 密码不正确 |
|
||||
| 404 | typeFormat | 403 | 类型不正确 |
|
||||
| 405 | blog_nameFormat | 403 | 博客名字格式不符合(格式允许0-9,A-Z,a-z,_及中文) |
|
||||
| 406 | blog_introduceFormat | 403 | 博客描述格式不符合(格式允许0-9,A-Z,a-z,_及中文) |
|
||||
| 407 | internetFormat | 403 | 地址格式错误 |
|
||||
| 408 | booleanFormat | 403 | 布尔值格式错误 |
|
||||
| 409 | blog_hostFormat | 403 | 主机格式不符合(格式允许0-9,A-Z,a-z,_及中文) |
|
||||
| 500 | CaptchaEffective | 200 | 激活码任然有效 |
|
||||
| 600 | AlReadyUser | 403 | 已经有这个用户 |
|
||||
| 601 | NoUser | 403 | 没有这个用户 |
|
||||
| 999 | | | (自定义输出模块 CustomOutput模块) |
|
83
public/api/blog/friends_link/create/index.php
Normal file
83
public/api/blog/friends_link/create/index.php
Normal file
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
/*
|
||||
* Copyright © 2016 - 2023 筱锋xiao_lfeng. All Rights Reserved.
|
||||
* 开发开源遵循 MIT 许可,若需商用请联系开发者
|
||||
* https://www.x-lf.com/
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @var array $Json_Data 最终数据编译输出
|
||||
* @var array $Array_ConfigData 配置文件
|
||||
*/
|
||||
|
||||
// 引入配置
|
||||
include dirname(__FILE__, 6) . "/Modules/API/header.php";
|
||||
require dirname(__FILE__, 6) . "/class/Sql.php";
|
||||
require dirname(__FILE__, 6) . "/class/Normal.php";
|
||||
|
||||
// 数据获取类型
|
||||
$PostData = file_get_contents('php://input');
|
||||
$PostData = json_decode($PostData, true);
|
||||
|
||||
// 逻辑构建
|
||||
if ($Array_ConfigData['Session'] == $_SERVER['HTTP_SESSION']) {
|
||||
// 检查用户是否登录
|
||||
$Data_UserUID = null;
|
||||
if (!empty($_COOKIE['user'])) {
|
||||
$AResult_User = Sql::SELECT("SELECT * FROM `index`.xf_user WHERE `uid`={$_COOKIE['uid']}");
|
||||
if ($AResult_User['output'] == 'Success')
|
||||
$Data_UserUID = $AResult_User['data'][0]->uid;
|
||||
}
|
||||
// 检查数据是否合法
|
||||
if (!DataCheck()) {
|
||||
// 检查数据库内是否有数据
|
||||
$AResult_BlogLink = Sql::SELECT("SELECT * FROM `index`.xf_blog_link WHERE `name`='{$PostData['blog_name']}' OR `owner_email`='{$PostData['user_email']}' OR `url`='{$PostData['blog_url']}'");
|
||||
if ($AResult_BlogLink['output'] == 'EmptyResult') {
|
||||
// 没有数据执行插入
|
||||
if (Sql::INSERT("INSERT INTO `index`.xf_blog_link (`name`, `url`, `owner_email`, `introduce`, `icon`, `rss_judge`, `rss`, `serverhost`, `adv`, `blog_ssl`, `location`, `sel_color`, `deleted`) VALUES ('{$PostData['blog_name']}','{$PostData['blog_url']}','{$PostData['user_email']}','{$PostData['blog_introduce']}','{$PostData['blog_icon']}','{$PostData['blog_rss_judge']}','{$PostData['blog_rss']}','{$PostData['blog_host']}',{$PostData['blog_adv_judge']},{$PostData['blog_ssl_judge']},0,0,0)")) {
|
||||
// 插入成功返回结果
|
||||
Normal::Output(200);
|
||||
} else Normal::Output(300);
|
||||
} else {
|
||||
// 检查博客主要数据是否重复
|
||||
if ($AResult_BlogLink['data'][0]['owner_email'] == $PostData['user_email']) {
|
||||
Normal::CustomOutput('UserEmailDuplication', 403, '用户邮箱与数据库重复');
|
||||
} else if ($AResult_BlogLink['data'][0]['name'] == $PostData['blog_name']) {
|
||||
Normal::CustomOutput('BlogNameDuplication', 403, '博客名字与数据库重复');
|
||||
} else if ($AResult_BlogLink['data'][0]['url'] == $PostData['blog_url'])
|
||||
Normal::CustomOutput('BlogUrlDuplication', 403, '博客地址与数据库重复');// 数据库信息查询不正确
|
||||
}
|
||||
}
|
||||
} else Normal::Output(100); // SESSION是否合法
|
||||
|
||||
/**
|
||||
* @return false|void 返回结果为
|
||||
*/
|
||||
function DataCheck()
|
||||
{
|
||||
global $PostData;
|
||||
if (preg_match('/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/', $PostData['user_email'])) {
|
||||
if (preg_match('/^[一-龥0-9A-Za-z_\']+$/', $PostData['blog_name'])) {
|
||||
if (preg_match('/^[一-龥0-9A-Za-z_\']+$/', $PostData['blog_introduce'])) {
|
||||
if (preg_match('/^http://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?$/', $PostData['blog_url'])) {
|
||||
if (preg_match('/^http://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?$/', $PostData['blog_icon'])) {
|
||||
if ((string)$PostData['blog_ssl_judge'] == "true" || (string)$PostData['blog_ssl_judge'] == "false") {
|
||||
if ((string)$PostData['blog_adv_judge'] == "true" || (string)$PostData['blog_adv_judge'] == "false") {
|
||||
if ((string)$PostData['blog_rss_judge'] == "true" || (string)$PostData['blog_rss_judge'] == "false") {
|
||||
if (preg_match('/^http://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?$/', $PostData['blog_rss'])) {
|
||||
if (preg_match('/^[一-龥0-9A-Za-z_\']+$/', $PostData['blog_host'])) {
|
||||
if (preg_match('/^[0-9]+$/', $PostData['blog_color'])) {
|
||||
return false;
|
||||
} else Normal::Output(410);
|
||||
} else Normal::Output(409); // 地址格式错误(RSS地址)
|
||||
} else Normal::Output(407, null, 'blog_rss'); // 地址格式错误(RSS地址)
|
||||
} else Normal::Output(408, null, 'blog_rss_judge'); // 不符合布尔值参数
|
||||
} else Normal::Output(408, null, 'blog_adv_judge'); // 不符合布尔值参数
|
||||
} else Normal::Output(408, null, 'blog_ssl_judge'); // 不符合布尔值参数
|
||||
} else Normal::Output(407, null, 'blog_icon'); // 地址格式错误(图标地址)
|
||||
} else Normal::Output(407, null, 'blog_url'); // 地址格式错误
|
||||
} else Normal::Output(406); // 博客描述格式不符合
|
||||
} else Normal::Output(405); // 博客名字格式不符合
|
||||
} else Normal::Output(401); // 邮箱是否合法
|
||||
}
|
|
@ -1,10 +1,11 @@
|
|||
{
|
||||
"Session": "xiaolfengindex",
|
||||
"Web": {
|
||||
"Title": "筱锋xiao_lfeng",
|
||||
"Title": "筱锋个人主页",
|
||||
"subTitle": "不为如何,只为在茫茫人海中有自己的一片天空~",
|
||||
"Keyword": "",
|
||||
"Icon": "https://api.x-lf.cn/avatar/?uid=1"
|
||||
"Icon": "https://api.x-lf.cn/avatar/?uid=1",
|
||||
"Domain": "index.develop.x-lf.cn"
|
||||
},
|
||||
"Mysql": {
|
||||
"Host": "127.0.0.1",
|
||||
|
@ -13,10 +14,10 @@
|
|||
"Password": "qaq061823zcw"
|
||||
},
|
||||
"Smtp": {
|
||||
"Host": "smtp.x-lf.cn",
|
||||
"Host": "smtp.qiye.aliyun.com",
|
||||
"SmtpAuth": true,
|
||||
"Username": "",
|
||||
"Password": "",
|
||||
"Username": "noreplay@x-lf.cn",
|
||||
"Password": "X+7ily20040722",
|
||||
"Port": 25,
|
||||
"SecurePort": 465,
|
||||
"User": "noreplay@x-lf.cn",
|
||||
|
|
Loading…
Reference in New Issue
Block a user