正在显示
10 个修改的文件
包含
201 行增加
和
74 行删除
@@ -21,64 +21,63 @@ class Home { | @@ -21,64 +21,63 @@ class Home { | ||
21 | // $mail,$password,$imap,$smtp | 21 | // $mail,$password,$imap,$smtp |
22 | $formData = app()->request(['email','password','imap','smtp']); | 22 | $formData = app()->request(['email','password','imap','smtp']); |
23 | 23 | ||
24 | - if(empty($formData['email']) || !preg_match("",$formData['email'])){ | 24 | + if(empty($formData['email']) || !preg_match("//",$formData['email'])){ |
25 | app()->e('email_verify_error'); | 25 | app()->e('email_verify_error'); |
26 | } | 26 | } |
27 | 27 | ||
28 | - | ||
29 | - $validator = validator($formData,[ | ||
30 | - 'email' => ['required','email'], | ||
31 | - 'password' => ['required','min:8','max:32'], | ||
32 | - 'imap' => ['required'], | ||
33 | - 'smtp' => ['required'], | ||
34 | - ],[ | ||
35 | - | ||
36 | - ]); | ||
37 | - | ||
38 | - if($validator->fails()){ | ||
39 | - return res() | ||
40 | - ->message($validator->errors()->first()) | ||
41 | - ->status(400) | ||
42 | - ->toJson(); | 28 | + if(empty($formData['password'])){ |
29 | + app()->e('password_verify_error'); | ||
43 | } | 30 | } |
44 | 31 | ||
45 | - // host | ||
46 | - $model = Email::_first($formData['email']); | ||
47 | - if(!$model){ | ||
48 | - $model = new Email(); | ||
49 | - $model->email = $formData['email']; | 32 | + if(empty($formData['imap'])){ |
33 | + app()->e('imap_verify_error'); | ||
50 | } | 34 | } |
51 | 35 | ||
52 | - $model->imap = $formData['imap']; | ||
53 | - $model->smtp = $formData['smtp']; | ||
54 | - $model->status = Email::STATUS_ACTIVE; | ||
55 | - $model->password = @base64_encode($formData['password']); | ||
56 | - | ||
57 | - try { | ||
58 | - Mail::login($model->email,$model->password,$model->imap); | ||
59 | - }catch (\Throwable $e){ | ||
60 | - return res() | ||
61 | - ->message($e->getMessage()) | ||
62 | - ->status(400) | ||
63 | - ->toJson(); | 36 | + if(empty($formData['smtp'])){ |
37 | + app()->e('smtp_verify_error'); | ||
64 | } | 38 | } |
65 | 39 | ||
66 | - // 登录成功了,密码验证字段通过 | ||
67 | - $model->pwd_error = 0; | ||
68 | - // 保存好邮箱 | ||
69 | - $model->save(); | ||
70 | - | ||
71 | - // 设置上id,方便后面使用 | ||
72 | - Mail::$client[$model->email]->setId($model->id); | ||
73 | - | ||
74 | - // 开始同步文件夹 | ||
75 | -// $folder = Mail::syncFolder($model->email); | ||
76 | - | ||
77 | - return res() | ||
78 | - ->data([ | ||
79 | - 'token' => token_en($model->id.','.$model->email.','.time()) | ||
80 | - ]) | ||
81 | - ->toJson(); | 40 | + $data = db()->first(\Model\email::first($formData['email'])); |
41 | + | ||
42 | + app()->_json($data); | ||
43 | + | ||
44 | +// // host | ||
45 | +// $model = Email::_first($formData['email']); | ||
46 | +// if(!$model){ | ||
47 | +// $model = new Email(); | ||
48 | +// $model->email = $formData['email']; | ||
49 | +// } | ||
50 | +// | ||
51 | +// $model->imap = $formData['imap']; | ||
52 | +// $model->smtp = $formData['smtp']; | ||
53 | +// $model->status = Email::STATUS_ACTIVE; | ||
54 | +// $model->password = @base64_encode($formData['password']); | ||
55 | +// | ||
56 | +// try { | ||
57 | +// Mail::login($model->email,$model->password,$model->imap); | ||
58 | +// }catch (\Throwable $e){ | ||
59 | +// return res() | ||
60 | +// ->message($e->getMessage()) | ||
61 | +// ->status(400) | ||
62 | +// ->toJson(); | ||
63 | +// } | ||
64 | +// | ||
65 | +// // 登录成功了,密码验证字段通过 | ||
66 | +// $model->pwd_error = 0; | ||
67 | +// // 保存好邮箱 | ||
68 | +// $model->save(); | ||
69 | +// | ||
70 | +// // 设置上id,方便后面使用 | ||
71 | +// Mail::$client[$model->email]->setId($model->id); | ||
72 | +// | ||
73 | +// // 开始同步文件夹 | ||
74 | +//// $folder = Mail::syncFolder($model->email); | ||
75 | +// | ||
76 | +// return res() | ||
77 | +// ->data([ | ||
78 | +// 'token' => token_en($model->id.','.$model->email.','.time()) | ||
79 | +// ]) | ||
80 | +// ->toJson(); | ||
82 | 81 | ||
83 | } | 82 | } |
84 | 83 |
@@ -3,31 +3,29 @@ | @@ -3,31 +3,29 @@ | ||
3 | 3 | ||
4 | /** | 4 | /** |
5 | * redis 驱动 | 5 | * redis 驱动 |
6 | - * @return RedisPool | 6 | + * @return \Lib\RedisPool |
7 | * @author:dc | 7 | * @author:dc |
8 | * @time 2023/2/13 9:44 | 8 | * @time 2023/2/13 9:44 |
9 | */ | 9 | */ |
10 | -function redis():\RedisPool { | 10 | +function redis():\Lib\RedisPool { |
11 | 11 | ||
12 | - return \RedisPool::instance(co::getCid()); | 12 | + return \Lib\RedisPool::instance(co::getCid()); |
13 | 13 | ||
14 | } | 14 | } |
15 | 15 | ||
16 | 16 | ||
17 | /** | 17 | /** |
18 | * 操作db | 18 | * 操作db |
19 | - * @return DbPool | 19 | + * @return \Lib\DbPool |
20 | * @author:dc | 20 | * @author:dc |
21 | - * @time 2023/2/13 9:43 | 21 | + * @time 2023/2/13 14:15 |
22 | */ | 22 | */ |
23 | -function db():DbPool{ | 23 | +function db():\Lib\DbPool{ |
24 | 24 | ||
25 | - return DbPool::instance(co::getCid()); | 25 | + return \Lib\DbPool::instance(co::getCid()); |
26 | } | 26 | } |
27 | 27 | ||
28 | -function model($model){ | ||
29 | 28 | ||
30 | -} | ||
31 | 29 | ||
32 | 30 | ||
33 | 31 | ||
@@ -40,7 +38,7 @@ function model($model){ | @@ -40,7 +38,7 @@ function model($model){ | ||
40 | function logs($message,$filename=null){ | 38 | function logs($message,$filename=null){ |
41 | @file_put_contents( | 39 | @file_put_contents( |
42 | $filename ? $filename : LOG_PATH.'/error.log', | 40 | $filename ? $filename : LOG_PATH.'/error.log', |
43 | - print_r($message,true), | 41 | + print_r($message,true).PHP_EOL, |
44 | FILE_APPEND | 42 | FILE_APPEND |
45 | ); | 43 | ); |
46 | } | 44 | } |
@@ -9,4 +9,9 @@ return [ | @@ -9,4 +9,9 @@ return [ | ||
9 | 'route_not_found' => '页面不存在', | 9 | 'route_not_found' => '页面不存在', |
10 | 10 | ||
11 | 'email_verify_error' => '邮箱验证失败', | 11 | 'email_verify_error' => '邮箱验证失败', |
12 | + 'password_verify_error' => '密码必须', | ||
13 | + 'imap_verify_error' => 'imap服务器地址错误', | ||
14 | + 'smtp_verify_error' => 'smtp服务器地址错误', | ||
15 | + | ||
16 | + 'server_error' => '服务器异常', | ||
12 | ]; | 17 | ]; |
@@ -2,6 +2,12 @@ | @@ -2,6 +2,12 @@ | ||
2 | 2 | ||
3 | namespace Lib; | 3 | namespace Lib; |
4 | 4 | ||
5 | +/** | ||
6 | + * @author:dc | ||
7 | + * @time 2023/2/13 15:07 | ||
8 | + * Class App | ||
9 | + * @package Lib | ||
10 | + */ | ||
5 | class App { | 11 | class App { |
6 | 12 | ||
7 | /** | 13 | /** |
@@ -32,6 +38,13 @@ class App { | @@ -32,6 +38,13 @@ class App { | ||
32 | */ | 38 | */ |
33 | private array $request = []; | 39 | private array $request = []; |
34 | 40 | ||
41 | + | ||
42 | + /** | ||
43 | + * TODO:: 如果debug打开,错误时会返回错误消息到前端 | ||
44 | + * @var bool | ||
45 | + */ | ||
46 | + public bool $debug = true; | ||
47 | + | ||
35 | /** | 48 | /** |
36 | * 输出到前端的数据 | 49 | * 输出到前端的数据 |
37 | * @var array | 50 | * @var array |
@@ -101,10 +114,17 @@ class App { | @@ -101,10 +114,17 @@ class App { | ||
101 | // 记录日志 | 114 | // 记录日志 |
102 | $filename = LOG_PATH.'/'.$app->nowDate().'.log'; | 115 | $filename = LOG_PATH.'/'.$app->nowDate().'.log'; |
103 | logs( | 116 | logs( |
104 | - $exception->getMessage().PHP_EOL.$exception->getTraceAsString(), | 117 | + $app->nowDateTime().' '.$exception->getMessage().PHP_EOL.$exception->getTraceAsString(), |
105 | $filename | 118 | $filename |
106 | ); | 119 | ); |
120 | + | ||
121 | + // 非 Err 错误类型 | ||
122 | + $app->data = [ | ||
123 | + 'message' => $app->debug ? $exception->getMessage().PHP_EOL.$exception->getTraceAsString() : __('server_error'), | ||
124 | + 'status' => $exception->getCode() ? $exception->getCode() : 500, | ||
125 | + ]; | ||
107 | } | 126 | } |
127 | + | ||
108 | } | 128 | } |
109 | 129 | ||
110 | } | 130 | } |
@@ -124,13 +144,17 @@ class App { | @@ -124,13 +144,17 @@ class App { | ||
124 | if (is_string($name)){ | 144 | if (is_string($name)){ |
125 | return $this->request[$name]??$default; | 145 | return $this->request[$name]??$default; |
126 | } | 146 | } |
127 | - $data = []; | ||
128 | - foreach ($this->request as $key=>$value){ | ||
129 | - if(in_array($key,$name)){ | ||
130 | - $data[$key] = $value; | 147 | + |
148 | + if(is_array($name)){ | ||
149 | + $data = []; | ||
150 | + foreach ($this->request as $key=>$value){ | ||
151 | + if(in_array($key,$name)){ | ||
152 | + $data[$key] = $value; | ||
153 | + } | ||
131 | } | 154 | } |
155 | + return $data; | ||
132 | } | 156 | } |
133 | - return $data; | 157 | + return null; |
134 | } | 158 | } |
135 | 159 | ||
136 | 160 |
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | +namespace Lib; | ||
4 | + | ||
5 | +/** | ||
6 | + * db 池 | ||
7 | + * @author:dc | ||
8 | + * @time 2023/2/13 15:03 | ||
9 | + * Class DbPool | ||
10 | + * @package Lib | ||
11 | + */ | ||
3 | class DbPool { | 12 | class DbPool { |
4 | 13 | ||
5 | /** | 14 | /** |
6 | - * @var DbPool[] | 15 | + * @var \Lib\DbPool[] |
7 | */ | 16 | */ |
8 | static $instance = []; | 17 | static $instance = []; |
9 | 18 | ||
@@ -22,6 +31,18 @@ class DbPool { | @@ -22,6 +31,18 @@ class DbPool { | ||
22 | return $this->client; | 31 | return $this->client; |
23 | } | 32 | } |
24 | 33 | ||
34 | + /** | ||
35 | + * 表 | ||
36 | + * @var string | ||
37 | + */ | ||
38 | + private string $table; | ||
39 | + | ||
40 | + /** | ||
41 | + * 查询条件 | ||
42 | + * @var string|array | ||
43 | + */ | ||
44 | + private string | array $where; | ||
45 | + | ||
25 | 46 | ||
26 | public function __construct() | 47 | public function __construct() |
27 | { | 48 | { |
@@ -33,7 +54,7 @@ class DbPool { | @@ -33,7 +54,7 @@ class DbPool { | ||
33 | [ | 54 | [ |
34 | \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC, | 55 | \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC, |
35 | \PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8mb4'", | 56 | \PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8mb4'", |
36 | - PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, | 57 | + \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, |
37 | ] | 58 | ] |
38 | ); | 59 | ); |
39 | }catch (\PDOException $e){ | 60 | }catch (\PDOException $e){ |
@@ -43,17 +64,64 @@ class DbPool { | @@ -43,17 +64,64 @@ class DbPool { | ||
43 | } | 64 | } |
44 | 65 | ||
45 | 66 | ||
46 | - public function query($sql){ | 67 | + /** |
68 | + * 表 | ||
69 | + * @param $table | ||
70 | + * @return $this | ||
71 | + * @author:dc | ||
72 | + * @time 2023/2/13 14:36 | ||
73 | + */ | ||
74 | + public function table($table){ | ||
75 | + $this->table = $table; | ||
76 | + return $this; | ||
77 | + } | ||
47 | 78 | ||
79 | + /** | ||
80 | + * 条件 | ||
81 | + * @param string|array $where | ||
82 | + * @return $this | ||
83 | + * @author:dc | ||
84 | + * @time 2023/2/13 14:38 | ||
85 | + */ | ||
86 | + public function where(string|array $where){ | ||
87 | + $this->where = $where; | ||
88 | + return $this; | ||
48 | } | 89 | } |
49 | 90 | ||
91 | + | ||
92 | + /** | ||
93 | + * @param $sql | ||
94 | + * @param null $params | ||
95 | + * @return false|\PDOStatement | ||
96 | + * @author:dc | ||
97 | + * @time 2023/2/13 14:41 | ||
98 | + */ | ||
99 | + private function query($sql,$params=null){ | ||
100 | + | ||
101 | + } | ||
102 | + | ||
103 | + | ||
50 | public function get($sql){ | 104 | public function get($sql){ |
51 | 105 | ||
52 | } | 106 | } |
53 | 107 | ||
54 | 108 | ||
55 | - public function first($sql){ | 109 | + /** |
110 | + * 查询一条数据 | ||
111 | + * @param string|array $sql | ||
112 | + * @return mixed|null | ||
113 | + * @author:dc | ||
114 | + * @time 2023/2/13 14:54 | ||
115 | + */ | ||
116 | + public function first(string|array $sql){ | ||
117 | + | ||
118 | + $query = $this->client->prepare(is_array($sql) ? $sql[0] : $sql); | ||
119 | + | ||
120 | + if($query->execute(is_array($sql) ? $sql[1] : null)){ | ||
121 | + return $query->fetch(); | ||
122 | + } | ||
56 | 123 | ||
124 | + return null; | ||
57 | } | 125 | } |
58 | 126 | ||
59 | 127 | ||
@@ -68,9 +136,9 @@ class DbPool { | @@ -68,9 +136,9 @@ class DbPool { | ||
68 | * @author:dc | 136 | * @author:dc |
69 | * @time 2023/2/13 9:39 | 137 | * @time 2023/2/13 9:39 |
70 | */ | 138 | */ |
71 | - public static function instance($cid){ | 139 | + public static function instance($cid=0){ |
72 | if(empty(static::$instance[$cid])){ | 140 | if(empty(static::$instance[$cid])){ |
73 | - static::$instance[$cid] = new \RedisPool(); | 141 | + static::$instance[$cid] = new DbPool(); |
74 | } | 142 | } |
75 | return static::$instance[$cid]; | 143 | return static::$instance[$cid]; |
76 | } | 144 | } |
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | +namespace Lib; | ||
4 | + | ||
3 | /** | 5 | /** |
4 | * redis 链接池 | 6 | * redis 链接池 |
5 | * @author:dc | 7 | * @author:dc |
@@ -9,7 +11,7 @@ | @@ -9,7 +11,7 @@ | ||
9 | class RedisPool { | 11 | class RedisPool { |
10 | 12 | ||
11 | /** | 13 | /** |
12 | - * @var RedisPool[] | 14 | + * @var \Lib\RedisPool[] |
13 | */ | 15 | */ |
14 | static $instance = []; | 16 | static $instance = []; |
15 | 17 | ||
@@ -168,13 +170,13 @@ class RedisPool { | @@ -168,13 +170,13 @@ class RedisPool { | ||
168 | 170 | ||
169 | /** | 171 | /** |
170 | * @param $cid | 172 | * @param $cid |
171 | - * @return RedisPool | 173 | + * @return \Lib\RedisPool |
172 | * @author:dc | 174 | * @author:dc |
173 | * @time 2023/2/13 9:38 | 175 | * @time 2023/2/13 9:38 |
174 | */ | 176 | */ |
175 | public static function instance($cid){ | 177 | public static function instance($cid){ |
176 | if(empty(static::$instance[$cid])){ | 178 | if(empty(static::$instance[$cid])){ |
177 | - static::$instance[$cid] = new \RedisPool(); | 179 | + static::$instance[$cid] = new \Lib\RedisPool(); |
178 | } | 180 | } |
179 | return static::$instance[$cid]; | 181 | return static::$instance[$cid]; |
180 | } | 182 | } |
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | +namespace Model; | ||
4 | + | ||
5 | +/** | ||
6 | + * @author:dc | ||
7 | + * @time 2023/2/13 14:11 | ||
8 | + * Class email | ||
9 | + */ | ||
3 | class email { | 10 | class email { |
4 | 11 | ||
12 | + | ||
13 | + /** | ||
14 | + * 通过email查询 | ||
15 | + * @param $email | ||
16 | + * @return array | ||
17 | + * @author:dc | ||
18 | + * @time 2023/2/13 14:50 | ||
19 | + */ | ||
20 | + public static function first($email){ | ||
21 | + return [ | ||
22 | + "select * from `emails` where `email` = ? limit 1", | ||
23 | + [ | ||
24 | |||
25 | + ] | ||
26 | + ]; | ||
27 | + } | ||
28 | + | ||
29 | + | ||
5 | } | 30 | } |
-
请 注册 或 登录 后发表评论