validate([ 'username' => 'required|string|max:16|unique:users', 'email' => 'required|string|email|max:255|unique:users', 'password' => ['required', 'confirmed', Rules\Password::defaults()] ]); $user = User::create([ 'username' => $request->username, 'email' => $request->email, 'password' => Hash::make($request->password), 'ip_address' => $request->ip() ]); /* Add account into Fider (https://myvideogamelist.com). */ $json = '{"name": "' . $request->username . '", "email": "' . $request->email . '"}'; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://features.myvideogamelist.com/api/v1/users", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => $json, CURLOPT_HTTPHEADER => array( "Content-Type: application/json", "Authorization: Bearer $TOKEN" ), )); curl_exec($curl); curl_close($curl); event(new Registered($user)); Auth::login($user); return redirect(RouteServiceProvider::HOME); } /** * Handle an incoming api registration request. * * @param \Illuminate\Http\Request $request * * @return \Illuminate\Http\Response * * @throws \Illuminate\Validation\ValidationException */ public function apiStore(Request $request) { $request->validate([ 'username' => 'required|string|max:16|unique:users', 'email' => 'required|string|email|max:255|unique:users', 'password' => ['required', 'confirmed', Rules\Password::defaults()], ]); $token = Str::random(60); $user = User::create([ 'username' => $request->username, 'email' => $request->email, 'password' => Hash::make($request->password), 'api_token' => hash('sha256', $token), 'ip_address' => $request->ip() ]); /* Add account into Fider (https://myvideogamelist.com). */ $json = '{"name": "' . $request->username . '", "email": "' . $request->email . '"}'; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://features.myvideogamelist.com/api/v1/users", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => $json, CURLOPT_HTTPHEADER => array( "Content-Type: application/json", "Authorization: Bearer $TOKEN" ), )); curl_exec($curl); curl_close($curl); return response($user); } }