46 lines
1.2 KiB
PHP
46 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Auth;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Auth\LoginPostRequest;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class LoginController extends Controller
|
|
{
|
|
|
|
public function index()
|
|
{
|
|
return view('auth.login');
|
|
}
|
|
|
|
|
|
public function post(LoginPostRequest $request)
|
|
{
|
|
$login = $request->validated();
|
|
|
|
$field = filter_var($login['username'], FILTER_VALIDATE_EMAIL) ? 'email' : 'username';
|
|
|
|
$credentials = [
|
|
$field => $login['username'],
|
|
'password' => $login['password'],
|
|
];
|
|
|
|
$remember = $request->boolean('remember');
|
|
|
|
if (Auth::attempt($credentials, $remember)) {
|
|
$request->session()->regenerate();
|
|
|
|
return redirect()
|
|
->intended(route('account.index'))
|
|
->with('success', 'با موفقیت وارد حساب کاربری شدید.');
|
|
}
|
|
|
|
return back()
|
|
->withInput($request->only('username'))
|
|
->withErrors([
|
|
'username' => 'نام کاربری، ایمیل یا رمز عبور اشتباه است.',
|
|
]);
|
|
}
|
|
}
|