v2board/app/Http/Controllers/Passport/ForgetController.php

31 lines
872 B
PHP
Raw Normal View History

2019-10-29 15:33:36 +08:00
<?php
namespace App\Http\Controllers\Passport;
use App\Http\Requests\Passport\ForgetIndex;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\Support\Facades\Mail;
use Cache;
2019-10-29 15:33:36 +08:00
class ForgetController extends Controller
{
2020-01-11 13:36:52 +08:00
public function index(ForgetIndex $request)
{
2019-10-29 15:33:36 +08:00
$redisKey = 'sendEmailVerify:' . $request->input('email');
if (Cache::get($redisKey) !== $request->input('email_code')) {
2019-10-29 15:33:36 +08:00
abort(500, '邮箱验证码有误');
}
$user = User::where('email', $request->input('email'))->first();
$user->password = password_hash($request->input('password'), PASSWORD_DEFAULT);
if (!$user->save()) {
abort(500, '重置失败');
}
Cache::forget($redisKey);
2019-10-29 15:33:36 +08:00
return response([
'data' => true
]);
}
}