Files
animexe/app/Http/Controllers/Frontend/PasswordResetController.php
2026-07-14 00:01:48 +03:00

79 lines
2.6 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Http\Controllers\Frontend;
use App\Http\Controllers\Controller;
use App\Mail\ResetPasswordMail;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Password;
use Illuminate\Validation\Rules\Password as PasswordRule;
class PasswordResetController extends Controller
{
public function showForgot()
{
return view('frontend.auth.forgot-password');
}
public function sendResetLink(Request $request)
{
$request->validate(['email' => 'required|email'], [
'email.required' => 'E-posta zorunludur.',
'email.email' => 'Geçerli bir e-posta girin.',
]);
$user = User::where('email', $request->email)->first();
// Kullanıcı bulunamasa bile aynı mesajı göster (güvenlik)
if ($user) {
$status = Password::sendResetLink(
$request->only('email'),
function (User $user, string $token) {
$url = url(route('password.reset', ['token' => $token, 'email' => $user->email], false));
Mail::to($user->email)->send(new ResetPasswordMail($url, $user->name));
}
);
}
return back()->with('status', 'Eğer bu e-posta adresine kayıtlı bir hesap varsa şifre sıfırlama bağlantısı gönderildi.');
}
public function showReset(Request $request, string $token)
{
return view('frontend.auth.reset-password', [
'token' => $token,
'email' => $request->query('email', ''),
]);
}
public function reset(Request $request)
{
$request->validate([
'token' => 'required',
'email' => 'required|email',
'password' => ['required', 'confirmed', PasswordRule::min(6)],
], [
'password.required' => 'Şifre zorunludur.',
'password.confirmed' => 'Şifreler eşleşmiyor.',
'password.min' => 'Şifre en az 6 karakter olmalıdır.',
]);
$status = Password::reset(
$request->only('email', 'password', 'password_confirmation', 'token'),
function (User $user, string $password) {
$user->forceFill(['password' => Hash::make($password)])->save();
}
);
if ($status === Password::PASSWORD_RESET) {
return redirect()->route('frontend.login')
->with('status', 'Şifreniz başarıyla sıfırlandı. Giriş yapabilirsiniz.');
}
return back()->withErrors(['email' => __($status)]);
}
}