Changeset View
Changeset View
Standalone View
Standalone View
src/app/Http/Controllers/API/SignupController.php
Show First 20 Lines • Show All 145 Lines • ▼ Show 20 Lines | public function invitation($id) | ||||
return response()->json($result); | return response()->json($result); | ||||
} | } | ||||
/** | /** | ||||
* Validation of the verification code. | * Validation of the verification code. | ||||
* | * | ||||
* @param \Illuminate\Http\Request $request HTTP request | * @param \Illuminate\Http\Request $request HTTP request | ||||
* @param bool $update Update the signup code record | |||||
* | * | ||||
* @return \Illuminate\Http\JsonResponse JSON response | * @return \Illuminate\Http\JsonResponse JSON response | ||||
*/ | */ | ||||
public function verify(Request $request) | public function verify(Request $request, $update = true) | ||||
{ | { | ||||
// Validate the request args | // Validate the request args | ||||
$v = Validator::make( | $v = Validator::make( | ||||
$request->all(), | $request->all(), | ||||
[ | [ | ||||
'code' => 'required', | 'code' => 'required', | ||||
'short_code' => 'required', | 'short_code' => 'required', | ||||
] | ] | ||||
Show All 11 Lines | public function verify(Request $request, $update = true) | ||||
|| $code->isExpired() | || $code->isExpired() | ||||
|| 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 | ||||
$request->code = $code; | $request->code = $code; | ||||
if ($update) { | |||||
$code->verify_ip_address = $request->ip(); | |||||
$code->save(); | |||||
} | |||||
$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, | ||||
'first_name' => $code->first_name, | 'first_name' => $code->first_name, | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | public function signup(Request $request) | ||||
$settings = [ | $settings = [ | ||||
'external_email' => $invitation->email, | 'external_email' => $invitation->email, | ||||
'first_name' => $request->first_name, | 'first_name' => $request->first_name, | ||||
'last_name' => $request->last_name, | 'last_name' => $request->last_name, | ||||
]; | ]; | ||||
} else { | } else { | ||||
// Validate verification codes (again) | // Validate verification codes (again) | ||||
$v = $this->verify($request); | $v = $this->verify($request, false); | ||||
if ($v->status() !== 200) { | if ($v->status() !== 200) { | ||||
return $v; | return $v; | ||||
} | } | ||||
// Get user name/email from the verification code database | // Get user name/email from the verification code database | ||||
$code_data = $v->getData(); | $code_data = $v->getData(); | ||||
$settings = [ | $settings = [ | ||||
▲ Show 20 Lines • Show All 66 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 | // Soft-delete the verification code, and store some more info with it | ||||
if ($request->code) { | if ($request->code) { | ||||
$request->code->delete(); | $request->code->user_id = $user->id; | ||||
$request->code->submit_ip_address = $request->ip(); | |||||
$request->code->deleted_at = \now(); | |||||
$request->code->timestamps = false; | |||||
$request->code->save(); | |||||
} | } | ||||
DB::commit(); | DB::commit(); | ||||
return AuthController::logonResponse($user, $request->password); | return AuthController::logonResponse($user, $request->password); | ||||
} | } | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 79 Lines • Show Last 20 Lines |