Created
June 7, 2017 13:18
-
-
Save mostafa6765/ad6f74633fd3adb1250c74ca7c0a8dbc to your computer and use it in GitHub Desktop.
recaptcha laravel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers\Auth; | |
use Illuminate\Http\Request; | |
use App\Http\Controllers\Controller; | |
use Auth; | |
class AdminLoginController extends Controller | |
{ | |
public function __construct() | |
{ | |
$this->middleware('guest:admin', ['except' => ['logout']]); | |
} | |
public function showLoginForm() | |
{ | |
return view('auth.admin-login'); | |
} | |
public function login(Request $request) | |
{ | |
// Validate the form data | |
$this->validate($request, [ | |
'email' => 'required|email', | |
'password' => 'required|min:6', | |
'g-recaptcha-response' => 'required|recaptcha' | |
]); | |
// Attempt to log the user in | |
if (Auth::guard('admin')->attempt(['email' => $request->email, 'password' => $request->password], $request->remember)) { | |
// if successful, then redirect to their intended location | |
return redirect()->intended(route('admin.dashboard')); | |
} | |
// if unsuccessful, then redirect back to the login with the form data | |
return redirect()->back()->withInput($request->only('email', 'remember')); | |
} | |
public function logout() | |
{ | |
Auth::guard('admin')->logout(); | |
return redirect('/admin'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment