Browse Source

Implementa base do cadastro de associados

usuarios_separados
Guilherme Capanema 6 years ago
parent
commit
bdc08e8c19
22 changed files with 339 additions and 104 deletions
  1. +29
    -0
      app/Events/UserCreating.php
  2. +5
    -14
      app/Http/Livewire/Auth/Register/Individual.php
  3. +37
    -0
      app/Listeners/SendUserPasswordEmail.php
  4. +50
    -0
      app/Mail/UserPassword.php
  5. +6
    -1
      app/Providers/EventServiceProvider.php
  6. +35
    -1
      app/User.php
  7. +30
    -0
      app/UserCategory.php
  8. +1
    -0
      composer.json
  9. +45
    -1
      composer.lock
  10. +2
    -2
      config/app.php
  11. +17
    -0
      config/auth.php
  12. +2
    -1
      database/factories/UserFactory.php
  13. +14
    -0
      database/migrations/2014_10_12_000000_create_users_table.php
  14. +2
    -0
      resources/lang/pt-BR/auth.php
  15. +5
    -0
      resources/lang/pt-BR/user_categories.php
  16. +8
    -0
      resources/lang/pt-BR/users.php
  17. +0
    -8
      resources/views/auth/register.blade.php
  18. +8
    -0
      resources/views/auth/register/individual.blade.php
  19. +23
    -0
      resources/views/emails/users/password.blade.php
  20. +7
    -31
      resources/views/livewire/auth/register/individual.blade.php
  21. +2
    -1
      routes/web.php
  22. +11
    -44
      tests/Feature/Auth/Register/IndividualTest.php

+ 29
- 0
app/Events/UserCreating.php View File

@ -0,0 +1,29 @@
<?php
namespace App\Events;
use App\User;
use Illuminate\Queue\SerializesModels;
class UserCreating
{
use SerializesModels;
/**
* The user being created.
*
* @var \App\User
*/
public $user;
/**
* Create a new event instance.
*
* @param \App\User $user
* @return void
*/
public function __construct(User $user)
{
$this->user = $user;
}
}

app/Http/Livewire/Auth/Register.php → app/Http/Livewire/Auth/Register/Individual.php View File


+ 37
- 0
app/Listeners/SendUserPasswordEmail.php View File

@ -0,0 +1,37 @@
<?php
namespace App\Listeners;
use App\Events\UserCreating;
use App\Mail\UserPassword;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Str;
class SendUserPasswordEmail
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param \App\Events\UserCreating $event
* @return void
*/
public function handle(UserCreating $event)
{
$password = Str::random(config('auth.password_requirements.users.min_length'));
$event->user->password = Hash::make($password);
Mail::to($event->user)->send(new UserPassword($event->user, $password));
}
}

+ 50
- 0
app/Mail/UserPassword.php View File

@ -0,0 +1,50 @@
<?php
namespace App\Mail;
use App\User;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class UserPassword extends Mailable
{
use Queueable, SerializesModels;
/**
* The user instance.
*
* @var \App\User
*/
public $user;
/**
* The user password.
*
* @var string
*/
public $password;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct(User $user, string $password)
{
$this->user = $user;
$this->password = $password;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->subject(__('Seu cadastro em ') . config('app.name'))
->markdown('emails.users.password');
}
}

+ 6
- 1
app/Providers/EventServiceProvider.php View File

@ -2,6 +2,8 @@
namespace App\Providers;
use App\Events\UserCreating;
use App\Listeners\SendUserPasswordEmail;
use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
@ -15,8 +17,11 @@ class EventServiceProvider extends ServiceProvider
* @var array
*/
protected $listen = [
UserCreating::class => [
SendUserPasswordEmail::class,
],
Registered::class => [
SendEmailVerificationNotification::class,
// SendEmailVerificationNotification::class,
],
];


+ 35
- 1
app/User.php View File

@ -2,6 +2,7 @@
namespace App;
use App\Events\UserCreating;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
@ -16,7 +17,7 @@ class User extends Authenticatable
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
'name', 'email', 'password', 'category_id',
];
/**
@ -36,4 +37,37 @@ class User extends Authenticatable
protected $casts = [
'email_verified_at' => 'datetime',
];
/**
* The event map for the model.
*
* @var array
*/
protected $dispatchesEvents = [
'creating' => UserCreating::class,
];
//
//
// =====================================================================
// RELATIONSHIPS
// =====================================================================
//
//
/**
* Get the user's category
*/
public function category()
{
return $this->belongsTo(UserCategory::class);
}
//
//
// =====================================================================
// OTHER METHODS
// =====================================================================
//
//
}

+ 30
- 0
app/UserCategory.php View File

@ -0,0 +1,30 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Sushi\Sushi;
class UserCategory extends Model
{
use Sushi;
protected $rows = [
[
'key' => 'individual',
'name' => 'Associado Indivíduo',
],
[
'key' => 'company',
'name' => 'Associada Empresa Apoiadora',
],
[
'key' => 'acting-institution',
'name' => 'Associada Instituição Atuante',
],
[
'key' => 'supporting-institution',
'name' => 'Associada Instituição Apoiadora',
],
];
}

+ 1
- 0
composer.json View File

@ -9,6 +9,7 @@
"license": "MIT",
"require": {
"php": "^7.2.5",
"calebporzio/sushi": "^2.0",
"fideloper/proxy": "^4.2",
"fruitcake/laravel-cors": "^1.0",
"guzzlehttp/guzzle": "^6.3",


+ 45
- 1
composer.lock View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "5f1d4ac11559c3a277baf833b1777cea",
"content-hash": "61a6d19307e7210b7b3f5262d1c1cdb4",
"packages": [
{
"name": "asm89/stack-cors",
@ -104,6 +104,50 @@
],
"time": "2020-04-15T15:59:35+00:00"
},
{
"name": "calebporzio/sushi",
"version": "v2.0.0",
"source": {
"type": "git",
"url": "https://github.com/calebporzio/sushi.git",
"reference": "df69a1af1fbbc0aed96f6563770f8d79fe0eb6a5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/calebporzio/sushi/zipball/df69a1af1fbbc0aed96f6563770f8d79fe0eb6a5",
"reference": "df69a1af1fbbc0aed96f6563770f8d79fe0eb6a5",
"shasum": ""
},
"require": {
"illuminate/database": "^5.8 || ^6.0 || ^7.0",
"illuminate/support": "^5.8 || ^6.0 || ^7.0",
"php": "^7.1.3"
},
"require-dev": {
"doctrine/dbal": "^2.10",
"orchestra/database": "3.8.* || 3.9.* || ^4.0",
"orchestra/testbench": "3.8.* || 3.9.* || ^4.0",
"phpunit/phpunit": "^7.5 || ^8.4 || ^9.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Sushi\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Caleb Porzio",
"email": "calebporzio@gmail.com"
}
],
"description": "Eloquent's missing \"array\" driver.",
"time": "2020-03-04T02:49:53+00:00"
},
{
"name": "dnoegel/php-xdg-base-dir",
"version": "v0.1.1",


+ 2
- 2
config/app.php View File

@ -80,7 +80,7 @@ return [
|
*/
'locale' => 'en',
'locale' => 'pt-BR',
/*
|--------------------------------------------------------------------------
@ -106,7 +106,7 @@ return [
|
*/
'faker_locale' => 'en_US',
'faker_locale' => 'pt_BR',
/*
|--------------------------------------------------------------------------


+ 17
- 0
config/auth.php View File

@ -114,4 +114,21 @@ return [
'password_timeout' => 10800,
/*
|--------------------------------------------------------------------------
| Password requirements
|--------------------------------------------------------------------------
|
| This array specifies the password requirements such as length, special
| characters, etc.
|
*/
'password_requirements' => [
'users' => [
'min_length' => 10,
'max_length' => 255,
],
],
];

+ 2
- 1
database/factories/UserFactory.php View File

@ -3,6 +3,7 @@
/** @var \Illuminate\Database\Eloquent\Factory $factory */
use App\User;
use App\UserCategory;
use Faker\Generator as Faker;
use Illuminate\Support\Str;
@ -21,8 +22,8 @@ $factory->define(User::class, function (Faker $faker) {
return [
'name' => $faker->name,
'email' => $faker->unique()->safeEmail,
'email_verified_at' => now(),
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
'category_id' => UserCategory::where('key', 'individual')->first()->id,
'remember_token' => Str::random(10),
];
});

+ 14
- 0
database/migrations/2014_10_12_000000_create_users_table.php View File

@ -19,6 +19,20 @@ class CreateUsersTable extends Migration
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
// User profile
$table->foreignId('category_id');
// $table->foreignId('nature_id');
// $table->foreignId('type_id');
// $table->string('avatar')->nullable();
// $table->date('birthday');
// $table->json('document')->nullable();
// $table->json('address');
// $table->string('phone');
// $table->string('discussion');
// $table->integer('donation')->nullable();
// $table->json('profile');
$table->rememberToken();
$table->timestamps();
});


+ 2
- 0
resources/lang/pt-BR/auth.php View File

@ -15,5 +15,7 @@ return [
'failed' => 'Credenciais informadas não correspondem com nossos registros.',
'throttle' => 'Você realizou muitas tentativas de login. Por favor, tente novamente em :seconds segundos.',
'login' => 'Entre na sua conta',
'register' => 'Cadastrar',
];

+ 5
- 0
resources/lang/pt-BR/user_categories.php View File

@ -0,0 +1,5 @@
<?php
return [
'individual' => 'Associado Indivíduo',
];

+ 8
- 0
resources/lang/pt-BR/users.php View File

@ -0,0 +1,8 @@
<?php
return [
'attributes' => [
'name' => 'Nome',
'email' => 'E-mail',
],
];

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

@ -1,8 +0,0 @@
@extends('layouts.auth')
@section('title', 'Create a new account')
@section('content')
<div>
@livewire('auth.register')
</div>
@endsection

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

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

+ 23
- 0
resources/views/emails/users/password.blade.php View File

@ -0,0 +1,23 @@
@component('mail::message')
{{ __('Olá') }}!
{{ __('Você acabou de se registrar em ') }} {{ config('app.name', 'Laravel') }}. {{ __('Sua senha é') }}:
@component('mail::panel')
**{{ $password }}**
@endcomponent
@component('mail::button', ['url' => route('login') ])
{{ __('Fazer login') }}
@endcomponent
{{ __('Obrigado,') }}
{{ __('Equipe') }} {{ config('app.name') }}
@component('mail::footer')
{{ __('Se o botão acima não funcionar, copie e cole a URL a seguir em seu navegador:') }} {{ route('login') }}
@endcomponent
@endcomponent

resources/views/livewire/auth/register.blade.php → resources/views/livewire/auth/register/individual.blade.php View File


+ 2
- 1
routes/web.php View File

@ -17,7 +17,8 @@ Route::view('/', 'welcome')->name('home');
Route::middleware('guest')->group(function () {
Route::view('login', 'auth.login')->name('login');
Route::view('register', 'auth.register')->name('register');
Route::redirect('register', 'register/individual')->name('register');
Route::view('register/individual', 'auth.register.individual')->name('register.individual');
});
Route::view('password/reset', 'auth.passwords.email')->name('password.request');


tests/Feature/Auth/RegisterTest.php → tests/Feature/Auth/Register/IndividualTest.php View File