Changeset View
Changeset View
Standalone View
Standalone View
src/app/Http/Controllers/API/SignupController.php
Show First 20 Lines • Show All 222 Lines • ▼ Show 20 Lines | public function signup(Request $request) | ||||
$code_data = $v->getData(); | $code_data = $v->getData(); | ||||
$user_email = $code_data->email; | $user_email = $code_data->email; | ||||
// We allow only ASCII, so we can safely lower-case the email address | // We allow only ASCII, so we can safely lower-case the email address | ||||
$login = Str::lower($login); | $login = Str::lower($login); | ||||
$domain_name = Str::lower($domain_name); | $domain_name = Str::lower($domain_name); | ||||
$domain = null; | $domain = null; | ||||
// Are we using the signup with approval process? | |||||
$withApproval = \config('app.signup_approval'); | |||||
DB::beginTransaction(); | DB::beginTransaction(); | ||||
// Create domain record | // Create domain record | ||||
if ($is_domain) { | if ($is_domain) { | ||||
$domain = Domain::create([ | $domain = Domain::create([ | ||||
'namespace' => $domain_name, | 'namespace' => $domain_name, | ||||
'status' => Domain::STATUS_NEW, | 'status' => Domain::STATUS_NEW, | ||||
'type' => Domain::TYPE_EXTERNAL, | 'type' => Domain::TYPE_EXTERNAL, | ||||
]); | ]); | ||||
} | } | ||||
// Create user record | // Create user record | ||||
$user = User::create([ | $user = User::create([ | ||||
'email' => $login . '@' . $domain_name, | 'email' => $login . '@' . $domain_name, | ||||
'password' => $request->password, | 'password' => $request->password, | ||||
'status' => $withApproval ? User::STATUS_DRAFT : 0, | |||||
]); | ]); | ||||
if (!empty($discount)) { | if (!empty($discount)) { | ||||
$wallet = $user->wallets()->first(); | $wallet = $user->wallets()->first(); | ||||
$wallet->discount()->associate($discount); | $wallet->discount()->associate($discount); | ||||
$wallet->save(); | $wallet->save(); | ||||
} | } | ||||
$user->assignPlan($plan, $domain); | $user->assignPlan($plan, $domain); | ||||
// Save the external email and plan in user settings | // Save the external email and plan in user settings | ||||
$user->setSettings([ | $user->setSettings([ | ||||
'external_email' => $user_email, | 'external_email' => $user_email, | ||||
'first_name' => $code_data->first_name, | 'first_name' => $code_data->first_name, | ||||
'last_name' => $code_data->last_name, | 'last_name' => $code_data->last_name, | ||||
]); | ]); | ||||
// Remove the verification code | // Remove the verification code | ||||
$this->code->delete(); | $this->code->delete(); | ||||
DB::commit(); | DB::commit(); | ||||
if ($withApproval) { | |||||
return response()->json(['status' => 'success']); | |||||
} | |||||
return AuthController::logonResponse($user); | return AuthController::logonResponse($user); | ||||
} | } | ||||
/** | /** | ||||
* 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 | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 105 Lines • Show Last 20 Lines |