Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Http\Controllers\Auth;
- use App\User;
- use App\Mail\Welcome;
- use App\Http\Controllers\Controller;
- use Illuminate\Support\Facades\Hash;
- use Illuminate\Support\Facades\Validator;
- use Illuminate\Foundation\Auth\RegistersUsers;
- use GuzzleHttp\Exception\GuzzleException;
- use GuzzleHttp\Client;
- use Curl;
- class RegisterController extends Controller
- {
- /*
- |--------------------------------------------------------------------------
- | Register Controller
- |--------------------------------------------------------------------------
- |
- | This controller handles the registration of new users as well as their
- | validation and creation. By default this controller uses a trait to
- | provide this functionality without requiring any additional code.
- |
- */
- use RegistersUsers;
- /**
- * Where to redirect users after registration.
- *
- * @var string
- */
- protected $redirectTo = '/';
- /**
- * Create a new controller instance.
- *
- * @return void
- */
- public function __construct()
- {
- $this->middleware('guest');
- }
- /**
- * Get a validator for an incoming registration request.
- *
- * @param array $data
- * @return \Illuminate\Contracts\Validation\Validator
- */
- protected function validator(array $data)
- {
- return Validator::make($data, [
- 'company_name' => 'string|max:255|nullable',
- 'first_name' => 'required|string|max:255',
- 'last_name' => 'required|string|max:255',
- 'userType' => 'required|string|max:255',
- 'email' => 'required|string|email|max:255|unique:users',
- 'password' => 'required|string|min:6|confirmed',
- 'zipcode' => 'required|numeric|min:5',
- ]);
- }
- /**
- * Create a new user instance after a valid registration.
- *
- * @param array $data
- * @return \App\User
- */
- protected function create(array $data)
- {
- $DropZone_ID = -1;
- $companyName = null;
- if ($data['userType'] === '0'){
- $companyName = $data['company_name'];
- $DropZone_ID = 0;
- }
- if ($data['userType'] === '1'){
- $companyName = $data['first_name'] . " " . $data['last_name'];
- $DropZone_ID = 0;
- }
- if( $data['USPA'] == "0") {
- // send API request to sig.ma
- // Generated by curl-to-PHP: http://incarnate.github.io/curl-to-php/
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, 'https://qwebhjklr-api.sig.ma/v2/orgs/5c533fd2301f140006fe97e4/access');
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_USERPWD, '5c549bdabbea8b00064c0974' . ':' . '1bK38mYQpTK8nlOl22oh3YGUrpv8o5yc');
- $result = curl_exec($ch);
- if (curl_errno($ch)) {
- echo 'Error:' . curl_error($ch);
- }
- curl_close ($ch);
- // here i need to get the result and place it in another curl request
- /* will be formated like this -> 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHBMaW5rSWQiOiI1YzU0OWJkYmJiZWE4YjAwMDY0YzA5NzUiLCJleHAiOiIyMDE5LTAyLTI4VDAxOjAyOjQxLjY1MVoiLCJ0eXBlIjoiQXBwTGlua0FjY2VzcyJ9.rstTlBKRBeLoI_BZD9-dSxKo6pKUKEVl7hveFON4dI4'
- */
- // need to put the result in $authCode = $result
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, 'https://qwebhjklr-api.sig.ma/v2/merits');
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, "{ \"meritTemplateId\": \"5c6702c7775c03000929d486\", \"recipientEmail\": \"jodymoorellc@icloud.com\", \"fieldValues\": [{ \"fieldId\": \"5bb67ec4d264cd253bddeb2e\", \"value\": { \"firstName\": \"Omer\", \"lastName\": \"Zach\" }}] }");
- curl_setopt($ch, CURLOPT_POST, 1);
- $headers = array();
- $headers[] = $authCode ;
- $headers[] = 'Content-Type: application/json';
- curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
- $result = curl_exec($ch);
- if (curl_errno($ch)) {
- echo 'Error:' . curl_error($ch);
- }
- curl_close ($ch);
- \Mail::to($data['email'])->send(new Welcome);
- return User::create([
- 'company_name' => $companyName,
- 'first_name' => $data['first_name'],
- 'last_name' => $data['last_name'],
- 'type' => intval($data['userType']),
- 'DropZone_ID' => $DropZone_ID,
- 'email' => $data['email'],
- 'password' => bcrypt($data['password']),
- 'zipcode' => $data['zipcode'],
- ]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement