add agents creation form
This commit is contained in:
parent
bbfba9e593
commit
06d0b88a73
@ -9,14 +9,14 @@
|
|||||||
use Laravel\Fortify\Contracts\UpdatesUserProfileInformation;
|
use Laravel\Fortify\Contracts\UpdatesUserProfileInformation;
|
||||||
|
|
||||||
class UpdateUserProfileInformation implements UpdatesUserProfileInformation
|
class UpdateUserProfileInformation implements UpdatesUserProfileInformation
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Validate and update the given user's profile information.
|
* Validate and update the given user's profile information.
|
||||||
*
|
*
|
||||||
* @param array<string, string> $input
|
* @param array<string, string> $input
|
||||||
*/
|
*/
|
||||||
public function update(User $user, array $input): void
|
public function update(User $user, array $input): void
|
||||||
{
|
{
|
||||||
Validator::make($input, [
|
Validator::make($input, [
|
||||||
'name' => ['required', 'string', 'max:255'],
|
'name' => ['required', 'string', 'max:255'],
|
||||||
|
|
||||||
@ -29,16 +29,21 @@ public function update(User $user, array $input): void
|
|||||||
],
|
],
|
||||||
])->validateWithBag('updateProfileInformation');
|
])->validateWithBag('updateProfileInformation');
|
||||||
|
|
||||||
if ($input['email'] !== $user->email &&
|
if (
|
||||||
$user instanceof MustVerifyEmail) {
|
$input['email'] !== $user->email &&
|
||||||
|
$user instanceof MustVerifyEmail
|
||||||
|
)
|
||||||
|
{
|
||||||
$this->updateVerifiedUser($user, $input);
|
$this->updateVerifiedUser($user, $input);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
$user->forceFill([
|
$user->forceFill([
|
||||||
'name' => $input['name'],
|
'name' => $input['name'],
|
||||||
'email' => $input['email'],
|
'email' => $input['email'],
|
||||||
])->save();
|
])->save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the given verified user's profile information.
|
* Update the given verified user's profile information.
|
||||||
@ -46,7 +51,7 @@ public function update(User $user, array $input): void
|
|||||||
* @param array<string, string> $input
|
* @param array<string, string> $input
|
||||||
*/
|
*/
|
||||||
protected function updateVerifiedUser(User $user, array $input): void
|
protected function updateVerifiedUser(User $user, array $input): void
|
||||||
{
|
{
|
||||||
$user->forceFill([
|
$user->forceFill([
|
||||||
'name' => $input['name'],
|
'name' => $input['name'],
|
||||||
'email' => $input['email'],
|
'email' => $input['email'],
|
||||||
@ -54,5 +59,5 @@ protected function updateVerifiedUser(User $user, array $input): void
|
|||||||
])->save();
|
])->save();
|
||||||
|
|
||||||
$user->sendEmailVerificationNotification();
|
$user->sendEmailVerificationNotification();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@ -4,15 +4,13 @@
|
|||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Models\Agent\Agent;
|
|
||||||
use App\Models\Company\Company;
|
use App\Models\Company\Company;
|
||||||
|
use App\Models\Company\CompanyAdmin;
|
||||||
|
use App\Models\Agent\Agent;
|
||||||
|
|
||||||
use Illuminate\Foundation\Auth\RegistersUsers;
|
use Illuminate\Foundation\Auth\RegistersUsers;
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
use App\Notifications\UserRegistered;
|
|
||||||
|
|
||||||
class RegisterController extends Controller
|
class RegisterController extends Controller
|
||||||
{
|
{
|
||||||
@ -70,14 +68,12 @@ protected function validator(array $data)
|
|||||||
*/
|
*/
|
||||||
protected function create(array $data)
|
protected function create(array $data)
|
||||||
{
|
{
|
||||||
$newUserPassword = Str::password(8);
|
|
||||||
$user = User::create([
|
$user = User::create([
|
||||||
'name' => $data['name'],
|
'name' => $data['name'],
|
||||||
'email' => $data['email'],
|
'email' => $data['email'],
|
||||||
'phone' => $data['phone'],
|
'phone' => $data['phone']
|
||||||
'password' => Hash::make($newUserPassword),
|
|
||||||
]);
|
]);
|
||||||
$user->notify(new UserRegistered(login: $user->email, password: $newUserPassword));
|
$user->setForcedPassword();
|
||||||
|
|
||||||
$company = Company::create([
|
$company = Company::create([
|
||||||
'name' => $data['name'],
|
'name' => $data['name'],
|
||||||
@ -88,6 +84,11 @@ protected function create(array $data)
|
|||||||
'status' => 'new'
|
'status' => 'new'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
CompanyAdmin::create([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'company_id' => $company->id
|
||||||
|
]);
|
||||||
|
|
||||||
Agent::create([
|
Agent::create([
|
||||||
'user_id' => $user->id,
|
'user_id' => $user->id,
|
||||||
'company_id' => $company->id
|
'company_id' => $company->id
|
||||||
|
|||||||
@ -36,7 +36,7 @@ public function index(Request $request)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
echo 'has no permissions';
|
abort(code: 401);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,8 +9,6 @@
|
|||||||
use App\Models\Company\Company;
|
use App\Models\Company\Company;
|
||||||
use App\Models\Company\CompanyAdmin;
|
use App\Models\Company\CompanyAdmin;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Notifications\UserRegistered;
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
class ConfirmCompanyController extends Controller
|
class ConfirmCompanyController extends Controller
|
||||||
{
|
{
|
||||||
@ -29,14 +27,12 @@ public function __invoke(Request $request)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$newUserPassword = Str::password(8);
|
|
||||||
$user = User::create([
|
$user = User::create([
|
||||||
'name' => $request->user_name,
|
'name' => $request->user_name,
|
||||||
'email' => $company->email,
|
'email' => $company->email,
|
||||||
'phone' => $request->user_phone,
|
'phone' => $request->user_phone
|
||||||
'password' => Hash::make($newUserPassword),
|
|
||||||
]);
|
]);
|
||||||
$user->notify(new UserRegistered($user->email, password: $newUserPassword));
|
$user->setForcedPassword();
|
||||||
}
|
}
|
||||||
CompanyAdmin::create([
|
CompanyAdmin::create([
|
||||||
'user_id' => $user->id,
|
'user_id' => $user->id,
|
||||||
|
|||||||
45
app/Http/Controllers/Company/CreateAgentController.php
Normal file
45
app/Http/Controllers/Company/CreateAgentController.php
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Http\Controllers\Company;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use App\Models\Company\CompanyAdmin;
|
||||||
|
use App\Models\Agent\Agent;
|
||||||
|
use App\Models\User;
|
||||||
|
|
||||||
|
class CreateAgentController extends Controller
|
||||||
|
{
|
||||||
|
public function __invoke(Request $request)
|
||||||
|
{
|
||||||
|
$request->only(['name', 'email', 'phone']);
|
||||||
|
$admin = CompanyAdmin::where('user_id', auth()->id());
|
||||||
|
if (!$admin->count())
|
||||||
|
{
|
||||||
|
abort(404);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$admin = $admin->first();
|
||||||
|
if (!$this->isUnique($request->email, $request->phone))
|
||||||
|
{
|
||||||
|
return back()->with('error', __('Agent is not unique'));
|
||||||
|
}
|
||||||
|
if ($user = User::create($request->all()))
|
||||||
|
{
|
||||||
|
$user->setForcedPassword();
|
||||||
|
$agent = Agent::create([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'company_id' => $admin->company_id
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
return to_route('company.agents.table');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isUnique($email, $phone)
|
||||||
|
{
|
||||||
|
if (User::where('email', $email)->count() || User::where('phone', $phone)->count())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -9,24 +9,27 @@
|
|||||||
|
|
||||||
use App\Models\Bitrix\SendCompany;
|
use App\Models\Bitrix\SendCompany;
|
||||||
class CreateCompanyController extends Controller
|
class CreateCompanyController extends Controller
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Handle the incoming request.
|
* Handle the incoming request.
|
||||||
*/
|
*/
|
||||||
public function __invoke(Request $request)
|
public function __invoke(Request $request)
|
||||||
{
|
{
|
||||||
$request->request->add([
|
$request->request->add([
|
||||||
'secret' => bin2hex(random_bytes(16)),
|
'secret' => bin2hex(random_bytes(16)),
|
||||||
'status' => 'new',
|
'status' => 'new',
|
||||||
'type' => 'AGENCY'
|
'type' => 'AGENCY'
|
||||||
]);
|
]);
|
||||||
$company = Company::create($request->only('name', 'email', 'inn', 'legal_address', 'secret', 'status', 'type'));
|
$company = Company::create($request->only('name', 'email', 'inn', 'legal_address', 'secret', 'status', 'type'));
|
||||||
if ($company) {
|
if ($company)
|
||||||
|
{
|
||||||
$companyConfirmByBitrix = new SendCompany($company);
|
$companyConfirmByBitrix = new SendCompany($company);
|
||||||
$companyConfirmByBitrix->send();
|
$companyConfirmByBitrix->send();
|
||||||
return view('company.created');
|
return view('company.created');
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
return back()->withInputs();
|
return back()->withInputs();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
use App\Models\Company\Company;
|
use App\Models\Company\Company;
|
||||||
use App\Models\Company\Details;
|
use App\Models\Company\Details;
|
||||||
use App\Models\Agent\Agent;
|
use App\Models\Company\CompanyAdmin;
|
||||||
|
|
||||||
class DetailsController extends Controller
|
class DetailsController extends Controller
|
||||||
{
|
{
|
||||||
@ -15,15 +15,15 @@ public function index()
|
|||||||
{
|
{
|
||||||
$company = false;
|
$company = false;
|
||||||
$userId = auth()->user()->id;
|
$userId = auth()->user()->id;
|
||||||
$agent = Agent::where('user_id', $userId)->get();
|
$admin = CompanyAdmin::where('user_id', $userId)->get();
|
||||||
if ($agent->count() == 1)
|
if ($admin->count() == 1)
|
||||||
{
|
{
|
||||||
$agent = $agent->first();
|
$agent = $admin->first();
|
||||||
$company = Company::find($agent->company_id);
|
$company = Company::find($agent->company_id);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return back();
|
abort(code: 401);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|||||||
19
app/Models/ForcedPassword.php
Normal file
19
app/Models/ForcedPassword.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
use App\Notifications\UserRegistered;
|
||||||
|
|
||||||
|
trait ForcedPassword
|
||||||
|
{
|
||||||
|
public function setForcedPassword()
|
||||||
|
{
|
||||||
|
$newPassword = Str::password(8);
|
||||||
|
$this->password = Hash::make($newPassword);
|
||||||
|
$this->save();
|
||||||
|
$this->notify(instance: new UserRegistered($this->email, password: $newPassword));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -7,9 +7,11 @@
|
|||||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||||
use Illuminate\Notifications\Notifiable;
|
use Illuminate\Notifications\Notifiable;
|
||||||
use Laravel\Sanctum\HasApiTokens;
|
use Laravel\Sanctum\HasApiTokens;
|
||||||
|
|
||||||
|
use App\Models\ForcedPassword;
|
||||||
class User extends Authenticatable
|
class User extends Authenticatable
|
||||||
{
|
{
|
||||||
use HasApiTokens, HasFactory, Notifiable;
|
use HasApiTokens, HasFactory, Notifiable, ForcedPassword;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The attributes that are mass assignable.
|
* The attributes that are mass assignable.
|
||||||
|
|||||||
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
@section('content')
|
@section('content')
|
||||||
<div>
|
<div>
|
||||||
<form class="d-flex mb-3" method="GET" action="{{ route('agents.table') }}">
|
<form class="d-flex mb-3" method="GET" action="{{ route('company.agents.table') }}">
|
||||||
<div class="p-2 border rounded-3 border-1 p-1 bg-white">
|
<div class="p-2 border rounded-3 border-1 bg-white">
|
||||||
<input type="radio" class="btn-check" name="status" value="all" id="option5" autocomplete="off"
|
<input type="radio" class="btn-check" name="status" value="all" id="option5" autocomplete="off"
|
||||||
onclick="this.form.submit()" {{ $status == 'all' || !$status ? 'checked' : '' }}>
|
onclick="this.form.submit()" {{ $status == 'all' || !$status ? 'checked' : '' }}>
|
||||||
<label class="btn p-2 fs-5" for="option5">Все</label>
|
<label class="btn p-2 fs-5" for="option5">Все</label>
|
||||||
@ -16,6 +16,7 @@
|
|||||||
autocomplete="off" onclick="this.form.submit()" {{ $status == $statuses::DISMISSED ? 'checked' : '' }}>
|
autocomplete="off" onclick="this.form.submit()" {{ $status == $statuses::DISMISSED ? 'checked' : '' }}>
|
||||||
<label class="btn p-2 fs-5" for="option7">Уволенные</label>
|
<label class="btn p-2 fs-5" for="option7">Уволенные</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="ms-auto p-2">
|
<div class="ms-auto p-2">
|
||||||
<select class="form-select form-select-lg" aria-label="Large select example">
|
<select class="form-select form-select-lg" aria-label="Large select example">
|
||||||
<option selected="">Город: любой</option>
|
<option selected="">Город: любой</option>
|
||||||
@ -24,6 +25,12 @@
|
|||||||
@endforeach
|
@endforeach
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="p-2">
|
||||||
|
<button type="button" class="btn btn-primary py-2 px-3 fs-5" data-bs-toggle="modal"
|
||||||
|
data-bs-target="#createAgentModal">
|
||||||
|
<i class="bi bi-person-plus"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
@if (!$status || $status == 'all' || $status == $statuses::ACTIVE)
|
@if (!$status || $status == 'all' || $status == $statuses::ACTIVE)
|
||||||
<h4 class="fw-bold mt-5 mb-3">Активные</h4>
|
<h4 class="fw-bold mt-5 mb-3">Активные</h4>
|
||||||
@ -39,4 +46,38 @@
|
|||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- Modal -->
|
||||||
|
<div class="modal fade" id="createAgentModal" tabindex="-1" aria-labelledby="createAgentModalLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog modal-dialog-centered">
|
||||||
|
<form class="modal-content" action="{{ route('company.agents.store') }}" method="post">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h1 class="modal-title fs-5" id="exampleModalLabel">{{ __('Create new agent') }}</h1>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
@csrf
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="agentName" class="form-label">Полное имя (ФИО)</label>
|
||||||
|
<input type="text" class="form-control" id="agentName" name="name">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="agentEmail" class="form-label">Электронная почта</label>
|
||||||
|
<input type="text" class="form-control" id="agentEmail" name="email">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="agentPhone" class="form-label">Телефон</label>
|
||||||
|
<input type="text" class="form-control" id="agentPhone" name="phone">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">{{ __('Close') }}</button>
|
||||||
|
<input type="submit" class="btn btn-primary" value="{{ __('Add agent') }}">
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@endsection
|
@endsection
|
||||||
|
|||||||
@ -12,7 +12,7 @@ class="nav-link d-flex align-items-center gap-2 fs-5 border rounded-4 active" ar
|
|||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item text-center m-2">
|
<li class="nav-item text-center m-2">
|
||||||
<a href="{{ route('agents.table') }}"
|
<a href="{{ route('company.agents.table') }}"
|
||||||
class="nav-link d-flex align-items-center gap-2 fs-5 border rounded-4 active" aria-current="page">
|
class="nav-link d-flex align-items-center gap-2 fs-5 border rounded-4 active" aria-current="page">
|
||||||
<i class="bi bi-people"></i> Агенты
|
<i class="bi bi-people"></i> Агенты
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
@ -1,11 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
use Illuminate\Foundation\Auth\EmailVerificationRequest;
|
use Illuminate\Foundation\Auth\EmailVerificationRequest;
|
||||||
|
|
||||||
use App\Http\Controllers\Company\CreateCompanyController;
|
use App\Http\Controllers\Company\CreateCompanyController;
|
||||||
|
use App\Http\Controllers\Company\AgentController;
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Web Routes
|
| Web Routes
|
||||||
@ -46,5 +44,7 @@
|
|||||||
Route::get('/clients/table', [App\Http\Controllers\ClientsTableController::class, 'index'])->name('clients.table');
|
Route::get('/clients/table', [App\Http\Controllers\ClientsTableController::class, 'index'])->name('clients.table');
|
||||||
Route::get('/company/details/', [App\Http\Controllers\Company\DetailsController::class, 'index'])->name('company.details');
|
Route::get('/company/details/', [App\Http\Controllers\Company\DetailsController::class, 'index'])->name('company.details');
|
||||||
Route::post('/company/{company}/details/', [App\Http\Controllers\Company\DetailsController::class, 'store'])->name('company.details.store');
|
Route::post('/company/{company}/details/', [App\Http\Controllers\Company\DetailsController::class, 'store'])->name('company.details.store');
|
||||||
Route::get('/agents/table', [App\Http\Controllers\Company\AgentsTableController::class, 'index'])->name('agents.table');
|
Route::get('/agents/table', [App\Http\Controllers\Company\AgentsTableController::class, 'index'])->name('company.agents.table');
|
||||||
|
Route::post('/company/details/', App\Http\Controllers\Company\CreateAgentController::class)->name('company.agents.store');
|
||||||
|
|
||||||
});
|
});
|
||||||
Loading…
Reference in New Issue
Block a user