-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from BRACKETS-by-TRIAD/laravel-7
Laravel 7
- Loading branch information
Showing
15 changed files
with
692 additions
and
11 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
return [ | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Reset Passwords Lines | ||
|-------------------------------------------------------------------------- | ||
| | ||
*/ | ||
|
||
'email' => [ | ||
'line' => 'You are receiving this email because we received a password reset request for your account.', | ||
'action' => 'Reset Password', | ||
'notRequested' => 'If you did not request a password reset, no further action is required.', | ||
], | ||
]; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
return [ | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Reset Passwords Lines | ||
|-------------------------------------------------------------------------- | ||
| | ||
*/ | ||
|
||
'email' => [ | ||
'line' => 'Tento email ste dostali pretože sme zaznamenali požiadavku o resetovanie hesla vašeho účtu.', | ||
'action' => 'Resetovať heslo', | ||
'notRequested' => 'Ak ste nepožiadali o resetovanie hesla môžete túto správu ignorovať.', | ||
], | ||
|
||
]; |
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
<?php | ||
|
||
namespace Brackets\AdminAuth\Traits; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Http\Response; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\Validation\ValidationException; | ||
|
||
trait AuthenticatesUsers | ||
{ | ||
use RedirectsUsers, ThrottlesLogins; | ||
|
||
/** | ||
* Show the application's login form. | ||
* | ||
* @return \Illuminate\View\View | ||
*/ | ||
public function showLoginForm() | ||
{ | ||
return view('auth.login'); | ||
} | ||
|
||
/** | ||
* Handle a login request to the application. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response|\Illuminate\Http\JsonResponse | ||
* | ||
* @throws \Illuminate\Validation\ValidationException | ||
*/ | ||
public function login(Request $request) | ||
{ | ||
$this->validateLogin($request); | ||
|
||
// If the class is using the ThrottlesLogins trait, we can automatically throttle | ||
// the login attempts for this application. We'll key this by the username and | ||
// the IP address of the client making these requests into this application. | ||
if (method_exists($this, 'hasTooManyLoginAttempts') && | ||
$this->hasTooManyLoginAttempts($request)) { | ||
$this->fireLockoutEvent($request); | ||
|
||
return $this->sendLockoutResponse($request); | ||
} | ||
|
||
if ($this->attemptLogin($request)) { | ||
return $this->sendLoginResponse($request); | ||
} | ||
|
||
// If the login attempt was unsuccessful we will increment the number of attempts | ||
// to login and redirect the user back to the login form. Of course, when this | ||
// user surpasses their maximum number of attempts they will get locked out. | ||
$this->incrementLoginAttempts($request); | ||
|
||
return $this->sendFailedLoginResponse($request); | ||
} | ||
|
||
/** | ||
* Validate the user login request. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return void | ||
* | ||
* @throws \Illuminate\Validation\ValidationException | ||
*/ | ||
protected function validateLogin(Request $request) | ||
{ | ||
$request->validate([ | ||
$this->username() => 'required|string', | ||
'password' => 'required|string', | ||
]); | ||
} | ||
|
||
/** | ||
* Attempt to log the user into the application. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return bool | ||
*/ | ||
protected function attemptLogin(Request $request) | ||
{ | ||
return $this->guard()->attempt( | ||
$this->credentials($request), $request->filled('remember') | ||
); | ||
} | ||
|
||
/** | ||
* Get the needed authorization credentials from the request. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return array | ||
*/ | ||
protected function credentials(Request $request) | ||
{ | ||
return $request->only($this->username(), 'password'); | ||
} | ||
|
||
/** | ||
* Send the response after the user was authenticated. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
protected function sendLoginResponse(Request $request) | ||
{ | ||
$request->session()->regenerate(); | ||
|
||
$this->clearLoginAttempts($request); | ||
|
||
if ($response = $this->authenticated($request, $this->guard()->user())) { | ||
return $response; | ||
} | ||
|
||
return $request->wantsJson() | ||
? new Response('', 204) | ||
: redirect()->intended($this->redirectPath()); | ||
} | ||
|
||
/** | ||
* The user has been authenticated. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param mixed $user | ||
* @return mixed | ||
*/ | ||
protected function authenticated(Request $request, $user) | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Get the failed login response instance. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return \Symfony\Component\HttpFoundation\Response | ||
* | ||
* @throws \Illuminate\Validation\ValidationException | ||
*/ | ||
protected function sendFailedLoginResponse(Request $request) | ||
{ | ||
throw ValidationException::withMessages([ | ||
$this->username() => [trans('auth.failed')], | ||
]); | ||
} | ||
|
||
/** | ||
* Get the login username to be used by the controller. | ||
* | ||
* @return string | ||
*/ | ||
public function username() | ||
{ | ||
return 'email'; | ||
} | ||
|
||
/** | ||
* Log the user out of the application. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function logout(Request $request) | ||
{ | ||
$this->guard()->logout(); | ||
|
||
$request->session()->invalidate(); | ||
|
||
$request->session()->regenerateToken(); | ||
|
||
if ($response = $this->loggedOut($request)) { | ||
return $response; | ||
} | ||
|
||
return $request->wantsJson() | ||
? new Response('', 204) | ||
: redirect('/'); | ||
} | ||
|
||
/** | ||
* The user has logged out of the application. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return mixed | ||
*/ | ||
protected function loggedOut(Request $request) | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Get the guard to be used during authentication. | ||
* | ||
* @return \Illuminate\Contracts\Auth\StatefulGuard | ||
*/ | ||
protected function guard() | ||
{ | ||
return Auth::guard(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Brackets\AdminAuth\Traits; | ||
|
||
trait RedirectsUsers | ||
{ | ||
/** | ||
* Get the post register / login redirect path. | ||
* | ||
* @return string | ||
*/ | ||
public function redirectPath() | ||
{ | ||
if (method_exists($this, 'redirectTo')) { | ||
return $this->redirectTo(); | ||
} | ||
|
||
return property_exists($this, 'redirectTo') ? $this->redirectTo : '/home'; | ||
} | ||
} |
Oops, something went wrong.