Advertisement
Jodyone

Untitled

Mar 14th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.72 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Controllers\Auth;
  4.  
  5. use App\User;
  6. use App\Mail\Welcome;
  7. use App\Http\Controllers\Controller;
  8. use Illuminate\Support\Facades\Hash;
  9. use Illuminate\Support\Facades\Validator;
  10. use Illuminate\Foundation\Auth\RegistersUsers;
  11. use GuzzleHttp\Exception\GuzzleException;
  12. use GuzzleHttp\Client;
  13. use Curl;
  14.  
  15. class RegisterController extends Controller
  16. {
  17.     /*
  18.     |--------------------------------------------------------------------------
  19.     | Register Controller
  20.     |--------------------------------------------------------------------------
  21.     |
  22.     | This controller handles the registration of new users as well as their
  23.     | validation and creation. By default this controller uses a trait to
  24.     | provide this functionality without requiring any additional code.
  25.     |
  26.     */
  27.  
  28.     use RegistersUsers;
  29.  
  30.     /**
  31.      * Where to redirect users after registration.
  32.      *
  33.      * @var string
  34.      */
  35.     protected $redirectTo = '/';
  36.  
  37.     /**
  38.      * Create a new controller instance.
  39.      *
  40.      * @return void
  41.      */
  42.     public function __construct()
  43.     {
  44.         $this->middleware('guest');
  45.     }
  46.  
  47.     /**
  48.      * Get a validator for an incoming registration request.
  49.      *
  50.      * @param  array  $data
  51.      * @return \Illuminate\Contracts\Validation\Validator
  52.      */
  53.     protected function validator(array $data)
  54.     {
  55.         return Validator::make($data, [
  56.             'company_name' => 'string|max:255|nullable',
  57.             'first_name' => 'required|string|max:255',
  58.             'last_name' => 'required|string|max:255',
  59.             'userType' => 'required|string|max:255',
  60.             'email' => 'required|string|email|max:255|unique:users',
  61.             'password' => 'required|string|min:6|confirmed',
  62.             'zipcode' => 'required|numeric|min:5',
  63.         ]);
  64.  
  65.     }
  66.  
  67.     /**
  68.      * Create a new user instance after a valid registration.
  69.      *
  70.      * @param  array  $data
  71.      * @return \App\User
  72.      */
  73.     protected function create(array $data)
  74.     {
  75.        
  76.         $DropZone_ID = -1;
  77.         $companyName = null;
  78.  
  79.         if ($data['userType'] === '0'){
  80.             $companyName = $data['company_name'];
  81.             $DropZone_ID = 0;
  82.         }
  83.  
  84.         if ($data['userType'] === '1'){
  85.             $companyName = $data['first_name'] . " " . $data['last_name'];
  86.             $DropZone_ID = 0;
  87.         }
  88.        
  89.  
  90.         if( $data['USPA'] == "0") {
  91.             // send API request to sig.ma
  92.  
  93.  
  94.         // Generated by curl-to-PHP: http://incarnate.github.io/curl-to-php/
  95.         $ch = curl_init();
  96.  
  97.         curl_setopt($ch, CURLOPT_URL, 'https://qwebhjklr-api.sig.ma/v2/orgs/5c533fd2301f140006fe97e4/access');
  98.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  99.         curl_setopt($ch, CURLOPT_POST, 1);
  100.         curl_setopt($ch, CURLOPT_USERPWD, '5c549bdabbea8b00064c0974' . ':' . '1bK38mYQpTK8nlOl22oh3YGUrpv8o5yc');
  101.  
  102.         $result = curl_exec($ch);
  103.         if (curl_errno($ch)) {
  104.             echo 'Error:' . curl_error($ch);
  105.         }
  106.  
  107.          
  108.         curl_close ($ch);
  109.  
  110.    
  111. // here i need to get the result and place it in another curl request
  112. /* will be formated like this -> 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHBMaW5rSWQiOiI1YzU0OWJkYmJiZWE4YjAwMDY0YzA5NzUiLCJleHAiOiIyMDE5LTAyLTI4VDAxOjAyOjQxLjY1MVoiLCJ0eXBlIjoiQXBwTGlua0FjY2VzcyJ9.rstTlBKRBeLoI_BZD9-dSxKo6pKUKEVl7hveFON4dI4'
  113. */
  114. // need to put the result in $authCode = $result
  115.  
  116.       $ch = curl_init();
  117.  
  118.         curl_setopt($ch, CURLOPT_URL, 'https://qwebhjklr-api.sig.ma/v2/merits');
  119.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  120.         curl_setopt($ch, CURLOPT_POSTFIELDS, "{ \"meritTemplateId\": \"5c6702c7775c03000929d486\", \"recipientEmail\": \"jodymoorellc@icloud.com\", \"fieldValues\": [{ \"fieldId\": \"5bb67ec4d264cd253bddeb2e\", \"value\": { \"firstName\": \"Omer\", \"lastName\": \"Zach\" }}] }");
  121.         curl_setopt($ch, CURLOPT_POST, 1);
  122.  
  123.         $headers = array();
  124.         $headers[] = $authCode ;
  125.         $headers[] = 'Content-Type: application/json';
  126.         curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  127.  
  128.         $result = curl_exec($ch);
  129.         if (curl_errno($ch)) {
  130.             echo 'Error:' . curl_error($ch);
  131.         }
  132.         curl_close ($ch);
  133.  
  134.         \Mail::to($data['email'])->send(new Welcome);
  135.  
  136.         return User::create([
  137.             'company_name' =>  $companyName,
  138.             'first_name' => $data['first_name'],
  139.             'last_name' => $data['last_name'],
  140.             'type' => intval($data['userType']),
  141.             'DropZone_ID' => $DropZone_ID,
  142.             'email' => $data['email'],
  143.             'password' => bcrypt($data['password']),
  144.             'zipcode' => $data['zipcode'],
  145.         ]);
  146.     }
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement