Deploy: 2026-05-23 03:23:22
This commit is contained in:
@@ -51,8 +51,19 @@ class AuthController extends BaseController
|
||||
'role' => 'admin'
|
||||
]);
|
||||
|
||||
// Automatically Assign 14-Day Free Trial (Plan ID: 4)
|
||||
$startsAt = date('Y-m-d H:i:s');
|
||||
$endsAt = date('Y-m-d H:i:s', strtotime('+14 days'));
|
||||
\App\Models\CompanySubscription::subscribeCompany(
|
||||
$companyId,
|
||||
4, // Trial Plan ID
|
||||
14, // Duration in days
|
||||
'auto_trial',
|
||||
'system'
|
||||
);
|
||||
|
||||
$response->json([
|
||||
'message' => 'Company and Admin user registered successfully.',
|
||||
'message' => 'Company and Admin user registered successfully. 14-Day Free Trial activated.',
|
||||
'company_id' => $companyId,
|
||||
'user_id' => $userId
|
||||
], 201);
|
||||
@@ -133,15 +144,35 @@ class AuthController extends BaseController
|
||||
return;
|
||||
}
|
||||
|
||||
$isSuperAdmin = (int)$user['company_id'] === 1;
|
||||
|
||||
// Fetch subscription info for the UI
|
||||
$subscription = \App\Models\CompanySubscription::findActiveByCompany($user['company_id']);
|
||||
$subStatus = $subscription ? $subscription['status'] : 'expired';
|
||||
$trialDaysLeft = 0;
|
||||
|
||||
if ($subscription && $subscription['status'] === 'active' && strpos((string)$subscription['payment_gateway'], 'auto_trial') !== false) {
|
||||
$subStatus = 'trialing'; // Treat as trialing
|
||||
}
|
||||
|
||||
if ($subStatus === 'trialing' || ($subscription && $subscription['plan_id'] == 4)) {
|
||||
$endsAt = strtotime($subscription['ends_at']);
|
||||
$now = time();
|
||||
$trialDaysLeft = max(0, ceil(($endsAt - $now) / 86400));
|
||||
}
|
||||
|
||||
$response->json([
|
||||
'user' => [
|
||||
'id' => $user['id'],
|
||||
'company_id' => $user['company_id'],
|
||||
'name' => $user['name'],
|
||||
'email' => Security::decrypt($user['email']), // Decrypt email before sending back
|
||||
'email' => Security::decrypt($user['email']),
|
||||
'role' => $user['role'],
|
||||
'status' => $user['status'],
|
||||
'created_at' => $user['created_at']
|
||||
'created_at' => $user['created_at'],
|
||||
'is_super_admin' => $isSuperAdmin,
|
||||
'subscription_status' => $subStatus,
|
||||
'trial_days_left' => $trialDaysLeft
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user