Merge pull request #6144 from turbo124/v5-develop

Fixes for contact registration
This commit is contained in:
David Bomba 2021-06-28 19:56:29 +10:00 committed by GitHub
commit 0429474abc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 62 additions and 29 deletions

View File

@ -15,6 +15,7 @@ use App\Exceptions\NonExistingMigrationFile;
use App\Http\Requests\Import\ImportJsonRequest;
use App\Jobs\Company\CompanyExport;
use App\Jobs\Company\CompanyImport;
use App\Utils\Ninja;
use App\Utils\Traits\MakesHash;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Cache;
@ -63,15 +64,12 @@ class ImportJsonController extends BaseController
$import_file = $request->file('files');
$contents = $this->unzipFile($import_file->getPathname());
$file_location = $this->unzipFile($import_file->getPathname());
$hash = Str::random(32);
nlog($hash);
Cache::put( $hash, base64_encode( $contents ), 3600 );
CompanyImport::dispatch(auth()->user()->getCompany(), auth()->user(), $hash, $request->except('files'))->delay(now()->addMinutes(1))->onQueue('himem');;
if(Ninja::isHosted())
CompanyImport::dispatch(auth()->user()->getCompany(), auth()->user(), $file_location, $request->except('files'))->onQueue('himem');
else
CompanyImport::dispatch(auth()->user()->getCompany(), auth()->user(), $file_location, $request->except('files'));
return response()->json(['message' => 'Processing'], 200);
@ -90,11 +88,12 @@ class ImportJsonController extends BaseController
if (! file_exists($file_location))
throw new NonExistingMigrationFile('Backup file does not exist, or is corrupted.');
$data = file_get_contents($file_location);
//$data = file_get_contents($file_location);
unlink($file_contents);
unlink($file_location);
return $file_location;
//unlink($file_contents);
//unlink($file_location);
return $data;
//return $data;
}
}

View File

@ -33,7 +33,8 @@ class ContactRegister
if($company)
{
abort_unless($company->client_can_register, 404);
if(! $company->client_can_register)
abort(400, 'Registration disabled');
$request->merge(['key' => $company->company_key]);
@ -49,7 +50,9 @@ class ContactRegister
if($company = Company::where($query)->first())
{
abort_unless($company->client_can_register, 404);
if(! $company->client_can_register)
abort(400, 'Registration disabled');
$request->merge(['key' => $company->company_key]);
@ -62,7 +65,10 @@ class ContactRegister
if ($request->route()->parameter('company_key') && Ninja::isSelfHost()) {
$company = Company::where('company_key', $request->company_key)->firstOrFail();
abort_unless($company->client_can_register, 404);
if(! (bool)$company->client_can_register);
abort(400, 'Registration disabled');
$request->merge(['key' => $company->company_key]);
return $next($request);
}
@ -72,7 +78,8 @@ class ContactRegister
if (!$request->route()->parameter('company_key') && Ninja::isSelfHost()) {
$company = Account::first()->default_company;
abort_unless($company->client_can_register, 404);
if(! $company->client_can_register)
abort(400, 'Registration disabled');
$request->merge(['key' => $company->company_key]);

View File

@ -2,6 +2,7 @@
namespace App\Http\Requests\ClientPortal;
use App\Libraries\MultiDB;
use App\Models\Account;
use App\Models\Company;
use App\Utils\Ninja;
@ -36,10 +37,11 @@ class RegisterRequest extends FormRequest
}
public function company()
{
if ($this->subdomain) {
return Company::where('subdomain', $this->subdomain)->firstOrFail();
}
{
//this should be all we need, the rest SHOULD be redundant because of our Middleware
if ($this->key)
return Company::where('company_key', $this->key)->first();
if ($this->company_key) {
return Company::where('company_key', $this->company_key)->firstOrFail();
@ -48,11 +50,34 @@ class RegisterRequest extends FormRequest
if (!$this->route()->parameter('company_key') && Ninja::isSelfHost()) {
$company = Account::first()->default_company;
abort_unless($company->client_can_register, 404);
if(!$company->client_can_register)
abort(403, "This page is restricted");
return $company;
}
abort(404, 'Register request not found.');
if (Ninja::isHosted()) {
$subdomain = explode('.', $this->getHost())[0];
$query = [
'subdomain' => $subdomain,
'portal_mode' => 'subdomain',
];
if($company = MultiDB::findAndSetDbByDomain($query))
return $company;
$query = [
'portal_domain' => $this->getSchemeAndHttpHost(),
'portal_mode' => 'domain',
];
if($company = MultiDB::findAndSetDbByDomain($query))
return $company;
}
abort(400, 'Register request not found.');
}
}

View File

@ -85,7 +85,7 @@ class CompanyImport implements ShouldQueue
public $user;
private $hash;
private $file_location;
public $backup_file;
@ -146,11 +146,11 @@ class CompanyImport implements ShouldQueue
* @param string $hash - the cache hash of the import data.
* @param array $request->all()
*/
public function __construct(Company $company, User $user, string $hash, array $request_array)
public function __construct(Company $company, User $user, string $file_location, array $request_array)
{
$this->company = $company;
$this->user = $user;
$this->hash = $hash;
$this->file_location = $file_location;
$this->request_array = $request_array;
$this->current_app_version = config('ninja.app_version');
}
@ -164,14 +164,14 @@ class CompanyImport implements ShouldQueue
$this->company_owner = $this->company->owner();
nlog("Company ID = {$this->company->id}");
nlog("Hash ID = {$this->hash}");
nlog("file_location ID = {$this->file_location}");
$this->backup_file = Cache::get($this->hash);
// $this->backup_file = Cache::get($this->hash);
if ( empty( $this->backup_file ) )
if ( empty( $this->file_location ) )
throw new \Exception('No import data found, has the cache expired?');
$this->backup_file = json_decode(base64_decode($this->backup_file));
$this->backup_file = json_decode(file_get_contents($this->file_location));
// nlog($this->backup_file);
$this->checkUserCount();
@ -198,6 +198,8 @@ class CompanyImport implements ShouldQueue
}
unlink($this->file_location);
}
/**