Example #1
0
 public function keygen()
 {
     //init variable
     $obj = new stdclass();
     $umodel = new JUser();
     $user = $umodel->getInstance();
     if (!$user->id) {
         $user = JFactory::getUser($this->plugin->get('user')->id);
     }
     $kmodel = new ApiModelKey();
     $model = new ApiModelKeys();
     $key = null;
     // Get login user hash
     $kmodel->setState('user_id', $user->id);
     $log_hash = $kmodel->getList();
     $log_hash = $log_hash[count($log_hash) - count($log_hash)];
     if ($log_hash->hash) {
         $key = $log_hash->hash;
     } elseif ($key == null || empty($key)) {
         // Create new key for user
         $data = array('userid' => $user->id, 'domain' => '', 'state' => 1, 'id' => '', 'task' => 'save', 'c' => 'key', 'ret' => 'index.php?option=com_api&view=keys', 'option' => 'com_api', JSession::getFormToken() => 1);
         $result = $kmodel->save($data);
         $key = $result->hash;
         //add new key in easysocial table
         $easyblog = JPATH_ROOT . '/administrator/components/com_easyblog/easyblog.php';
         if (JFile::exists($easyblog) && JComponentHelper::isEnabled('com_easysocial', true)) {
             $this->updateEauth($user, $key);
         }
     }
     if (!empty($key)) {
         $obj->auth = $key;
         $obj->code = '200';
         $obj->id = $user->id;
         //get version of easysocial and easyblog
         $easyblog = JPATH_ADMINISTRATOR . '/components/com_easyblog/easyblog.php';
         $easysocial = JPATH_ADMINISTRATOR . '/components/com_easysocial/easysocial.php';
         //eb version
         if (JFile::exists($easyblog)) {
             $obj->easyblog = $this->getCompParams('com_easyblog', 'easyblog');
         }
         //es version
         if (JFile::exists($easysocial)) {
             /*$xml = JFactory::getXML(JPATH_ADMINISTRATOR .'/components/com_easysocial/easyblog.xml');
             		$obj->easysocial_version = (string)$xml->version;*/
             $obj->easysocial = $this->getCompParams('com_easysocial', 'easysocial');
         }
         //
     } else {
         $obj->code = 403;
         $obj->message = 'Bad request';
     }
     return $obj;
 }
Example #2
0
 public function keygen()
 {
     $app = JFactory::getApplication();
     $user_details = 0;
     //code for social login
     $slogin = $app->input->get('social_login', 0, 'INT');
     if ($slogin) {
         //$provider = $app->input->get('provider', 'facebook' , 'STRING');
         $user_id = $app->input->get('user_id', 0, 'INT');
         $tokan = $app->input->get('tokan', 0, 'STRING');
         $username = $app->input->get('username', '', 'STRING');
         $name = $app->input->get('name', '', 'STRING');
         $email_crp = $app->input->get('email', '', 'STRING');
         //$crpt = base64_encode($email_crp.$tokan);
         $email_crp = base64_decode($email_crp);
         $email = str_replace($tokan, '', $email_crp);
         $reg_usr = 0;
         if ($email) {
             $reg_usr = $this->check_user($email);
             //print_r( $_POST );
             //var_dump( $reg_usr );
             //die("in slogin api");
             if ($reg_usr == null) {
                 $user_details = $this->createUser($username, $name, $email);
                 $reg_usr = $user_details['user_id'];
             }
         }
         $user = JFactory::getUser($reg_usr);
     } else {
         //init variable
         $obj = new stdclass();
         $umodel = new JUser();
         $user = $umodel->getInstance();
         if (!$user->id) {
             $user = JFactory::getUser($this->plugin->get('user')->id);
         }
     }
     if (!$user->id) {
         $obj->code = 403;
         $obj->message = 'Invalid User';
         return $obj;
     }
     $kmodel = new ApiModelKey();
     $model = new ApiModelKeys();
     $key = null;
     // Get login user hash
     $kmodel->setState('user_id', $user->id);
     $log_hash = $kmodel->getList();
     $log_hash = $log_hash[count($log_hash) - count($log_hash)];
     if ($log_hash->hash) {
         $key = $log_hash->hash;
     } elseif ($key == null || empty($key)) {
         // Create new key for user
         $data = array('userid' => $user->id, 'domain' => '', 'state' => 1, 'id' => '', 'task' => 'save', 'c' => 'key', 'ret' => 'index.php?option=com_api&view=keys', 'option' => 'com_api', JSession::getFormToken() => 1);
         $result = $kmodel->save($data);
         $key = $result->hash;
         //add new key in easysocial table
         $easyblog = JPATH_ROOT . '/administrator/components/com_easyblog/easyblog.php';
         if (JFile::exists($easyblog) && JComponentHelper::isEnabled('com_easysocial', true)) {
             $this->updateEauth($user, $key);
         }
     }
     if (!empty($key)) {
         $obj->auth = $key;
         $obj->code = '200';
         $obj->id = $user->id;
     } else {
         $obj->code = 403;
         $obj->message = 'Bad request';
     }
     return $obj;
 }