diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index 34eb97ff1..840eb6c73 100755 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -10,7 +10,6 @@ use Captcha; use Carbon\Carbon; use Request; -use Validator; /** * @apiDefine users @@ -92,7 +91,7 @@ public function login() Cache::forget("code::" . $email); if ($isRegVerify && $user->email_verity === 0) { UserEmailVerification::userEmailSend($user); - return $retError('您还没有验证邮箱,请先登录邮箱通过验证邮件验证邮箱'); + return Base::retError('您还没有验证邮箱,请先登录邮箱通过验证邮件验证邮箱', ['code' => 'email']); } } // diff --git a/app/Models/User.php b/app/Models/User.php index d17c6f188..750aa481e 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -191,7 +191,7 @@ public static function reg($email, $password, $other = []) $user = self::whereUserid(User::email2userid($email))->first(); if ($isRegVerify && $user->email_verity === 0) { UserEmailVerification::userEmailSend($user); - throw new ApiException('您的账号已注册过,请验证邮箱'); + throw new ApiException('您的账号已注册过,请验证邮箱', ['code' => 'email']); } throw new ApiException('邮箱地址已存在'); } diff --git a/app/Models/UserEmailVerification.php b/app/Models/UserEmailVerification.php index ab91e16e7..570d03a6d 100644 --- a/app/Models/UserEmailVerification.php +++ b/app/Models/UserEmailVerification.php @@ -5,9 +5,8 @@ use App\Exceptions\ApiException; use App\Module\Base; use Carbon\Carbon; -use Config; -use Exception; -use Mail; +use Guanguans\Notify\Factory; +use Guanguans\Notify\Messages\EmailMessage; /** * App\Models\UserEmailVerification @@ -40,49 +39,42 @@ class UserEmailVerification extends AbstractModel */ public static function userEmailSend(User $user) { - $res = self::where('userid', $user->userid)->where('created_at', '>', Carbon::now()->subMinutes(1440))->first(); + $res = self::whereUserid($user->userid)->where('created_at', '>', Carbon::now()->subMinutes(1440))->first(); if ($res) return; //删除 - self::where('userid', $user->userid)->delete(); - $info['created_at'] = date("Y-m-d H:i:s"); - $info['userid'] = $user->userid; - $info['email'] = $user->email; - $info['code'] = md5(uniqid(md5(microtime(true)), true)) . md5($user->userid . md5('lddsgagsgkdiid' . microtime(true))); - $info['status'] = 0; - $userEmailVerification = self::createInstance($info); + self::whereUserid($user->userid)->delete(); + $userEmailVerification = self::createInstance([ + 'userid' => $user->userid, + 'email' => $user->email, + 'code' => Base::generatePassword(64), + 'status' => 0, + ]); $userEmailVerification->save(); - $url = Base::fillUrl('single/valid/email') . '?code=' . $info['code']; + + $setting = Base::setting('emailSetting'); + $url = Base::fillUrl('single/valid/email') . '?code=' . $userEmailVerification->code; + $subject = "绑定邮箱验证"; + $content = "您好,您正在绑定 " . env('APP_NAME') . " 的邮箱,请于24小时之内点击该链接完成验证 :
{$url}
"; try { - // 15秒后超时 - self::initMailConfig(); - Mail::send('email', ['url' => $url], function ($m) use ($user) { - $m->from(Config::get("mail.mailers.smtp.username"), env('APP_NAME')); - $m->to($user->email); - $m->subject("绑定邮箱验证"); - }); - } catch (Exception $exception) { - // 一般是请求超时 - if (str_contains($exception->getMessage(), "Timed Out")) { + if (!Base::isEmail($user->email)) { + throw new \Exception("User email '{$user->email}' address error"); + } + Factory::mailer() + ->setDsn("smtp://{$setting['account']}:{$setting['password']}@{$setting['smtp_server']}:{$setting['port']}?verify_peer=0") + ->setMessage(EmailMessage::create() + ->from(env('APP_NAME', 'Task') . " <{$setting['account']}>") + ->to($user->email) + ->subject($subject) + ->html($content)) + ->send(); + } catch (\Exception $e) { + if (str_contains($e->getMessage(), "Timed Out")) { throw new ApiException("language.TimedOut"); - } elseif ($exception->getCode() == 550) { + } elseif ($e->getCode() === 550) { throw new ApiException('邮件内容被拒绝,请检查邮箱是否开启接收功能'); } else { - throw new ApiException($exception->getMessage()); + throw new ApiException($e->getMessage()); } } } - - /** - * 初始化邮箱配置 - * @return void - */ - public static function initMailConfig() - { - $config = Base::setting('emailSetting'); - Config::set("mail.mailers.smtp.host", $config['smtp_server'] ?: Config::get("mail.mailers.smtp.host")); - Config::set("mail.mailers.smtp.port", $config['port'] ?: Config::get("mail.mailers.smtp.port")); - Config::set("mail.mailers.smtp.username", $config['account'] ?: Config::get("mail.mailers.smtp.username")); - Config::set("mail.mailers.smtp.password", $config['password'] ?: Config::get("mail.mailers.smtp.password")); - Config::set("mail.mailers.smtp.encryption", 'ssl'); - } } diff --git a/app/Tasks/OverdueRemindEmailTask.php b/app/Tasks/OverdueRemindEmailTask.php index 3363cfe4a..130fee9c5 100644 --- a/app/Tasks/OverdueRemindEmailTask.php +++ b/app/Tasks/OverdueRemindEmailTask.php @@ -76,10 +76,10 @@ private function overdueBeforeAfterEmail(ProjectTask $task, $isBefore) $hours2 = floatval($setting['task_remind_hours2']); if ($isBefore) { $subject = "任务提醒"; - $content = "

用户您好, " . env('APP_NAME') . " 任务到期提醒。

您有一个任务【{{$task->name}}】还有{{$hours}}小时即将超时,请及时处理

"; + $content = "

用户您好, " . env('APP_NAME') . " 任务到期提醒。

您有一个任务【{$task->name}】还有{$hours}小时即将超时,请及时处理

"; } else { $subject = "任务过期提醒"; - $content = "

用户您好, " . env('APP_NAME') . " 任务到期提醒。

您的任务【{{$task->name}}】已经超时{{$hours2}}小时,请及时处理

"; + $content = "

用户您好, " . env('APP_NAME') . " 任务到期提醒。

您的任务【{$task->name}】已经超时{$hours2}小时,请及时处理

"; } /** @var User $user */ diff --git a/resources/assets/js/pages/login.vue b/resources/assets/js/pages/login.vue index a0cf5e241..06b31e66b 100644 --- a/resources/assets/js/pages/login.vue +++ b/resources/assets/js/pages/login.vue @@ -85,7 +85,7 @@ export default { loadIng: 0, codeNeed: false, - codeUrl: $A.apiUrl('users/login/codeimg'), + codeUrl: $A.apiUrl('users/login/codeimg?_=' + Math.random()), loginType: 'login', loginJump: false, diff --git a/resources/views/email.blade.php b/resources/views/email.blade.php deleted file mode 100644 index 39c8d886b..000000000 --- a/resources/views/email.blade.php +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - -您好,您正在绑定 {{env('APP_NAME') }} 的邮箱,请于24小时之内点击该链接完成验证 : -
- {{$url}} -
- - -