Browse Source

Separa página inicial dos colaboradores

master
Guilherme Capanema 6 years ago
parent
commit
a7abee1167
12 changed files with 64 additions and 201 deletions
  1. +2
    -2
      app/Http/Controllers/Collaborators/Auth/EmailVerificationController.php
  2. +1
    -1
      app/Http/Controllers/Collaborators/Auth/LogoutController.php
  3. +1
    -1
      app/Http/Livewire/Collaborators/Auth/Login.php
  4. +1
    -1
      app/Http/Livewire/Collaborators/Auth/Passwords/Reset.php
  5. +0
    -181
      app/Http/Livewire/Collaborators/Auth/Register/Individual.php
  6. +1
    -1
      app/Http/Middleware/Authenticate.php
  7. +1
    -1
      app/Http/Middleware/RedirectIfAuthenticated.php
  8. +0
    -8
      resources/views/collaborators/auth/register/individual.blade.php
  9. +52
    -0
      resources/views/collaborators/dashboard.blade.php
  10. +1
    -1
      routes/web.php
  11. +3
    -3
      tests/Feature/Collaborators/Auth/LoginTest.php
  12. +1
    -1
      tests/Feature/Collaborators/Auth/LogoutTest.php

+ 2
- 2
app/Http/Controllers/Collaborators/Auth/EmailVerificationController.php View File

@ -22,13 +22,13 @@ class EmailVerificationController extends Controller
} }
if (Auth::user()->hasVerifiedEmail()) { if (Auth::user()->hasVerifiedEmail()) {
return redirect(route('home'));
return redirect(route('collaborators.dashboard'));
} }
if (Auth::user()->markEmailAsVerified()) { if (Auth::user()->markEmailAsVerified()) {
event(new Verified(Auth::user())); event(new Verified(Auth::user()));
} }
return redirect(route('home'));
return redirect(route('collaborators.dashboard'));
} }
} }

+ 1
- 1
app/Http/Controllers/Collaborators/Auth/LogoutController.php View File

@ -13,6 +13,6 @@ class LogoutController extends Controller
{ {
Auth::guard('collaborators')->logout(); Auth::guard('collaborators')->logout();
return redirect(route('collaborators.home'));
return redirect(route('collaborators.dashboard'));
} }
} }

+ 1
- 1
app/Http/Livewire/Collaborators/Auth/Login.php View File

@ -30,7 +30,7 @@ class Login extends Component
return; return;
} }
redirect(route('collaborators.home'));
redirect(route('collaborators.dashboard'));
} }
public function render() public function render()


+ 1
- 1
app/Http/Livewire/Collaborators/Auth/Passwords/Reset.php View File

@ -59,7 +59,7 @@ class Reset extends Component
if ($response == Password::PASSWORD_RESET) { if ($response == Password::PASSWORD_RESET) {
session()->flash(trans($response)); session()->flash(trans($response));
return redirect(route('collaborators.home'));
return redirect(route('collaborators.dashboard'));
} }
$this->addError('email', trans($response)); $this->addError('email', trans($response));


+ 0
- 181
app/Http/Livewire/Collaborators/Auth/Register/Individual.php View File

@ -1,181 +0,0 @@
<?php
namespace App\Http\Livewire\Collaborators\Auth\Register;
use App\Providers\RouteServiceProvider;
use App\Associate;
use App\AssociateCategory;
use App\AssociateNature;
use App\AssociateType;
use Carbon\Carbon;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Str;
use Livewire\Component;
class Individual extends Component
{
/** @var string */
public $name = '';
/** @var string */
public $birthday = '';
/** @var array */
public $document = [
'type' => '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');
}
}

+ 1
- 1
app/Http/Middleware/Authenticate.php View File

@ -15,7 +15,7 @@ class Authenticate extends Middleware
protected function redirectTo($request) protected function redirectTo($request)
{ {
if (! $request->expectsJson()) { if (! $request->expectsJson()) {
if ($request->is('admin/*')) {
if ($request->is('admin*')) {
return route('collaborators.login'); return route('collaborators.login');
} else { } else {
return route('login'); return route('login');


+ 1
- 1
app/Http/Middleware/RedirectIfAuthenticated.php View File

@ -20,7 +20,7 @@ class RedirectIfAuthenticated
{ {
if (Auth::guard($guard)->check()) { if (Auth::guard($guard)->check()) {
if ($guard === 'collaborators') { if ($guard === 'collaborators') {
return redirect(route('collaborators.home'));
return redirect(route('collaborators.dashboard'));
} else { } else {
return redirect(route('home')); return redirect(route('home'));
} }


+ 0
- 8
resources/views/collaborators/auth/register/individual.blade.php View File

@ -1,8 +0,0 @@
@extends('layouts.auth')
@section('title', __('user_categories.individual'))
@section('content')
<div>
@livewire('collaborators.auth.register.individual')
</div>
@endsection

+ 52
- 0
resources/views/collaborators/dashboard.blade.php View File

@ -0,0 +1,52 @@
@extends('layouts.app')
@section('content')
<div class="flex flex-col justify-center min-h-screen py-12 bg-gray-50 sm:px-6 lg:px-8">
<div class="absolute top-0 right-0 mt-4 mr-4">
@if (Route::has('login'))
<div class="space-x-4">
<a
href="{{ route('collaborators.logout') }}"
onclick="event.preventDefault(); document.getElementById('logout-form').submit();"
class="font-medium text-green-600 hover:text-green-500 focus:outline-none focus:underline transition ease-in-out duration-150"
>
Log out
</a>
<form id="logout-form" action="{{ route('collaborators.logout') }}" method="POST" style="display: none;">
@csrf
</form>
</div>
@endif
</div>
<div class="flex items-center justify-center">
<div class="flex flex-col justify-around">
<div class="space-y-6">
<a href="{{ route('home') }}">
<x-logo class="w-auto h-16 mx-auto text-green-600" />
</a>
<h1 class="text-5xl font-extrabold tracking-wider text-center text-gray-600">
{{ config('app.name') }}
</h1>
<ul class="list-reset">
<li class="inline px-4">
<a href="https://tailwindcss.com" class="font-medium text-green-600 hover:text-green-500 focus:outline-none focus:underline transition ease-in-out duration-150">Tailwind CSS</a>
</li>
<li class="inline px-4">
<a href="https://github.com/alpinejs/alpine" class="font-medium text-green-600 hover:text-green-500 focus:outline-none focus:underline transition ease-in-out duration-150">Alpine.js</a>
</li>
<li class="inline px-4">
<a href="https://laravel.com" class="font-medium text-green-600 hover:text-green-500 focus:outline-none focus:underline transition ease-in-out duration-150">Laravel</a>
</li>
<li class="inline px-4">
<a href="https://laravel-livewire.com" class="font-medium text-green-600 hover:text-green-500 focus:outline-none focus:underline transition ease-in-out duration-150">Livewire</a>
</li>
</ul>
</div>
</div>
</div>
</div>
@endsection

+ 1
- 1
routes/web.php View File

@ -37,7 +37,7 @@ Route::prefix('admin')->name('collaborators.')->group(function () {
Route::get('password/reset/{token}', 'Collaborators\Auth\PasswordResetController')->name('password.reset'); Route::get('password/reset/{token}', 'Collaborators\Auth\PasswordResetController')->name('password.reset');
Route::middleware('auth:collaborators')->group(function () { 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'); Route::post('logout', 'Collaborators\Auth\LogoutController')->name('logout');
}); });
}); });

+ 3
- 3
tests/Feature/Collaborators/Auth/LoginTest.php View File

@ -29,7 +29,7 @@ class LoginTest extends TestCase
$this->be($collaborator, 'collaborators'); $this->be($collaborator, 'collaborators');
$this->get(route('collaborators.login')) $this->get(route('collaborators.login'))
->assertRedirect(route('collaborators.home'));
->assertRedirect(route('collaborators.dashboard'));
} }
/** @test */ /** @test */
@ -46,7 +46,7 @@ class LoginTest extends TestCase
} }
/** @test */ /** @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')]); $collaborator = $this->factoryWithoutObservers(Collaborator::class)->create(['password' => Hash::make('password')]);
@ -54,7 +54,7 @@ class LoginTest extends TestCase
->set('email', $collaborator->email) ->set('email', $collaborator->email)
->set('password', 'password') ->set('password', 'password')
->call('authenticate') ->call('authenticate')
->assertRedirect(route('collaborators.home'));
->assertRedirect(route('collaborators.dashboard'));
} }
/** @test */ /** @test */


+ 1
- 1
tests/Feature/Collaborators/Auth/LogoutTest.php View File

@ -18,7 +18,7 @@ class LogoutTest extends TestCase
$this->be($collaborator, 'collaborators'); $this->be($collaborator, 'collaborators');
$this->post(route('collaborators.logout')) $this->post(route('collaborators.logout'))
->assertRedirect(route('collaborators.home'));
->assertRedirect(route('collaborators.dashboard'));
$this->assertFalse(Auth::check('collaborators')); $this->assertFalse(Auth::check('collaborators'));
} }