Changeset View
Changeset View
Standalone View
Standalone View
src/app/Http/Controllers/API/SignupController.php
Show First 20 Lines • Show All 205 Lines • ▼ Show 20 Lines | public function signup(Request $request) | ||||
return response()->json(['status' => 'error', 'errors' => $errors], 422); | return response()->json(['status' => 'error', 'errors' => $errors], 422); | ||||
} | } | ||||
} | } | ||||
// Get the plan | // Get the plan | ||||
$plan = $this->getPlan(); | $plan = $this->getPlan(); | ||||
$is_domain = $plan->hasDomain(); | $is_domain = $plan->hasDomain(); | ||||
$login = $request->login; | $login = $request->login; | ||||
$domain = $request->domain; | $domain_name = $request->domain; | ||||
// Validate login | // Validate login | ||||
if ($errors = self::validateLogin($login, $domain, $is_domain)) { | if ($errors = self::validateLogin($login, $domain_name, $is_domain)) { | ||||
return response()->json(['status' => 'error', 'errors' => $errors], 422); | return response()->json(['status' => 'error', 'errors' => $errors], 422); | ||||
} | } | ||||
// 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(); | ||||
$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 = Str::lower($domain); | $domain_name = Str::lower($domain_name); | ||||
$domain = null; | |||||
DB::beginTransaction(); | DB::beginTransaction(); | ||||
// Create user record | |||||
$user = User::create([ | |||||
'email' => $login . '@' . $domain, | |||||
'password' => $request->password, | |||||
]); | |||||
// Create domain record | // Create domain record | ||||
// FIXME: Should we do this in UserObserver::created()? | |||||
if ($is_domain) { | if ($is_domain) { | ||||
$domain = Domain::create([ | $domain = Domain::create([ | ||||
'namespace' => $domain, | 'namespace' => $domain_name, | ||||
'status' => Domain::STATUS_NEW, | 'status' => Domain::STATUS_NEW, | ||||
'type' => Domain::TYPE_EXTERNAL, | 'type' => Domain::TYPE_EXTERNAL, | ||||
]); | ]); | ||||
} | } | ||||
// Create user record | |||||
$user = User::create([ | |||||
'email' => $login . '@' . $domain_name, | |||||
'password' => $request->password, | |||||
]); | |||||
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); | ||||
▲ Show 20 Lines • Show All 125 Lines • Show Last 20 Lines |