Exemplo n.º 1
0
 /**
  * @param $profiles
  * @param $accessToken
  * @return mixed
  */
 public function createUserFromGoogleProfile($profiles, $accessToken)
 {
     $userService = new userService();
     $emailService = new mailService();
     $result['ok'] = 0;
     if (!$profiles) {
         $result['error_code'] = KACANA_AUTH_SIGNUP_BAD_GOOGLE_PROFILE;
         $result['error_message'] = 'google profile is empty';
         return $result;
     }
     if (!$profiles->email) {
         $result['error_code'] = KACANA_AUTH_SIGNUP_BAD_GOOGLE_EMAIL;
         $result['error_message'] = 'google email is empty';
         return $result;
     }
     if (!isset($profiles->name)) {
         $result['error_code'] = KACANA_AUTH_SIGNUP_BAD_GOOGLE_NAME;
         $result['error_message'] = 'google first name is empty';
         return $result;
     }
     if (!isset($profiles->phone)) {
         $profiles->phone = '';
     }
     $data = array('password' => Hash::make(md5(time())), 'email' => $profiles->email, 'name' => $profiles->name, 'role' => KACANA_USER_ROLE_BUYER, 'status' => KACANA_USER_STATUS_ACTIVE, 'phone' => $profiles->phone, 'image' => $profiles->picture);
     $user = $this->getUserByEmail($profiles['email']);
     if ($user) {
         $user = $this->updateItem($user->id, ['status' => KACANA_USER_STATUS_ACTIVE, 'image' => $data['image']]);
     } else {
         $user = $this->createUser($data);
         $emailService->sendEmailNewUser($profiles->email);
     }
     $userSocial = $this->_userSocial->getItem($user->id, KACANA_SOCIAL_TYPE_GOOGLE);
     if ($userSocial) {
         $userSocial = $this->_userSocial->updateItem($user->id, KACANA_SOCIAL_TYPE_GOOGLE, ['token' => $accessToken]);
     } else {
         $userSocial = $this->_userSocial->createItem($user->id, KACANA_SOCIAL_TYPE_GOOGLE, $accessToken, $profiles->id);
     }
     if (Auth::loginUsingId($user->id, true)) {
         $result['ok'] = 1;
         $result['user'] = $user;
         $result['userSocial'] = $userSocial;
     } else {
         $result['error_code'] = KACANA_AUTH_LOGIN_FAILED;
         $result['error_message'] = 'login failed';
     }
     return $result;
 }
Exemplo n.º 2
0
 public function postProductToFacebook($productId, $descPost, $images, $userId)
 {
     $productModel = new productModel();
     $userSocialModel = new userSocialModel();
     $util = new Util();
     $socialAccount = $userSocialModel->getItem($userId, KACANA_SOCIAL_TYPE_FACEBOOK);
     $facebook = $util->initFacebook();
     $facebook->setDefaultAccessToken($socialAccount->token);
     $product = $productModel->getProductById($productId);
     if (!$product) {
         throw new \Exception('BAD Product ID');
     }
     $galleries = $product->galleries;
     $arrayFbMedia = [];
     foreach ($galleries as $gallery) {
         if (in_array($gallery->id, $images)) {
             array_push($arrayFbMedia, $facebook->postPhoto('http:' . AWS_CDN_URL . str_replace(' ', '%20', $gallery->getOriginal('image')), $product->name));
         }
     }
     return $facebook->postFeed($arrayFbMedia, $descPost);
 }