No ideas on how to do this...?
Feb 8, 2017
6
Level 1
How to Register/Create a User Programmatically?
Hi. I need to register/create a User programmatically, without going through the normal, interactive, form-based registration process.
I thought about mimicking what's in the register() method in the RegisterController:
public function register(RegisterRequest $request)
{
Auth::login($user = Spark::interact(
Register::class, [$request]
));
event(new UserRegistered($user));
return response()->json([
'redirect' => $this->redirectPath()
]);
}
but I don't know how to mimic the $request argument to Spark::interact().
So then I thought about trying to mimic the registration form post request to the RegisterController@register() method thus:
public function register_user()
{
$data = [
'stripe_token' => '',
'plan' => '',
'team' => '',
'team_slug' => '',
'name' => 'Joe User',
'email' => '[email protected]',
'password' => 'j0eybaby',
'password_confirmation' => 'j0eybaby',
'address' => '',
'address_line_2' => '',
'city' => '',
'state' => '',
'zip' => '',
'country' => 'US',
'vat_id' => '',
'terms' => true,
'coupon' => null,
'invitation' => null,
'errors' => array('errors' => (object) array()),
'busy' => true,
'successful' => false,
];
$client = new GuzzleHttp\Client([
'headers' =>
[
'Content-Type' => 'application/json;charset=UTF-8',
'X-Csrf-Token' => csrf_token(),
'X-Requested-With' => 'XMLHttpRequest',
]
]);
// issue http post request that mimics registration form post request...
$client->post('https://www.mysite.com/register', [ 'body' => json_encode($data) ]);
}
but that gives me a 500 Internal Server error - not sure why, maybe I'm not sending some cookies that I need to send...
Is there any way to do what I'm trying to do?
Thanks.
Please or to participate in this conversation.