Fixes for user auth

This commit is contained in:
David Bomba 2025-05-29 19:27:26 +10:00
parent 89c915b261
commit 8d037a5ca9
7 changed files with 152 additions and 16 deletions

View File

@ -143,6 +143,12 @@ class CreateSingleAccount extends Command
'portal_domain' => 'http://ninja.test:8000',
'track_inventory' => true
]);
$custom_fields = new \stdClass();
$custom_fields->client1 = 'CKey|single_line_text';
$custom_fields->client2 = 'AKey|single_line_text';
$company->custom_fields = $custom_fields;
$faker = \Faker\Factory::create();
$settings = $company->settings;
@ -256,7 +262,11 @@ class CreateSingleAccount extends Command
'company_id' => $company->id,
'name' => 'cypress'
]);
$client->custom_value1 = $company->company_key;
$client->custom_value2 = $account->key;
$client->save();
ClientContact::factory()->create([
'user_id' => $user->id,
'client_id' => $client->id,
@ -422,6 +432,36 @@ class CreateSingleAccount extends Command
'quantity' => 1,
]);
$pe5 = Product::factory()->create([
'user_id' => $user->id,
'company_id' => $company->id,
'product_key' => 'enterprise_plan_5',
'notes' => 'The Enterprise Plan 5',
'cost' => 28,
'price' => 28,
'quantity' => 1,
]);
$pe10 = Product::factory()->create([
'user_id' => $user->id,
'company_id' => $company->id,
'product_key' => 'enterprise_plan_10',
'notes' => 'The Enterprise Plan 10',
'cost' => 56,
'price' => 56,
'quantity' => 1,
]);
$pe20 = Product::factory()->create([
'user_id' => $user->id,
'company_id' => $company->id,
'product_key' => 'enterprise_plan_20',
'notes' => 'The Enterprise Plan 20',
'cost' => 112,
'price' => 112,
'quantity' => 1,
]);
$p3 = Product::factory()->create([
'user_id' => $user->id,
'company_id' => $company->id,
@ -432,6 +472,28 @@ class CreateSingleAccount extends Command
'quantity' => 1,
]);
$p4= Product::factory()->create([
'user_id' => $user->id,
'company_id' => $company->id,
'product_key' => 'docuninja_user',
'notes' => 'The DocuNinja Monthly User Plan',
'cost' => 6,
'price' => 6,
'quantity' => 1,
]);
$p5 = Product::factory()->create([
'user_id' => $user->id,
'company_id' => $company->id,
'product_key' => 'docuninja_user_annual',
'notes' => 'The DocuNinja Annual User Plan',
'cost' => 60,
'price' => 60,
'quantity' => 1,
]);
$webhook_config = [
'post_purchase_url' => 'http://ninja.test:8000/api/admin/plan',
'post_purchase_rest_method' => 'post',
@ -464,6 +526,80 @@ class CreateSingleAccount extends Command
$sub->allow_plan_changes = true;
$sub->frequency_id = RecurringInvoice::FREQUENCY_MONTHLY;
$sub->save();
if(!\App\Models\Subscription::find(6)){
$sub = SubscriptionFactory::create($company->id, $user->id);
$sub->id = 6;
$sub->name = " PRO Pro Plan";
$sub->group_id = $gs->id;
$sub->recurring_product_ids = "{$p1->hashed_id}";
$sub->webhook_configuration = $webhook_config;
$sub->allow_plan_changes = true;
$sub->frequency_id = RecurringInvoice::FREQUENCY_MONTHLY;
$sub->save();
}
if (!\App\Models\Subscription::find(11)) {
$sub = SubscriptionFactory::create($company->id, $user->id);
$sub->id = 11;
$sub->name = " EEE Enterprise Plan";
$sub->group_id = $gs->id;
$sub->recurring_product_ids = "{$p2->hashed_id}";
$sub->webhook_configuration = $webhook_config;
$sub->allow_plan_changes = true;
$sub->frequency_id = RecurringInvoice::FREQUENCY_MONTHLY;
$sub->max_seats_limit =2;
$sub->per_seat_enabled = true;
$sub->save();
}
$_sub = $sub->replicate();
$_sub->id = 41;
$_sub->name = "Enterprise Plan 3-5 Users";
$_sub->recurring_product_ids = "{$pe5->hashed_id}";
$_sub->max_seats_limit =5;
$_sub->per_seat_enabled = true;
$_sub->save();
$_sub = $sub->replicate();
$_sub->id = 46;
$_sub->name = "Enterprise Plan 6-10 Users";
$_sub->recurring_product_ids = "{$pe10->hashed_id}";
$_sub->max_seats_limit =10;
$_sub->per_seat_enabled = true;
$_sub->save();
$_sub = $sub->replicate();
$_sub->id = 51;
$_sub->name = "Enterprise Plan 11-20 Users";
$_sub->recurring_product_ids = "{$pe20->hashed_id}";
$_sub->max_seats_limit =20;
$_sub->per_seat_enabled = true;
$_sub->save();
$sub = SubscriptionFactory::create($company->id, $user->id);
$sub->name = "DocuNinja Monthly Plan";
$sub->group_id = $gs->id;
$sub->recurring_product_ids = "{$p4->hashed_id}";
$sub->webhook_configuration = $webhook_config;
$sub->allow_plan_changes = true;
$sub->frequency_id = RecurringInvoice::FREQUENCY_MONTHLY;
$sub->save();
$sub = SubscriptionFactory::create($company->id, $user->id);
$sub->name = "DocuNinja Annual Plan";
$sub->group_id = $gs->id;
$sub->recurring_product_ids = "{$p5->hashed_id}";
$sub->webhook_configuration = $webhook_config;
$sub->allow_plan_changes = true;
$sub->frequency_id = RecurringInvoice::FREQUENCY_ANNUALLY;
$sub->save();
}
private function createClient($company, $user)

View File

@ -51,6 +51,7 @@ class EInvoicePeppolController extends BaseController
*/
public function setup(StoreEntityRequest $request, Storecove $storecove): Response|JsonResponse
{
/**
* @var \App\Models\Company
*/

View File

@ -208,7 +208,7 @@ class MultiDB
foreach (self::$dbs as $db) {
self::setDB($db);
if ($user = User::on($db)->where($data)->withTrashed()->first()) {
if ($user = User::where($data)->withTrashed()->first()) {
return $user;
}
}
@ -330,8 +330,9 @@ class MultiDB
$current_db = config('database.default');
foreach (self::$dbs as $db) {
self::setDB($db);
if ($ct = CompanyToken::on($db)->with([
if ($ct = CompanyToken::with([
'user.account',
'company',
'account',
@ -563,9 +564,8 @@ class MultiDB
$current_db = config('database.default');
foreach (self::$dbs as $db) {
if ($company = Company::on($db)->where($query_array)->first()) {
self::setDb($db);
self::setDb($db);
if ($company = Company::where($query_array)->first()) {
return $company;
}
}
@ -625,7 +625,6 @@ class MultiDB
foreach (self::$dbs as $db) {
if ($invite = $class::on($db)->where('key', $invitation_key)->exists()) {
self::setDb($db);
return true;
}
}

View File

@ -233,7 +233,7 @@ class StorecoveProxy
->withHeaders($this->getHeaders())
->post($uri, $payload);
if ($response->successful()) {
if ($response->successful()) {
if ($response->hasHeader('X-EINVOICE-QUOTA')) {
// @dave is there any case this will run when user is not logged in? (async)

View File

@ -1869,7 +1869,7 @@ $lang = array(
'upgrade_for_features' => 'Upgrade For More Features',
'pay_annually_discount' => 'Pay annually for 10 months + 2 free!',
'pro_upgrade_title' => 'Ninja Pro',
'pro_upgrade_feature1' => 'YourBrand.InvoiceNinja.com',
'pro_upgrade_feature1' => 'YourBrand.invoicing.co',
'pro_upgrade_feature2' => 'Customize every aspect of your invoice!',
'enterprise_upgrade_feature1' => 'Set permissions for multiple-users',
'enterprise_upgrade_feature2' => 'Attach 3rd party files to invoices & expenses',
@ -5530,7 +5530,7 @@ $lang = array(
'premium_business_plus_label' => 'Premium Business+',
'pro_plan_feature_1' => 'Unlimited Clients & Invoices',
'pro_plan_feature_2' => 'Remove "Created by Invoice Ninja"',
'pro_plan_feature_3' => 'Email Invoices via Gmail & MSN',
'pro_plan_feature_3' => 'Email Invoices via Gmail & Microsoft',
'pro_plan_feature_4' => 'Email Invoices via your custom SMTP',
'pro_plan_feature_5' => 'Branded URL: "YourSite".Invoicing.co',
'pro_plan_feature_6' => '11 Professional Invoice Templates',
@ -5546,10 +5546,10 @@ $lang = array(
'pro_plan_feature_16' => 'Interlink 10 Companies with 1 Login',
'pro_plan_feature_17' => 'Create Unique "Client Group" Settings',
'pro_plan_feature_18' => 'Auto Sales Tax Calculation (US States)',
'enterprise_plan_feature_1' => 'Create Additional Account Users (up to 50!) & Set Permissions per User',
'enterprise_plan_feature_2' => 'Attach Files to Emails & Client-Portal (pdf, jpg, ppt, xls, doc & more)',
'enterprise_plan_feature_3' => 'Fully Branded Client Portal: "Billing.YourCompany.com"',
'enterprise_plan_feature_4' => 'Integrate Your Financial Accounts and Sync Banking Transactions via Yodlee or Nordigen Banking Platforms',
'enterprise_plan_feature_1' => 'Additional Account Users & Permissions',
'enterprise_plan_feature_2' => 'Upload & Attach Files',
'enterprise_plan_feature_3' => 'Custom Portal Domain: "Billing.YourCompany.com"',
'enterprise_plan_feature_4' => 'Connect your bank accounts for syncing',
'premium_business_plus_feature_1' => 'Developer Concierge',
'premium_business_plus_feature_2' => 'Direct Priority Support',
'premium_business_plus_feature_3' => 'Invoice Design Service',

View File

@ -139,7 +139,7 @@ Route::group(['middleware' => ['throttle:login', 'api_secret_check', 'email_db']
Route::post('api/v1/reset_password', [ForgotPasswordController::class, 'sendResetLinkEmail']);
});
Route::group(['middleware' => ['throttle:api', 'api_db', 'token_auth', 'valid_json','locale'], 'prefix' => 'api/v1', 'as' => 'api.'], function () {
Route::group(['middleware' => ['throttle:api', 'token_auth', 'valid_json','locale'], 'prefix' => 'api/v1', 'as' => 'api.'], function () {
Route::post('password_timeout', PasswordTimeoutController::class)->name('password_timeout');
Route::put('accounts/{account}', [AccountController::class, 'update'])->name('account.update');

View File

@ -123,7 +123,7 @@ Route::get('client/subscriptions/{subscription}/purchase', [App\Http\Controllers
Route::get('client/subscriptions/{subscription}/purchase/v2', [App\Http\Controllers\ClientPortal\SubscriptionPurchaseController::class, 'upgrade'])->name('client.subscription.upgrade')->middleware('domain_db');
Route::get('client/subscriptions/{subscription}/purchase/v3', [App\Http\Controllers\ClientPortal\SubscriptionPurchaseController::class, 'v3'])->name('client.subscription.v3')->middleware('domain_db');
Route::group(['middleware' => ['api_db','invite_db'], 'prefix' => 'client', 'as' => 'client.'], function () {
Route::group(['middleware' => ['invite_db'], 'prefix' => 'client', 'as' => 'client.'], function () {
/*Invitation catches*/
Route::get('recurring_invoice/{invitation_key}', [App\Http\Controllers\ClientPortal\InvitationController::class, 'recurringRouter']);
Route::get('invoice/{invitation_key}', [App\Http\Controllers\ClientPortal\InvitationController::class, 'invoiceRouter']);