pimplesushant-pere

socialSignUp()

Apr 24th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     public function socialSignUp()
  2.     {
  3.         try{
  4.  
  5.             $validator = \Illuminate\Support\Facades\Validator::make(request()->request->all(), [
  6.                 Col::EMAIL => 'required|string|email',
  7.                 Col::SOCIAL_TYPE => 'required|string',
  8.                 Col::SOCIAL_ID=> 'required|string',
  9.                 Col::SOCIAL_TOKEN => 'required|string',
  10.                 Col::MOBILE => 'required'
  11.             ]);
  12.            
  13.             if ($validator->fails()) {
  14.                 return $this->respondWithError($validator->errors(), 422);
  15.             }
  16.            
  17.             $social_id = request()->request->get('social_id');
  18.             $password = bcrypt($social_id);
  19.             request()->request->add(['password' => $password]);
  20.  
  21.             if (request()->request->get('social_type') == 'gmail') {
  22.                 request()->request->add(['email_verified' => 1]);
  23.             }
  24.            
  25.             /*if (request()->request->has('referral_code') && request()->request->get('referral_code') != '') {
  26.                 request()->request->add(['original_referral_code' => request()->request->get('referral_code')]);
  27.                 $existing_patient_obj = User::where(['referral_code' => request()->request->get('referral_code')])->first();
  28.                 if (null == $existing_patient_obj || '' == $existing_patient_obj || empty($existing_patient_obj)) {
  29.                     return $this->respondWithError("Please enter valid referral code", 422);
  30.                 }
  31.                 request()->request->add(['referred_by' => $existing_patient_obj->id]);
  32.             }
  33.  
  34.             if (request()->request->has('profile_image') && request()->request->get('profile_image') != '') {
  35.                 $profile_image = $this->saveProfileImage(request()->request->get('profile_image'));
  36.                 request()->request->add(['profile_image' => $profile_image]);
  37.             }
  38.  
  39.             $stripeCustomerId = $this->createCustomer(request()->request->get('email'));
  40.             request()->request->add(['stripe_customer_id' => $stripeCustomerId['id']]);
  41.  
  42.             $referral_code = $this->generateReferralCode();
  43.  
  44.             request()->request->add(['role' => 'P', 'referral_code' => $referral_code]);
  45.             request()->request->add(['is_active' => 1]);
  46.            
  47.             $result = parent::store();
  48.  
  49.             $response = json_decode($result->getContent());
  50.  
  51.             if ($result->getStatusCode() == 201) {
  52.                 DB::commit();
  53.                 return $this->respondWithSuccess(null, "Registration successful", $result->getStatusCode());
  54.             }
  55.             return $this->respondWithError(json_decode($response->getContent()), $result->getStatusCode());
  56.            
  57.  
  58.             if (request()->request->has('original_referral_code') && request()->request->get('original_referral_code') != '') {
  59.                 //get referred_by using referral_code
  60.                 $referral_code = request()->request->get('original_referral_code');
  61.                 $existing_patient_obj = User::where(['referral_code' => $referral_code])->first();
  62.  
  63.                 $max_refer_count = Reward::select('rewards.* ')
  64.                     ->where('user_id', $existing_patient_obj->id)
  65.                     ->groupBy('rewards.user_id')
  66.                     ->count();
  67.  
  68.                 if ($max_refer_count < Config::get('constants.MAX_REFER_REWARD_COUNT')) {
  69.  
  70.                     $reward_obj = new Reward();
  71.                     $reward_obj->type = "referral";
  72.                     $reward_obj->user_id = $existing_patient_obj->id;
  73.                     $reward_obj->referral_email = request()->request->get('email');
  74.                     $reward_obj->reward_points = Config::get('constants.REWARD_POINTS.REFERRAL');
  75.                     $reward_obj->save();
  76.                 }
  77.             }*/
  78.  
  79.             $response = json_decode($result->getContent());
  80.  
  81.             if ($result->getStatusCode() == 201 || $result->getStatusCode() == 200) {
  82.                 DB::commit();
  83.                 return $this->respondWithSuccess(null, "Registration successful", $result->getStatusCode());
  84.             }
  85.             DB::rollBack();
  86.             return $this->respondWithError(json_decode($response->getContent()), $result->getStatusCode());
  87.         } catch (\Exception $ex) {
  88.             Log::info(exceptionMessage($ex->getMessage(), $ex->getLine()));
  89.             return $this->respondWithError("Social Signup Failed", 500);
  90.         }
  91.     }
Add Comment
Please, Sign In to add comment