mirror of
https://github.com/v2board/v2board.git
synced 2024-11-10 17:49:11 +08:00
update send email verify ttl 300 sec
This commit is contained in:
parent
01da63f82e
commit
13dbb143f8
@ -13,6 +13,7 @@ use App\Models\User;
|
|||||||
use App\Models\InviteCode;
|
use App\Models\InviteCode;
|
||||||
use App\Utils\Helper;
|
use App\Utils\Helper;
|
||||||
use App\Utils\Dict;
|
use App\Utils\Dict;
|
||||||
|
use App\Utils\CacheKey;
|
||||||
|
|
||||||
class AuthController extends Controller
|
class AuthController extends Controller
|
||||||
{
|
{
|
||||||
@ -35,11 +36,10 @@ class AuthController extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((int)config('v2board.email_verify', 0)) {
|
if ((int)config('v2board.email_verify', 0)) {
|
||||||
$redisKey = 'sendEmailVerify:' . $request->input('email');
|
|
||||||
if (empty($request->input('email_code'))) {
|
if (empty($request->input('email_code'))) {
|
||||||
abort(500, '邮箱验证码不能为空');
|
abort(500, '邮箱验证码不能为空');
|
||||||
}
|
}
|
||||||
if (Cache::get($redisKey) !== $request->input('email_code')) {
|
if (Cache::get(CacheKey::get('EMAIL_VERIFY_CODE', $request->input('email'))) !== $request->input('email_code')) {
|
||||||
abort(500, '邮箱验证码有误');
|
abort(500, '邮箱验证码有误');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -86,7 +86,7 @@ class AuthController extends Controller
|
|||||||
abort(500, '注册失败');
|
abort(500, '注册失败');
|
||||||
}
|
}
|
||||||
if ((int)config('v2board.email_verify', 0)) {
|
if ((int)config('v2board.email_verify', 0)) {
|
||||||
Cache::forget($redisKey);
|
Cache::forget(CacheKey::get('EMAIL_VERIFY_CODE', $request->input('email')));
|
||||||
}
|
}
|
||||||
$request->session()->put('email', $user->email);
|
$request->session()->put('email', $user->email);
|
||||||
$request->session()->put('id', $user->id);
|
$request->session()->put('id', $user->id);
|
||||||
@ -189,8 +189,7 @@ class AuthController extends Controller
|
|||||||
|
|
||||||
public function forget(AuthForget $request)
|
public function forget(AuthForget $request)
|
||||||
{
|
{
|
||||||
$redisKey = 'sendEmailVerify:' . $request->input('email');
|
if (Cache::get(CacheKey::get('EMAIL_VERIFY_CODE', $request->input('email'))) !== $request->input('email_code')) {
|
||||||
if (Cache::get($redisKey) !== $request->input('email_code')) {
|
|
||||||
abort(500, '邮箱验证码有误');
|
abort(500, '邮箱验证码有误');
|
||||||
}
|
}
|
||||||
$user = User::where('email', $request->input('email'))->first();
|
$user = User::where('email', $request->input('email'))->first();
|
||||||
@ -202,7 +201,7 @@ class AuthController extends Controller
|
|||||||
if (!$user->save()) {
|
if (!$user->save()) {
|
||||||
abort(500, '重置失败');
|
abort(500, '重置失败');
|
||||||
}
|
}
|
||||||
Cache::forget($redisKey);
|
Cache::forget(CacheKey::get('EMAIL_VERIFY_CODE', $request->input('email')));
|
||||||
return response([
|
return response([
|
||||||
'data' => true
|
'data' => true
|
||||||
]);
|
]);
|
||||||
|
@ -12,6 +12,7 @@ use Illuminate\Support\Facades\Cache;
|
|||||||
use App\Jobs\SendEmail;
|
use App\Jobs\SendEmail;
|
||||||
use App\Models\InviteCode;
|
use App\Models\InviteCode;
|
||||||
use App\Utils\Dict;
|
use App\Utils\Dict;
|
||||||
|
use App\Utils\CacheKey;
|
||||||
|
|
||||||
class CommController extends Controller
|
class CommController extends Controller
|
||||||
{
|
{
|
||||||
@ -38,11 +39,10 @@ class CommController extends Controller
|
|||||||
public function sendEmailVerify(CommSendEmailVerify $request)
|
public function sendEmailVerify(CommSendEmailVerify $request)
|
||||||
{
|
{
|
||||||
$email = $request->input('email');
|
$email = $request->input('email');
|
||||||
$cacheKey = 'sendEmailVerify:' . $email;
|
if (Cache::get(CacheKey::get('LAST_SEND_EMAIL_VERIFY_TIMESTAMP', $email))) {
|
||||||
if (Cache::get($cacheKey)) {
|
|
||||||
abort(500, '验证码已发送,请过一会再请求');
|
abort(500, '验证码已发送,请过一会再请求');
|
||||||
}
|
}
|
||||||
$code = Helper::randomChar(6);
|
$code = rand(100000, 999999);
|
||||||
$subject = config('v2board.app_name', 'V2Board') . '邮箱验证码';
|
$subject = config('v2board.app_name', 'V2Board') . '邮箱验证码';
|
||||||
|
|
||||||
SendEmail::dispatch([
|
SendEmail::dispatch([
|
||||||
@ -56,7 +56,8 @@ class CommController extends Controller
|
|||||||
]
|
]
|
||||||
])->onQueue('verify_mail');
|
])->onQueue('verify_mail');
|
||||||
|
|
||||||
Cache::put($cacheKey, $code, 60);
|
Cache::put(CacheKey::get('EMAIL_VERIFY_CODE', $email), $code, 300);
|
||||||
|
Cache::put(CacheKey::get('LAST_SEND_EMAIL_VERIFY_TIMESTAMP', $email), time(), 60);
|
||||||
return response([
|
return response([
|
||||||
'data' => true
|
'data' => true
|
||||||
]);
|
]);
|
||||||
|
@ -4,5 +4,16 @@ namespace App\Utils;
|
|||||||
|
|
||||||
class CacheKey
|
class CacheKey
|
||||||
{
|
{
|
||||||
|
CONST KEYS = [
|
||||||
|
'EMAIL_VERIFY_CODE' => '邮箱验证吗',
|
||||||
|
'LAST_SEND_EMAIL_VERIFY_TIMESTAMP' => '最后一次发送邮箱验证码时间'
|
||||||
|
];
|
||||||
|
|
||||||
|
public static function get(string $key, $uniqueValue)
|
||||||
|
{
|
||||||
|
if (!in_array($key, array_keys(self::KEYS))) {
|
||||||
|
abort(500, 'key is not in cache key list');
|
||||||
|
}
|
||||||
|
return $key . '_' . $uniqueValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user