Exemple #1
0
 public function save($params)
 {
     $data = $params['data'];
     $authAdapter = new OW_RemoteAuthAdapter($data['facebookId'], 'facebook');
     $nonQuestions = array('name', 'email', 'avatarUrl');
     $nonQuestionsValue = array();
     foreach ($nonQuestions as $name) {
         $nonQuestionsValue[$name] = empty($data[$name]) ? null : $data[$name];
         unset($data[$name]);
     }
     $data['realname'] = $nonQuestionsValue['name'];
     $email = $nonQuestionsValue['email'];
     $password = uniqid();
     $user = BOL_UserService::getInstance()->findByEmail($email);
     $newUser = false;
     if ($user === null) {
         $newUser = true;
         $username = $this->makeUsername($nonQuestionsValue['name']);
         $user = BOL_UserService::getInstance()->createUser($username, $password, $email, null, true);
     }
     BOL_QuestionService::getInstance()->saveQuestionsData(array_filter($data), $user->id);
     if (!empty($nonQuestionsValue['avatarUrl'])) {
         $avatarUrl = $nonQuestionsValue['avatarUrl'];
         $pluginfilesDir = OW::getPluginManager()->getPlugin('skadateios')->getPluginFilesDir();
         $ext = UTIL_File::getExtension($avatarUrl);
         $tmpFile = $pluginfilesDir . uniqid('avatar-') . (empty($ext) ? '' : '.' . $ext);
         copy($avatarUrl, $tmpFile);
         BOL_AvatarService::getInstance()->setUserAvatar($user->id, $tmpFile);
         @unlink($tmpFile);
     }
     if (!$authAdapter->isRegistered()) {
         $authAdapter->register($user->id);
     }
     if ($newUser) {
         $event = new OW_Event(OW_EventManager::ON_USER_REGISTER, array('method' => 'facebook', 'userId' => $user->id, 'params' => array()));
         OW::getEventManager()->trigger($event);
     }
     OW::getUser()->login($user->id);
     $this->assign('success', true);
     $this->respondUserData($user->id);
 }
Exemple #2
0
 public function __construct($remoteId, $type)
 {
     parent::__construct($remoteId, $type);
 }
 public function facebooklogin(array $params)
 {
     $data = $_POST;
     $facebookId = (int) $data['facebookid'];
     $email = (int) $data['email'];
     $authAdapter = new OW_RemoteAuthAdapter($facebookId, 'facebook');
     //        $nonQuestions = array('name', 'email', 'avatarUrl');
     //        $nonQuestionsValue = array();
     //        foreach ( $nonQuestions as $name )
     //        {
     //            $nonQuestionsValue[$name] = empty($data[$name]) ? null : $data[$name];
     //            unset($data[$name]);
     //        }
     //
     //        $data['realname'] = $nonQuestionsValue['name'];
     $email = trim($data['email']);
     $this->checkfacebookuserexists($data);
     $password = uniqid();
     $tmpUsername = explode('@', $email);
     $username = $tmpUsername[0];
     $username = trim(preg_replace('/[^\\w]/', '', $username));
     $username = $this->makeUsername($username);
     $newUser = false;
     $data['realname'] = $username;
     $accountype = (int) $data["sex"];
     //(1 = Female, 2 = Male)
     $data["sex"] = (int) $data["sex"];
     $UserDob = date("Y/m/d", strtotime($data["birthdate"]));
     $data["birthdate"] = $UserDob;
     try {
         $user = BOL_UserService::getInstance()->createUser($username, $password, $email, $accountype, true);
         $newUser = true;
     } catch (LogicException $ex) {
         $userdata = array("status" => "false", "message" => "unsuccess", "error" => $ex->getCode());
         echo json_encode($userdata);
         exit;
     }
     //        if (!empty($data['custom_location'])) {
     //            $data['googlemap_location'] = json_decode($data['custom_location'], true);
     //            $data['googlemap_location']['json'] = $data['custom_location'];
     //            unset($data['custom_location']);
     //        }
     if (!empty($data["address"])) {
         $urlencode_address = urlencode($data["address"]);
         $geocode = file_get_contents('http://maps.google.com/maps/api/geocode/json?address=' . $urlencode_address . '&sensor=false');
         $output = json_decode($geocode);
         //echo print_r(json_encode($output->results));
         if (!empty($output->results[0]->formatted_address)) {
             $data['googlemap_location']['address'] = $output->results[0]->formatted_address;
             $data['googlemap_location']['latitude'] = $output->results[0]->geometry->location->lat;
             $data['googlemap_location']['longitude'] = $output->results[0]->geometry->location->lng;
             $data['googlemap_location']['northEastLat'] = $output->results[0]->geometry->bounds->northeast->lat;
             $data['googlemap_location']['northEastLng'] = $output->results[0]->geometry->bounds->northeast->lng;
             $data['googlemap_location']['southWestLat'] = $output->results[0]->geometry->bounds->southwest->lat;
             $data['googlemap_location']['southWestLng'] = $output->results[0]->geometry->bounds->southwest->lng;
             $data['googlemap_location']['json'] = json_encode($output->results[0]);
         }
     }
     //        echo "got here";
     BOL_QuestionService::getInstance()->saveQuestionsData(array_filter($data), $user->id);
     //        echo "suceees";
     //        die;
     $avatarUrl = 'http://graph.facebook.com/' . $facebookId . '/picture?type=large&height=400&width=400';
     $pluginfilesDir = OW::getPluginManager()->getPlugin('skapi')->getPluginFilesDir();
     $ext = 'jpg';
     $tmpFile = $pluginfilesDir . uniqid('avatar-') . (empty($ext) ? '' : '.' . $ext);
     @copy($avatarUrl, $tmpFile);
     if (file_exists($tmpFile)) {
         BOL_AvatarService::getInstance()->setUserAvatar($user->id, $tmpFile);
         @unlink($tmpFile);
     }
     if (!$authAdapter->isRegistered()) {
         $authAdapter->register($user->id);
     }
     if ($newUser) {
         $event = new OW_Event(OW_EventManager::ON_USER_REGISTER, array('method' => 'facebook', 'userId' => $user->id, 'params' => array()));
         OW::getEventManager()->trigger($event);
     }
     $userdata = $this->respondUserData($user->id);
     echo json_encode($userdata);
     exit;
     //$this->assign('success', true);
 }
Exemple #4
0
 public function __construct($remoteId)
 {
     parent::__construct($remoteId, 'facebook');
 }