1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/Http/Controllers/Auth/ContactRegisterController.php

57 lines
1.6 KiB
PHP
Raw Normal View History

2020-05-28 17:39:38 +02:00
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Http\Requests\ClientPortal\RegisterRequest;
use App\Models\Client;
use App\Models\ClientContact;
use App\Models\Company;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
class ContactRegisterController extends Controller
{
public function __construct()
{
$this->middleware(['guest', 'contact.register']);
}
public function showRegisterForm(string $company_key)
{
return render('auth.register');
}
public function register(RegisterRequest $request)
{
2020-05-28 17:48:03 +02:00
if ($request->subdomain) {
$company = Company::where('subdomain', $request->subdomain)->firstOrFail();
}
if ($request->company_key) {
$company = Company::where('company_key', $request->company_key)->firstOrFail();
}
2020-05-28 17:39:38 +02:00
$client = factory(Client::class)->create([
'user_id' => $user->id, /** @wip */
'company_id' => $company->id
]);
ClientContact::create([
'first_name' => $request->first_name,
'last_name' => $request->last_name,
'email' => $request->email,
'company_id' => $company->id,
'password' => Hash::make($request->password),
'client_id' => $client->id,
'user_id' => $user->id, /** @wip */
'is_primary' => true, /** @verify */
'contact_key' => \Illuminate\Support\Str::random(40),
]);
Auth::guard('contact')->login($client, true);
return redirect()->route('client.dashboard');
}
}