2019-10-29 15:33:36 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Passport;
|
|
|
|
|
|
|
|
use App\Http\Requests\Passport\CommSendEmailVerify;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use Illuminate\Http\Exceptions\HttpResponseException;
|
|
|
|
use Illuminate\Support\Facades\Mail;
|
|
|
|
use Illuminate\Support\Facades\Redis;
|
|
|
|
|
|
|
|
class CommController extends Controller
|
|
|
|
{
|
2019-11-25 18:14:49 +08:00
|
|
|
public function config () {
|
|
|
|
return response([
|
|
|
|
'isEmailVerify' => (int)config('v2board.email_verify', 0) ? 1 : 0,
|
|
|
|
'isInviteForce' => (int)config('v2board.invite_force', 0) ? 1 : 0,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function isEmailVerify () {
|
2019-10-29 15:33:36 +08:00
|
|
|
return response([
|
2019-11-18 19:52:30 +08:00
|
|
|
'data' => (int)config('v2board.email_verify', 0) ? 1 : 0
|
2019-10-29 15:33:36 +08:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function sendEmailVerify (CommSendEmailVerify $request) {
|
|
|
|
$email = $request->input('email');
|
|
|
|
$redisKey = 'sendEmailVerify:' . $email;
|
|
|
|
if (Redis::get($redisKey)) {
|
|
|
|
abort(500, '验证码已发送,请过一会在请求');
|
|
|
|
}
|
|
|
|
$code = rand(100000, 999999);
|
2019-11-18 19:52:30 +08:00
|
|
|
$subject = config('v2board.app_name', 'V2Board') . '邮箱验证码';
|
2019-10-29 15:33:36 +08:00
|
|
|
Mail::send(
|
|
|
|
'mail.sendEmailVerify',
|
|
|
|
[
|
|
|
|
'code' => $code,
|
2019-11-18 19:52:30 +08:00
|
|
|
'name' => config('v2board.app_name', 'V2Board')
|
2019-10-29 15:33:36 +08:00
|
|
|
],
|
|
|
|
function ($message) use($email, $subject) {
|
|
|
|
$message->to($email)->subject($subject);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
if (count(Mail::failures()) >= 1) {
|
|
|
|
// 发送失败
|
|
|
|
abort(500, '发送失败');
|
|
|
|
}
|
|
|
|
|
|
|
|
Redis::set($redisKey, $code);
|
|
|
|
Redis::expire($redisKey, 600);
|
|
|
|
return response([
|
|
|
|
'data' => true
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|