正在显示
4 个修改的文件
包含
74 行增加
和
3 行删除
| @@ -16,6 +16,7 @@ abstract class Base { | @@ -16,6 +16,7 @@ abstract class Base { | ||
| 16 | 16 | ||
| 17 | 17 | ||
| 18 | /** | 18 | /** |
| 19 | + * 多个邮箱前端提交 | ||
| 19 | * @param string $filed | 20 | * @param string $filed |
| 20 | * @return mixed|null | 21 | * @return mixed|null |
| 21 | * @throws \Lib\Err | 22 | * @throws \Lib\Err |
| @@ -39,6 +40,29 @@ abstract class Base { | @@ -39,6 +40,29 @@ abstract class Base { | ||
| 39 | 40 | ||
| 40 | } | 41 | } |
| 41 | 42 | ||
| 43 | + /** | ||
| 44 | + * 一个邮箱前端提交 | ||
| 45 | + * @param string $filed | ||
| 46 | + * @return mixed|string|null | ||
| 47 | + * @throws \Lib\Err | ||
| 48 | + * @author:dc | ||
| 49 | + * @time 2023/3/10 16:07 | ||
| 50 | + */ | ||
| 51 | + protected final function getEmail($filed='*'){ | ||
| 52 | + static $data; | ||
| 53 | + if(empty($data)){ | ||
| 54 | + $data = db()->first(emailSql::first(web_request_email())); | ||
| 55 | + if(empty($data)){ | ||
| 56 | + app()->e('email_request_required'); | ||
| 57 | + } | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + if($filed == '*'){ | ||
| 61 | + return $data; | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + return $data[$filed]??''; | ||
| 65 | + } | ||
| 42 | 66 | ||
| 43 | 67 | ||
| 44 | } | 68 | } |
| @@ -26,8 +26,8 @@ class Folder extends Base { | @@ -26,8 +26,8 @@ class Folder extends Base { | ||
| 26 | // 查询 | 26 | // 查询 |
| 27 | $folders = db()->all( | 27 | $folders = db()->all( |
| 28 | \Model\folderSql::all( | 28 | \Model\folderSql::all( |
| 29 | - $this->login_email['id'], | ||
| 30 | - '`id`,`folder`,`pid`' | 29 | + $this->getEmail('id'), |
| 30 | + '`id`,`folder`,`pid`,`exsts`,`unseen`' | ||
| 31 | ) | 31 | ) |
| 32 | ); | 32 | ); |
| 33 | 33 |
| @@ -188,7 +188,7 @@ function web_request_emails():array { | @@ -188,7 +188,7 @@ function web_request_emails():array { | ||
| 188 | $emails = app()->request('emails'); | 188 | $emails = app()->request('emails'); |
| 189 | $emails = is_array($emails) ? $emails : [$emails]; | 189 | $emails = is_array($emails) ? $emails : [$emails]; |
| 190 | foreach ($emails as $k=>$email){ | 190 | foreach ($emails as $k=>$email){ |
| 191 | - if(!preg_match('/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/',$email)){ | 191 | + if(!\Lib\Verify::email($email)){ |
| 192 | unset($emails[$k]); | 192 | unset($emails[$k]); |
| 193 | } | 193 | } |
| 194 | } | 194 | } |
| @@ -200,6 +200,25 @@ function web_request_emails():array { | @@ -200,6 +200,25 @@ function web_request_emails():array { | ||
| 200 | return array_values($emails); | 200 | return array_values($emails); |
| 201 | } | 201 | } |
| 202 | 202 | ||
| 203 | +/** | ||
| 204 | + * 前端获取邮箱一个 | ||
| 205 | + * @return string | ||
| 206 | + * @throws \Lib\Err | ||
| 207 | + * @author:dc | ||
| 208 | + * @time 2023/3/10 16:05 | ||
| 209 | + */ | ||
| 210 | +function web_request_email():string { | ||
| 211 | + $email = app()->request('email'); | ||
| 212 | + | ||
| 213 | + if(!\Lib\Verify::email($email)){ | ||
| 214 | + app()->e('email_request_required'); | ||
| 215 | + } | ||
| 216 | + | ||
| 217 | + return $email; | ||
| 218 | +} | ||
| 219 | + | ||
| 220 | + | ||
| 221 | + | ||
| 203 | 222 | ||
| 204 | /** | 223 | /** |
| 205 | * 分页数据 | 224 | * 分页数据 |
lib/Verify.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace Lib; | ||
| 4 | + | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * 验证 | ||
| 8 | + * @author:dc | ||
| 9 | + * @time 2023/3/10 16:03 | ||
| 10 | + * Class Verify | ||
| 11 | + * @package Lib | ||
| 12 | + */ | ||
| 13 | +class Verify { | ||
| 14 | + | ||
| 15 | + /** | ||
| 16 | + * 验证邮箱 | ||
| 17 | + * @param $email | ||
| 18 | + * @return false|int | ||
| 19 | + * @author:dc | ||
| 20 | + * @time 2023/3/10 16:04 | ||
| 21 | + */ | ||
| 22 | + public static function email($email){ | ||
| 23 | + return preg_match('/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/',$email); | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + | ||
| 27 | + | ||
| 28 | +} |
-
请 注册 或 登录 后发表评论