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;
|
2020-01-12 01:27:36 +08:00
|
|
|
use Illuminate\Support\Facades\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');
|
2020-01-08 01:34:48 +08:00
|
|
|
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, '重置失败');
|
|
|
|
}
|
2020-01-08 01:34:48 +08:00
|
|
|
Cache::forget($redisKey);
|
2019-10-29 15:33:36 +08:00
|
|
|
return response([
|
|
|
|
'data' => true
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|