Changeset View
Changeset View
Standalone View
Standalone View
src/app/Http/Controllers/API/SignupController.php
Show All 37 Lines | class SignupController extends Controller | ||||
* | * | ||||
* @return \Illuminate\Http\JsonResponse JSON response | * @return \Illuminate\Http\JsonResponse JSON response | ||||
*/ | */ | ||||
public function plans(Request $request) | public function plans(Request $request) | ||||
{ | { | ||||
$plans = []; | $plans = []; | ||||
// Use reverse order just to have individual on left, group on right ;) | // Use reverse order just to have individual on left, group on right ;) | ||||
Plan::select()->orderByDesc('title')->get()->map(function ($plan) use (&$plans) { | Plan::withEnvTenantContext()->orderByDesc('title')->get() | ||||
->map(function ($plan) use (&$plans) { | |||||
$plans[] = [ | $plans[] = [ | ||||
'title' => $plan->title, | 'title' => $plan->title, | ||||
'name' => $plan->name, | 'name' => $plan->name, | ||||
'button' => __('app.planbutton', ['plan' => $plan->name]), | 'button' => __('app.planbutton', ['plan' => $plan->name]), | ||||
'description' => $plan->description, | 'description' => $plan->description, | ||||
]; | ]; | ||||
}); | }); | ||||
return response()->json(['status' => 'success', 'plans' => $plans]); | return response()->json(['status' => 'success', 'plans' => $plans]); | ||||
} | } | ||||
/** | /** | ||||
* Starts signup process. | * Starts signup process. | ||||
* | * | ||||
* Verifies user name and email/phone, sends verification email/sms message. | * Verifies user name and email/phone, sends verification email/sms message. | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | class SignupController extends Controller | ||||
* Returns signup invitation information. | * Returns signup invitation information. | ||||
* | * | ||||
* @param string $id Signup invitation identifier | * @param string $id Signup invitation identifier | ||||
* | * | ||||
* @return \Illuminate\Http\JsonResponse|void | * @return \Illuminate\Http\JsonResponse|void | ||||
*/ | */ | ||||
public function invitation($id) | public function invitation($id) | ||||
{ | { | ||||
$invitation = SignupInvitation::withEnvTenant()->find($id); | $invitation = SignupInvitation::withEnvTenantContext()->find($id); | ||||
if (empty($invitation) || $invitation->isCompleted()) { | if (empty($invitation) || $invitation->isCompleted()) { | ||||
return $this->errorResponse(404); | return $this->errorResponse(404); | ||||
} | } | ||||
$has_domain = $this->getPlan()->hasDomain(); | $has_domain = $this->getPlan()->hasDomain(); | ||||
$result = [ | $result = [ | ||||
▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | public function signup(Request $request) | ||||
); | ); | ||||
if ($v->fails()) { | if ($v->fails()) { | ||||
return response()->json(['status' => 'error', 'errors' => $v->errors()], 422); | return response()->json(['status' => 'error', 'errors' => $v->errors()], 422); | ||||
} | } | ||||
// Signup via invitation | // Signup via invitation | ||||
if ($request->invitation) { | if ($request->invitation) { | ||||
$invitation = SignupInvitation::withEnvTenant()->find($request->invitation); | $invitation = SignupInvitation::withEnvTenantContext()->find($request->invitation); | ||||
if (empty($invitation) || $invitation->isCompleted()) { | if (empty($invitation) || $invitation->isCompleted()) { | ||||
return $this->errorResponse(404); | return $this->errorResponse(404); | ||||
} | } | ||||
// Check required fields | // Check required fields | ||||
$v = Validator::make( | $v = Validator::make( | ||||
$request->all(), | $request->all(), | ||||
▲ Show 20 Lines • Show All 110 Lines • ▼ Show 20 Lines | class SignupController extends Controller | ||||
* | * | ||||
* @returns \App\Plan Plan object selected for current signup process | * @returns \App\Plan Plan object selected for current signup process | ||||
*/ | */ | ||||
protected function getPlan() | protected function getPlan() | ||||
{ | { | ||||
if (!$this->plan) { | if (!$this->plan) { | ||||
// Get the plan if specified and exists... | // Get the plan if specified and exists... | ||||
if ($this->code && $this->code->plan) { | if ($this->code && $this->code->plan) { | ||||
$plan = Plan::where('title', $this->code->plan)->first(); | $plan = Plan::withEnvTenantContext()->where('title', $this->code->plan)->first(); | ||||
} | } | ||||
// ...otherwise use the default plan | // ...otherwise use the default plan | ||||
if (empty($plan)) { | if (empty($plan)) { | ||||
// TODO: Get default plan title from config | // TODO: Get default plan title from config | ||||
$plan = Plan::where('title', 'individual')->first(); | $plan = Plan::withEnvTenantContext()->where('title', 'individual')->first(); | ||||
} | } | ||||
$this->plan = $plan; | $this->plan = $plan; | ||||
} | } | ||||
return $this->plan; | return $this->plan; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 85 Lines • Show Last 20 Lines |