/** * Submit handler for registration */ public function onRegisterSubmit() { $data = post(); AuthManager::register($data); /* * Redirect to the intended page after successful sign in */ $redirectUrl = $this->pageUrl($this->property('redirect')); if ($redirectUrl = post('redirect', $redirectUrl)) { return Redirect::intended($redirectUrl); } }
/** * * @SWG\Definition( * definition="request.user", * type="object", * required={"email", "password", "password_confirm"}, * @SWG\Property( * property="first_name", * type="string" * ), * @SWG\Property( * property="last_name", * type="string" * ), * @SWG\Property( * property="email", * type="string" * ), * @SWG\Property( * property="email_optin", * type="boolean" * ), * @SWG\Property( * property="password", * type="string" * ), * @SWG\Property( * property="password_confirmation", * type="string" * ), * @SWG\Property( * property="address", * type="string" * ), * @SWG\Property( * description="State id. Get state using users/profile-options/states", * property="state", * type="integer", * format="int32" * ), * @SWG\Property( * property="zip", * type="string" * ), * @SWG\Property( * property="phone", * type="string" * ), * @SWG\Property( * property="birthday_year", * type="string" * ), * @SWG\Property( * property="birthday_month", * type="string" * ), * @SWG\Property( * property="birthday_day", * type="string" * ), * @SWG\Property( * description="Get an update list from endpoint users/profile-options/gender", * property="gender", * type="string", * enum={"Male", "Female", "Non Binary/Other"} * ), * @SWG\Property( * description="Get an update list from endpoint users/profile-options/race", * property="race", * type="string", * enum={"White", "Hispanic", "Black or African American", "American Indian or Alaska Native", "Asian", "Native Hawaiian or Other Pacific Islander", "Two or more races", "Other"} * ), * @SWG\Property( * description="Get an update list from endpoint users/profile-options/household_income", * property="household_income", * type="string", * enum={"Less then $25,000", "$25,000 - $50,000", "$50,000 - $75,000", "$75,000 - $150,000", "$150,000 - $500,000", "$500,000 or more"} * ), * @SWG\Property( * description="Get an update list from endpoint users/profile-options/education", * property="education", * type="string", * enum={"K-12", "High School/GED", "Some College", "Vocational or Trade School", "Bachelors Degree", "Masters Degree", "PhD"} * ) * ) * * @SWG\Post( * path="users", * description="Register a new user", * summary="Register a new user", * tags={ "user"}, * * @SWG\Parameter( * description="User payload", * name="body", * in="body", * required=true, * schema=@SWG\Schema(ref="#/definitions/request.user") * ), * @SWG\Response( * response=200, * description="Successful response", * @SWG\Schema(ref="#/definitions/user.extended") * ), * @SWG\Response( * response=500, * description="Unexpected error", * @SWG\Schema(ref="#/definitions/error500") * ) * ) */ public function store() { try { $data = Request::all(); // Rules $rules = ['first_name' => 'min:2', 'last_name' => 'min:2', 'birthday_year' => 'required_with:birthday_month,birthday_day|alpha_num|min:4', 'birthday_month' => 'required_with:birthday_year,birthday_day|alpha_num|min:2', 'birthday_day' => 'required_with:birthday_year,birthday_month|alpha_num|min:2']; // Reformat birthday data structure $bd_year = array_get($data, 'birthday_year', null); $bd_month = array_get($data, 'birthday_month', null); $bd_day = array_get($data, 'birthday_day', null); $data['birthday'] = ['year' => $bd_year, 'month' => $bd_month, 'day' => $bd_day]; // COMPLETE NEW USER DATA STRUCTURE // The API allows to register users with only email and password. // so it is necessary to complete the data structure with empty strings // when the data is not present. In that way the AuthManager don't complain // for missing fields. $defaultFields = ['first_name', 'last_name', 'phone', 'street_addr', 'city', 'state', 'zip']; foreach ($defaultFields as $field) { $data[$field] = array_get($data, $field, ''); } // Register new user $user = AuthManager::register($data, $rules); return $this->show($user->id); } catch (Exception $e) { if ($e instanceof ModelException) { return $this->errorDataValidation($e->getMessage()); } else { if ($e instanceof ValidationException) { return $this->errorDataValidation('User data fails to validated', $e->getErrors()); } else { // Lets the API resource deal with the exception throw $e; } } } }