...
|
...
|
@@ -21,64 +21,63 @@ class Home { |
|
|
// $mail,$password,$imap,$smtp
|
|
|
$formData = app()->request(['email','password','imap','smtp']);
|
|
|
|
|
|
if(empty($formData['email']) || !preg_match("",$formData['email'])){
|
|
|
if(empty($formData['email']) || !preg_match("//",$formData['email'])){
|
|
|
app()->e('email_verify_error');
|
|
|
}
|
|
|
|
|
|
|
|
|
$validator = validator($formData,[
|
|
|
'email' => ['required','email'],
|
|
|
'password' => ['required','min:8','max:32'],
|
|
|
'imap' => ['required'],
|
|
|
'smtp' => ['required'],
|
|
|
],[
|
|
|
|
|
|
]);
|
|
|
|
|
|
if($validator->fails()){
|
|
|
return res()
|
|
|
->message($validator->errors()->first())
|
|
|
->status(400)
|
|
|
->toJson();
|
|
|
if(empty($formData['password'])){
|
|
|
app()->e('password_verify_error');
|
|
|
}
|
|
|
|
|
|
// host
|
|
|
$model = Email::_first($formData['email']);
|
|
|
if(!$model){
|
|
|
$model = new Email();
|
|
|
$model->email = $formData['email'];
|
|
|
if(empty($formData['imap'])){
|
|
|
app()->e('imap_verify_error');
|
|
|
}
|
|
|
|
|
|
$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();
|
|
|
if(empty($formData['smtp'])){
|
|
|
app()->e('smtp_verify_error');
|
|
|
}
|
|
|
|
|
|
// 登录成功了,密码验证字段通过
|
|
|
$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();
|
|
|
$data = db()->first(\Model\email::first($formData['email']));
|
|
|
|
|
|
app()->_json($data);
|
|
|
|
|
|
// // host
|
|
|
// $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();
|
|
|
|
|
|
}
|
|
|
|
...
|
...
|
|