diff --git a/app/Http/Controllers/Collaborators/Auth/EmailVerificationController.php b/app/Http/Controllers/Collaborators/Auth/EmailVerificationController.php index a2f7ee2..e50fb98 100644 --- a/app/Http/Controllers/Collaborators/Auth/EmailVerificationController.php +++ b/app/Http/Controllers/Collaborators/Auth/EmailVerificationController.php @@ -22,13 +22,13 @@ class EmailVerificationController extends Controller } if (Auth::user()->hasVerifiedEmail()) { - return redirect(route('home')); + return redirect(route('collaborators.dashboard')); } if (Auth::user()->markEmailAsVerified()) { event(new Verified(Auth::user())); } - return redirect(route('home')); + return redirect(route('collaborators.dashboard')); } } diff --git a/app/Http/Controllers/Collaborators/Auth/LogoutController.php b/app/Http/Controllers/Collaborators/Auth/LogoutController.php index 911b5df..9d5a44b 100644 --- a/app/Http/Controllers/Collaborators/Auth/LogoutController.php +++ b/app/Http/Controllers/Collaborators/Auth/LogoutController.php @@ -13,6 +13,6 @@ class LogoutController extends Controller { Auth::guard('collaborators')->logout(); - return redirect(route('collaborators.home')); + return redirect(route('collaborators.dashboard')); } } diff --git a/app/Http/Livewire/Collaborators/Auth/Login.php b/app/Http/Livewire/Collaborators/Auth/Login.php index 88fcf86..e11d470 100644 --- a/app/Http/Livewire/Collaborators/Auth/Login.php +++ b/app/Http/Livewire/Collaborators/Auth/Login.php @@ -30,7 +30,7 @@ class Login extends Component return; } - redirect(route('collaborators.home')); + redirect(route('collaborators.dashboard')); } public function render() diff --git a/app/Http/Livewire/Collaborators/Auth/Passwords/Reset.php b/app/Http/Livewire/Collaborators/Auth/Passwords/Reset.php index 17d44ca..96568b5 100644 --- a/app/Http/Livewire/Collaborators/Auth/Passwords/Reset.php +++ b/app/Http/Livewire/Collaborators/Auth/Passwords/Reset.php @@ -59,7 +59,7 @@ class Reset extends Component if ($response == Password::PASSWORD_RESET) { session()->flash(trans($response)); - return redirect(route('collaborators.home')); + return redirect(route('collaborators.dashboard')); } $this->addError('email', trans($response)); diff --git a/app/Http/Livewire/Collaborators/Auth/Register/Individual.php b/app/Http/Livewire/Collaborators/Auth/Register/Individual.php deleted file mode 100644 index 6e5a60e..0000000 --- a/app/Http/Livewire/Collaborators/Auth/Register/Individual.php +++ /dev/null @@ -1,181 +0,0 @@ - 'cpf', - 'number' => '', - ]; - - /** @var array */ - public $address = [ - 'city' => '', - 'complement' => '', - 'country' => 'BR', - 'neighbourhood' => '', - 'number' => '', - 'postcode' => '', - 'state' => '', - 'street' => '', - ]; - - /** @var array */ - public $profile = [ - 'gender' => '', - 'occupation' => '', - 'scholarity' => '', - 'phone' => '', - 'secondary_emails' => '', - 'website' => '', - 'social' => '', - 'expectation' => '', - 'bike_use' => '', - 'org_participation' => '', - 'bike_activities' => '', - 'comments' => '', - 'ucb_comments' => '', - ]; - - /** @var string */ - public $email = ''; - - /** @var string */ - public $discussion = ''; - - /** @var int */ - public $contribution = null; - - public function updated($field) - { - $this->validateOnly($field, [ - 'address.city' => ['string'], - 'address.complement' => ['string'], - 'address.country' => ['string'], - 'address.neighbourhood' => ['string'], - 'address.number' => ['string'], - 'address.postcode' => ['string'], - 'address.state' => ['string'], - 'address.street' => ['string'], - 'birthday' => ['date_format:d/m/Y'], - 'contribution' => ['numeric'], - 'discussion' => ['string', 'in:all,daily,occasional'], - 'document.number' => ['string'], - 'document.type' => ['string', 'in:cpf,identity,passport'], - 'email' => ['email', 'unique:associates'], - 'profile.bike_activities' => ['string'], - 'profile.bike_use' => ['string'], - 'profile.comments' => ['string'], - 'profile.expectation' => ['string'], - 'profile.gender' => ['string', 'in:male,female,other'], - 'profile.occupation' => ['string'], - 'profile.org_participation' => ['string'], - 'profile.phone' => ['string'], - 'profile.scholarity' => ['string', 'in:primary-school,high-school,bachelor,master,phd'], - 'profile.secondary_emails' => ['string'], - 'profile.social' => ['string'], - 'profile.ucb_comments' => ['string'], - 'profile.website' => ['string'], - ]); - - if ($this->address['country'] === 'BR' && $field === 'address.postcode') { - $postcode = Str::slug($this->address['postcode'], ''); - - try { - $response = Http::timeout(5)->get("https://viacep.com.br/ws/$postcode/json"); - - if ($response->ok()) { - $address = $response->json(); - - $this->address['city'] = $response['localidade']; - $this->address['neighbourhood'] = $response['bairro']; - $this->address['state'] = $response['uf']; - $this->address['street'] = $response['logradouro']; - - $this->dispatchBrowserEvent('address-autofilled'); - } - } catch (\Illuminate\Http\Client\ConnectionException $exception) { - // TODO: show error to associate - } - } - } - - public function register() - { - $this->validate([ - 'address.city' => ['required', 'string'], - 'address.complement' => ['nullable', 'string'], - 'address.country' => ['required', 'string'], - 'address.neighbourhood' => ['required', 'string'], - 'address.number' => ['required', 'string'], - 'address.postcode' => ['required', 'string'], - 'address.state' => ['required', 'string'], - 'address.street' => ['required', 'string'], - 'birthday' => ['required', 'date_format:d/m/Y'], - 'contribution' => ['required', 'numeric'], - 'discussion' => ['required', 'string', 'in:all,daily,occasional'], - 'document.number' => ['required', 'string'], - 'document.type' => ['required', 'string', 'in:cpf,identity,passport'], - 'email' => ['required', 'email', 'unique:associates'], - 'name' => ['required'], - 'profile.bike_activities' => ['nullable', 'string'], - 'profile.bike_use' => ['nullable', 'string'], - 'profile.comments' => ['nullable', 'string'], - 'profile.expectation' => ['nullable', 'string'], - 'profile.gender' => ['required', 'string', 'in:male,female,other'], - 'profile.occupation' => ['required', 'string'], - 'profile.org_participation' => ['nullable', 'string'], - 'profile.phone' => ['required', 'string'], - 'profile.scholarity' => ['required', 'string', 'in:primary-school,high-school,bachelor,master,phd'], - 'profile.secondary_emails' => ['nullable', 'string'], - 'profile.social' => ['nullable', 'string'], - 'profile.ucb_comments' => ['nullable', 'string'], - 'profile.website' => ['nullable', 'string'], - ]); - - $associate = new Associate([ - 'address' => $this->address, - 'birthday' => Carbon::createFromFormat('d/m/Y', $this->birthday), - 'contribution' => $this->contribution, - 'discussion' => $this->discussion, - 'document' => $this->document, - 'email' => $this->email, - 'name' => $this->name, - 'profile' => $this->profile, - ]); - - $associate->associate_category_id = AssociateCategory::where('key', 'individual')->first()->id; - $associate->associate_nature_id = AssociateNature::where('key', 'individual')->first()->id; - $associate->associate_type_id = AssociateType::where('key', 'individual')->first()->id; - - $associate->save(); - - Auth::login($associate, true); - - redirect(route('home')); - } - - public function render() - { - return view('livewire.collaborators.auth.register.individual'); - } -} diff --git a/app/Http/Middleware/Authenticate.php b/app/Http/Middleware/Authenticate.php index 46fcfee..14b6cbd 100644 --- a/app/Http/Middleware/Authenticate.php +++ b/app/Http/Middleware/Authenticate.php @@ -15,7 +15,7 @@ class Authenticate extends Middleware protected function redirectTo($request) { if (! $request->expectsJson()) { - if ($request->is('admin/*')) { + if ($request->is('admin*')) { return route('collaborators.login'); } else { return route('login'); diff --git a/app/Http/Middleware/RedirectIfAuthenticated.php b/app/Http/Middleware/RedirectIfAuthenticated.php index 638f3ae..4ca9851 100644 --- a/app/Http/Middleware/RedirectIfAuthenticated.php +++ b/app/Http/Middleware/RedirectIfAuthenticated.php @@ -20,7 +20,7 @@ class RedirectIfAuthenticated { if (Auth::guard($guard)->check()) { if ($guard === 'collaborators') { - return redirect(route('collaborators.home')); + return redirect(route('collaborators.dashboard')); } else { return redirect(route('home')); } diff --git a/resources/views/collaborators/auth/register/individual.blade.php b/resources/views/collaborators/auth/register/individual.blade.php deleted file mode 100644 index bbda5be..0000000 --- a/resources/views/collaborators/auth/register/individual.blade.php +++ /dev/null @@ -1,8 +0,0 @@ -@extends('layouts.auth') -@section('title', __('user_categories.individual')) - -@section('content') -
- @livewire('collaborators.auth.register.individual') -
-@endsection diff --git a/resources/views/collaborators/dashboard.blade.php b/resources/views/collaborators/dashboard.blade.php new file mode 100644 index 0000000..045cc23 --- /dev/null +++ b/resources/views/collaborators/dashboard.blade.php @@ -0,0 +1,52 @@ +@extends('layouts.app') + +@section('content') +
+
+ @if (Route::has('login')) +
+ + Log out + + + +
+ @endif +
+ +
+
+
+ + + + +

+ {{ config('app.name') }} +

+ + +
+
+
+
+@endsection diff --git a/routes/web.php b/routes/web.php index 5010608..19ece9c 100644 --- a/routes/web.php +++ b/routes/web.php @@ -37,7 +37,7 @@ Route::prefix('admin')->name('collaborators.')->group(function () { Route::get('password/reset/{token}', 'Collaborators\Auth\PasswordResetController')->name('password.reset'); Route::middleware('auth:collaborators')->group(function () { - Route::view('/', 'welcome')->name('home'); + Route::view('/', 'collaborators.dashboard')->name('dashboard'); Route::post('logout', 'Collaborators\Auth\LogoutController')->name('logout'); }); }); diff --git a/tests/Feature/Collaborators/Auth/LoginTest.php b/tests/Feature/Collaborators/Auth/LoginTest.php index d708e05..ec45b82 100644 --- a/tests/Feature/Collaborators/Auth/LoginTest.php +++ b/tests/Feature/Collaborators/Auth/LoginTest.php @@ -29,7 +29,7 @@ class LoginTest extends TestCase $this->be($collaborator, 'collaborators'); $this->get(route('collaborators.login')) - ->assertRedirect(route('collaborators.home')); + ->assertRedirect(route('collaborators.dashboard')); } /** @test */ @@ -46,7 +46,7 @@ class LoginTest extends TestCase } /** @test */ - public function is_redirected_to_the_home_page_after_login() + public function is_redirected_to_the_dashboard_after_login() { $collaborator = $this->factoryWithoutObservers(Collaborator::class)->create(['password' => Hash::make('password')]); @@ -54,7 +54,7 @@ class LoginTest extends TestCase ->set('email', $collaborator->email) ->set('password', 'password') ->call('authenticate') - ->assertRedirect(route('collaborators.home')); + ->assertRedirect(route('collaborators.dashboard')); } /** @test */ diff --git a/tests/Feature/Collaborators/Auth/LogoutTest.php b/tests/Feature/Collaborators/Auth/LogoutTest.php index 271cdcc..afd3d07 100644 --- a/tests/Feature/Collaborators/Auth/LogoutTest.php +++ b/tests/Feature/Collaborators/Auth/LogoutTest.php @@ -18,7 +18,7 @@ class LogoutTest extends TestCase $this->be($collaborator, 'collaborators'); $this->post(route('collaborators.logout')) - ->assertRedirect(route('collaborators.home')); + ->assertRedirect(route('collaborators.dashboard')); $this->assertFalse(Auth::check('collaborators')); }