-
-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactoring authentication, rules in MoonShineUserResource, admin use…
…r avatar in header, minor fixes
- Loading branch information
Showing
9 changed files
with
129 additions
and
27 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
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,40 @@ | ||
<?php | ||
|
||
namespace Leeto\MoonShine\Http\Requests; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
class LoginFormRequest extends FormRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
* | ||
* @return bool | ||
*/ | ||
public function authorize(): bool | ||
{ | ||
return auth(config('moonshine.auth.guard'))->guest(); | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
public function rules(): array | ||
{ | ||
return [ | ||
'email' => ['required', 'email'], | ||
'password' => ['required'], | ||
]; | ||
} | ||
|
||
protected function prepareForValidation() | ||
{ | ||
$this->merge([ | ||
'email' => (string)str(request('email')) | ||
->lower() | ||
->trim(), | ||
]); | ||
} | ||
} |
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,56 @@ | ||
<?php | ||
|
||
namespace Leeto\MoonShine\Tests\Controllers; | ||
|
||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Leeto\MoonShine\Models\MoonshineUser; | ||
use Leeto\MoonShine\Models\MoonshineUserRole; | ||
use Leeto\MoonShine\Resources\MoonShineUserResource; | ||
use Leeto\MoonShine\Tests\TestCase; | ||
|
||
class MoonShineAuthControllerTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
|
||
public function test_login_page() | ||
{ | ||
$response = $this->get(route(config('moonshine.route.prefix') . '.login')); | ||
|
||
$response->assertOk(); | ||
$response->assertViewIs('moonshine::auth.login'); | ||
} | ||
|
||
public function test_login_redirect_to_dashboard() | ||
{ | ||
$response = $this->actingAs($this->user, config('moonshine.auth.guard')) | ||
->get(route(config('moonshine.route.prefix') . '.login')); | ||
|
||
$response->assertRedirect(route(config('moonshine.route.prefix') . '.index')); | ||
} | ||
|
||
public function test_authenticate() | ||
{ | ||
$response = $this->post( | ||
route(config('moonshine.route.prefix') . '.authenticate'), | ||
['email' => $this->user->email, 'password' => 'invalid'] | ||
); | ||
|
||
$response->assertInvalid(['login']); | ||
|
||
$response = $this->post( | ||
route(config('moonshine.route.prefix') . '.authenticate'), | ||
['email' => $this->user->email, 'password' => 'test'] | ||
); | ||
|
||
$response->assertValid(); | ||
} | ||
|
||
public function test_logout() | ||
{ | ||
$response = $this->actingAs($this->user, config('moonshine.auth.guard')) | ||
->get(route(config('moonshine.route.prefix') . '.logout')); | ||
|
||
$response->assertRedirect(route(config('moonshine.route.prefix') . '.login')); | ||
} | ||
|
||
} |