Changeset View
Changeset View
Standalone View
Standalone View
src/app/Http/Controllers/API/SignupController.php
Show All 19 Lines | |||||
use Illuminate\Support\Facades\Validator; | use Illuminate\Support\Facades\Validator; | ||||
use Illuminate\Support\Str; | use Illuminate\Support\Str; | ||||
/** | /** | ||||
* Signup process API | * Signup process API | ||||
*/ | */ | ||||
class SignupController extends Controller | class SignupController extends Controller | ||||
{ | { | ||||
/** @var ?\App\SignupCode A verification code object */ | |||||
protected $code; | |||||
/** @var ?\App\Plan Signup plan object */ | |||||
protected $plan; | |||||
/** | /** | ||||
* Returns plans definitions for signup. | * Returns plans definitions for signup. | ||||
* | * | ||||
* @param \Illuminate\Http\Request $request HTTP request | * @param \Illuminate\Http\Request $request HTTP request | ||||
* | * | ||||
* @return \Illuminate\Http\JsonResponse JSON response | * @return \Illuminate\Http\JsonResponse JSON response | ||||
*/ | */ | ||||
public function plans(Request $request) | public function plans(Request $request) | ||||
▲ Show 20 Lines • Show All 129 Lines • ▼ Show 20 Lines | public function verify(Request $request) | ||||
|| Str::upper($request->short_code) !== Str::upper($code->short_code) | || Str::upper($request->short_code) !== Str::upper($code->short_code) | ||||
) { | ) { | ||||
$errors = ['short_code' => "The code is invalid or expired."]; | $errors = ['short_code' => "The code is invalid or expired."]; | ||||
return response()->json(['status' => 'error', 'errors' => $errors], 422); | return response()->json(['status' => 'error', 'errors' => $errors], 422); | ||||
} | } | ||||
// For signup last-step mode remember the code object, so we can delete it | // For signup last-step mode remember the code object, so we can delete it | ||||
// with single SQL query (->delete()) instead of two (::destroy()) | // with single SQL query (->delete()) instead of two (::destroy()) | ||||
$this->code = $code; | $request->code = $code; | ||||
$has_domain = $this->getPlan()->hasDomain(); | $has_domain = $this->getPlan()->hasDomain(); | ||||
// Return user name and email/phone/voucher from the codes database, | // Return user name and email/phone/voucher from the codes database, | ||||
// domains list for selection and "plan type" flag | // domains list for selection and "plan type" flag | ||||
return response()->json([ | return response()->json([ | ||||
'status' => 'success', | 'status' => 'success', | ||||
'email' => $code->email, | 'email' => $code->email, | ||||
▲ Show 20 Lines • Show All 134 Lines • ▼ Show 20 Lines | public function signup(Request $request) | ||||
// Update the invitation | // Update the invitation | ||||
if (!empty($invitation)) { | if (!empty($invitation)) { | ||||
$invitation->status = SignupInvitation::STATUS_COMPLETED; | $invitation->status = SignupInvitation::STATUS_COMPLETED; | ||||
$invitation->user_id = $user->id; | $invitation->user_id = $user->id; | ||||
$invitation->save(); | $invitation->save(); | ||||
} | } | ||||
// Remove the verification code | // Remove the verification code | ||||
if ($this->code) { | if ($request->code) { | ||||
$this->code->delete(); | $request->code->delete(); | ||||
} | } | ||||
DB::commit(); | DB::commit(); | ||||
return AuthController::logonResponse($user, $request->password); | return AuthController::logonResponse($user, $request->password); | ||||
} | } | ||||
/** | /** | ||||
* Returns plan for the signup process | * Returns plan for the signup process | ||||
* | * | ||||
* @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) { | $request = request(); | ||||
if (!$request->plan || !$request->plan instanceof Plan) { | |||||
// Get the plan if specified and exists... | // Get the plan if specified and exists... | ||||
if ($this->code && $this->code->plan) { | if ($request->code && $request->code->plan) { | ||||
$plan = Plan::withEnvTenantContext()->where('title', $this->code->plan)->first(); | $plan = Plan::withEnvTenantContext()->where('title', $request->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::withEnvTenantContext()->where('title', 'individual')->first(); | $plan = Plan::withEnvTenantContext()->where('title', 'individual')->first(); | ||||
} | } | ||||
$this->plan = $plan; | $request->plan = $plan; | ||||
} | } | ||||
return $this->plan; | return $request->plan; | ||||
} | } | ||||
/** | /** | ||||
* Checks if the input string is a valid email address or a phone number | * Checks if the input string is a valid email address or a phone number | ||||
* | * | ||||
* @param string $input Email address or phone number | * @param string $input Email address or phone number | ||||
* @param bool $is_phone Will have been set to True if the string is valid phone number | * @param bool $is_phone Will have been set to True if the string is valid phone number | ||||
* | * | ||||
▲ Show 20 Lines • Show All 79 Lines • Show Last 20 Lines |