mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
client register wip
This commit is contained in:
parent
e65b6d971e
commit
41c76e55bc
50
app/Http/Controllers/Auth/ContactRegisterController.php
Normal file
50
app/Http/Controllers/Auth/ContactRegisterController.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?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)
|
||||
{
|
||||
$company = Company::where('company_key', $request->company_key)->firstOrFail();
|
||||
|
||||
$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');
|
||||
}
|
||||
}
|
@ -105,5 +105,6 @@ class Kernel extends HttpKernel
|
||||
'web_db' => \App\Http\Middleware\SetWebDb::class,
|
||||
'api_db' => \App\Http\Middleware\SetDb::class,
|
||||
'locale' => \App\Http\Middleware\Locale::class,
|
||||
'contact.register' => \App\Http\Middleware\ContactRegister::class,
|
||||
];
|
||||
}
|
||||
|
41
app/Http/Middleware/ContactRegister.php
Normal file
41
app/Http/Middleware/ContactRegister.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Models\Company;
|
||||
use Closure;
|
||||
|
||||
class ContactRegister
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
/**
|
||||
* Notes:
|
||||
*
|
||||
* 1. If request supports subdomain (for hosted) check domain and continue request.
|
||||
* 2. If request doesn't support subdomain and doesn' have company_key, abort
|
||||
* 3. firstOrFail() will abort with 404 if company with company_key wasn't found.
|
||||
* 4. Abort if setting isn't enabled.
|
||||
*/
|
||||
|
||||
if ($request->subdomain) {
|
||||
/** @wip */
|
||||
}
|
||||
|
||||
abort_unless($request->company_key, 404);
|
||||
|
||||
$company = Company::where('company_key', $request->company_key)->firstOrFail();
|
||||
|
||||
// abort_unless($company->getSetting('enable_client_registration'), 404);
|
||||
abort_unless(true, 404);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
33
app/Http/Requests/ClientPortal/RegisterRequest.php
Normal file
33
app/Http/Requests/ClientPortal/RegisterRequest.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\ClientPortal;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class RegisterRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
// Place to double check if key is okay, do company allow direct registrations, etc..
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'email' => ['required', 'string', 'email', 'max:255', 'unique:client_contacts'],
|
||||
'password' => ['required', 'string', 'min:6', 'confirmed'],
|
||||
];
|
||||
}
|
||||
}
|
@ -3208,4 +3208,8 @@ return [
|
||||
|
||||
'payment_failed_subject' => 'Payment failed for Client :client',
|
||||
'payment_failed_body' => 'A payment made by client :client failed with message :message',
|
||||
|
||||
'register' => 'Register',
|
||||
'register_label' => 'Create your account in seconds',
|
||||
'password_confirmation' => 'Confirm your password',
|
||||
];
|
||||
|
53
resources/views/portal/ninja2020/auth/register.blade.php
Normal file
53
resources/views/portal/ninja2020/auth/register.blade.php
Normal file
@ -0,0 +1,53 @@
|
||||
@extends('portal.ninja2020.layout.clean')
|
||||
@section('meta_title', ctrans('texts.register'))
|
||||
|
||||
@section('body')
|
||||
<div class="grid lg:grid-cols-3">
|
||||
<div class="hidden lg:block col-span-1 bg-red-100 h-screen">
|
||||
<img src="https://www.invoiceninja.com/wp-content/uploads/2018/04/bg-home2018b.jpg" class="w-full h-screen object-cover" alt="Background image">
|
||||
</div>
|
||||
<div class="col-span-2 h-screen flex">
|
||||
<div class="m-auto md:w-1/2 lg:w-1/4">
|
||||
<div class="flex flex-col">
|
||||
<h1 class="text-center text-3xl">{{ ctrans('texts.register') }}</h1>
|
||||
<p class="block text-center text-gray-600">{{ ctrans('texts.register_label') }}</p>
|
||||
<form action="{{ route('client.register', request()->route('company_key')) }}" method="post" class="mt-6">
|
||||
@csrf
|
||||
<div class="flex flex-col">
|
||||
<label for="email" class="input-label">{{ ctrans('texts.email_address') }}</label>
|
||||
<input type="email" name="email" id="email" class="input" value="{{ old('email') }}" autofocus>
|
||||
@error('email')
|
||||
<div class="validation validation-fail">
|
||||
{{ $message }}
|
||||
</div>
|
||||
@enderror
|
||||
</div>
|
||||
<div class="flex flex-col mt-4">
|
||||
<label for="password" class="input-label">{{ ctrans('texts.password') }}</label>
|
||||
<input type="password" name="password" id="password" class="input">
|
||||
@error('password')
|
||||
<div class="validation validation-fail">
|
||||
{{ $message }}
|
||||
</div>
|
||||
@enderror
|
||||
</div>
|
||||
<div class="flex flex-col mt-4">
|
||||
<label for="email" class="input-label">{{ ctrans('texts.password_confirmation') }}</label>
|
||||
<input type="password" name="password_confirmation" id="password_confirmation" class="input">
|
||||
@error('password_confirmation')
|
||||
<div class="validation validation-fail">
|
||||
{{ $message }}
|
||||
</div>
|
||||
@enderror
|
||||
</div>
|
||||
<div class="mt-5">
|
||||
<button id="loginBtn" class="button button-primary button-block">
|
||||
{{ trans('texts.register') }}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
@ -7,6 +7,9 @@ Route::get('client', 'Auth\ContactLoginController@showLoginForm')->name('client.
|
||||
Route::get('client/login', 'Auth\ContactLoginController@showLoginForm')->name('client.login')->middleware('locale');
|
||||
Route::post('client/login', 'Auth\ContactLoginController@login')->name('client.login.submit');
|
||||
|
||||
Route::get('client/register/{company_key?}', 'Auth\ContactRegisterController@showRegisterForm')->name('client.register');
|
||||
Route::post('client/register/{company_key?}', 'Auth\ContactRegisterController@register');
|
||||
|
||||
Route::get('client/password/reset', 'Auth\ContactForgotPasswordController@showLinkRequestForm')->name('client.password.request')->middleware('locale');
|
||||
Route::post('client/password/email', 'Auth\ContactForgotPasswordController@sendResetLinkEmail')->name('client.password.email')->middleware('locale');
|
||||
Route::get('client/password/reset/{token}', 'Auth\ContactResetPasswordController@showResetForm')->name('client.password.reset')->middleware('locale');
|
||||
|
Loading…
x
Reference in New Issue
Block a user