Browse Source

Separa as configurações de autenticação dos modelos

usuarios_separados
Guilherme Capanema 6 years ago
parent
commit
e204ef41fe
4 changed files with 64 additions and 22 deletions
  1. +1
    -1
      app/Listeners/SendUserPasswordEmail.php
  2. +28
    -18
      config/auth.php
  3. +3
    -3
      database/migrations/2014_10_12_100000_create_associate_password_resets_table.php
  4. +32
    -0
      database/migrations/2014_10_12_100000_create_collaborator_password_resets_table.php

+ 1
- 1
app/Listeners/SendUserPasswordEmail.php View File

@ -30,7 +30,7 @@ class SendUserPasswordEmail
*/ */
public function handle(UserCreating $event) public function handle(UserCreating $event)
{ {
$password = Str::random(config('auth.password_requirements.users.min_length'));
$password = Str::random(config('auth.password_requirements.min_length'));
$event->user->password = Hash::make($password); $event->user->password = Hash::make($password);
Mail::to($event->user)->send(new UserPassword($event->user, $password)); Mail::to($event->user)->send(new UserPassword($event->user, $password));
} }


+ 28
- 18
config/auth.php View File

@ -14,8 +14,8 @@ return [
*/ */
'defaults' => [ 'defaults' => [
'guard' => 'web',
'passwords' => 'users',
'guard' => 'associates',
'passwords' => 'associates',
], ],
/* /*
@ -36,14 +36,19 @@ return [
*/ */
'guards' => [ 'guards' => [
'web' => [
'associates' => [
'driver' => 'session', 'driver' => 'session',
'provider' => 'users',
'provider' => 'associates',
],
'collaborators' => [
'driver' => 'session',
'provider' => 'collaborators',
], ],
'api' => [ 'api' => [
'driver' => 'token', 'driver' => 'token',
'provider' => 'users',
'provider' => 'collaborators',
'hash' => false, 'hash' => false,
], ],
], ],
@ -66,15 +71,15 @@ return [
*/ */
'providers' => [ 'providers' => [
'users' => [
'associates' => [
'driver' => 'eloquent', 'driver' => 'eloquent',
'model' => App\User::class,
'model' => App\Associate::class,
], ],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
'collaborators' => [
'driver' => 'eloquent',
'model' => App\Collaborator::class,
],
], ],
/* /*
@ -93,9 +98,16 @@ return [
*/ */
'passwords' => [ 'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'associates' => [
'provider' => 'associates',
'table' => 'associate_password_resets',
'expire' => 60,
'throttle' => 60,
],
'collaborators' => [
'provider' => 'collaborators',
'table' => 'collaborator_password_resets',
'expire' => 60, 'expire' => 60,
'throttle' => 60, 'throttle' => 60,
], ],
@ -125,10 +137,8 @@ return [
*/ */
'password_requirements' => [ 'password_requirements' => [
'users' => [
'min_length' => 10,
'max_length' => 255,
],
'min_length' => 10,
'max_length' => 255,
], ],
]; ];

database/migrations/2014_10_12_100000_create_password_resets_table.php → database/migrations/2014_10_12_100000_create_associate_password_resets_table.php View File


+ 32
- 0
database/migrations/2014_10_12_100000_create_collaborator_password_resets_table.php View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateCollaboratorPasswordResetsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('collaborator_password_resets', function (Blueprint $table) {
$table->string('email')->index();
$table->string('token');
$table->timestamp('created_at')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('collaborator_password_resets');
}
}