diff --git a/app/Events/UserCreating.php b/app/Events/UserCreating.php new file mode 100644 index 0000000..a9338c0 --- /dev/null +++ b/app/Events/UserCreating.php @@ -0,0 +1,29 @@ +user = $user; + } +} diff --git a/app/Http/Livewire/Auth/Register.php b/app/Http/Livewire/Auth/Register/Individual.php similarity index 58% rename from app/Http/Livewire/Auth/Register.php rename to app/Http/Livewire/Auth/Register/Individual.php index 7b5b00e..9a06c38 100644 --- a/app/Http/Livewire/Auth/Register.php +++ b/app/Http/Livewire/Auth/Register/Individual.php @@ -1,14 +1,14 @@ validate([ 'name' => ['required'], 'email' => ['required', 'email', 'unique:users'], - 'password' => ['required', 'min:8', 'same:passwordConfirmation'], ]); $user = User::create([ 'email' => $this->email, 'name' => $this->name, - 'password' => Hash::make($this->password), + 'category_id' => UserCategory::where('key', 'individual')->first()->id, ]); - $user->sendEmailVerificationNotification(); - Auth::login($user, true); redirect(route('home')); @@ -45,6 +36,6 @@ class Register extends Component public function render() { - return view('livewire.auth.register'); + return view('livewire.auth.register.individual'); } } diff --git a/app/Listeners/SendUserPasswordEmail.php b/app/Listeners/SendUserPasswordEmail.php new file mode 100644 index 0000000..3204358 --- /dev/null +++ b/app/Listeners/SendUserPasswordEmail.php @@ -0,0 +1,37 @@ +user->password = Hash::make($password); + Mail::to($event->user)->send(new UserPassword($event->user, $password)); + } +} diff --git a/app/Mail/UserPassword.php b/app/Mail/UserPassword.php new file mode 100644 index 0000000..86999f3 --- /dev/null +++ b/app/Mail/UserPassword.php @@ -0,0 +1,50 @@ +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'); + } +} diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 723a290..785a23f 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -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, ], ]; diff --git a/app/User.php b/app/User.php index e79dab7..6c71516 100644 --- a/app/User.php +++ b/app/User.php @@ -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 + // ===================================================================== + // + // } diff --git a/app/UserCategory.php b/app/UserCategory.php new file mode 100644 index 0000000..39b0b81 --- /dev/null +++ b/app/UserCategory.php @@ -0,0 +1,30 @@ + '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', + ], + ]; +} diff --git a/composer.json b/composer.json index 68358b0..17b8f22 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/composer.lock b/composer.lock index d28b720..ee0af9c 100644 --- a/composer.lock +++ b/composer.lock @@ -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", diff --git a/config/app.php b/config/app.php index 8409e00..ff3b6f1 100644 --- a/config/app.php +++ b/config/app.php @@ -80,7 +80,7 @@ return [ | */ - 'locale' => 'en', + 'locale' => 'pt-BR', /* |-------------------------------------------------------------------------- @@ -106,7 +106,7 @@ return [ | */ - 'faker_locale' => 'en_US', + 'faker_locale' => 'pt_BR', /* |-------------------------------------------------------------------------- diff --git a/config/auth.php b/config/auth.php index aaf982b..3a54923 100644 --- a/config/auth.php +++ b/config/auth.php @@ -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, + ], + ], + ]; diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 741edea..904e625 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -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), ]; }); diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php index 621a24e..840ae45 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -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(); }); diff --git a/resources/lang/pt-BR/auth.php b/resources/lang/pt-BR/auth.php index c6cb01d..4548952 100644 --- a/resources/lang/pt-BR/auth.php +++ b/resources/lang/pt-BR/auth.php @@ -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', ]; diff --git a/resources/lang/pt-BR/user_categories.php b/resources/lang/pt-BR/user_categories.php new file mode 100644 index 0000000..4b69a42 --- /dev/null +++ b/resources/lang/pt-BR/user_categories.php @@ -0,0 +1,5 @@ + 'Associado Indivíduo', +]; diff --git a/resources/lang/pt-BR/users.php b/resources/lang/pt-BR/users.php new file mode 100644 index 0000000..5b6a2f1 --- /dev/null +++ b/resources/lang/pt-BR/users.php @@ -0,0 +1,8 @@ + [ + 'name' => 'Nome', + 'email' => 'E-mail', + ], +]; diff --git a/resources/views/auth/register.blade.php b/resources/views/auth/register.blade.php deleted file mode 100644 index b2e06ba..0000000 --- a/resources/views/auth/register.blade.php +++ /dev/null @@ -1,8 +0,0 @@ -@extends('layouts.auth') -@section('title', 'Create a new account') - -@section('content') -
- Or - - sign in to your account + Ou + + {{ __('auth.login') }}
@@ -21,7 +21,7 @@