Home.php
1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
namespace Controller;
/**
* @author:dc
* @time 2023/2/13 11:28
* Class Home
* @package Controller
*/
class Home {
/**
* 登录操作
* @return int[]
* @author:dc
* @time 2023/2/13 11:50
*/
public function login(){
// $mail,$password,$imap,$smtp
$formData = app()->request(['email','password','imap','smtp']);
if(empty($formData['email']) || !preg_match("//",$formData['email'])){
app()->e('email_verify_error');
}
if(empty($formData['password'])){
app()->e('password_verify_error');
}
if(empty($formData['imap'])){
app()->e('imap_verify_error');
}
if(empty($formData['smtp'])){
app()->e('smtp_verify_error');
}
// 查询数据
$model = db()->first(\Model\email::first($formData['email']));
if(!$model){
$model = new Email();
$model->email = $formData['email'];
}
$model->imap = $formData['imap'];
$model->smtp = $formData['smtp'];
$model->status = Email::STATUS_ACTIVE;
$model->password = @base64_encode($formData['password']);
try {
Mail::login($model->email,$model->password,$model->imap);
}catch (\Throwable $e){
return res()
->message($e->getMessage())
->status(400)
->toJson();
}
// 登录成功了,密码验证字段通过
$model->pwd_error = 0;
// 保存好邮箱
$model->save();
// 设置上id,方便后面使用
Mail::$client[$model->email]->setId($model->id);
// 开始同步文件夹
// $folder = Mail::syncFolder($model->email);
return res()
->data([
'token' => token_en($model->id.','.$model->email.','.time())
])
->toJson();
}
}