Does anyone have any experience using this plugin? i've acquired the client library for php, and setup the appropriate functions in my controller. i get a valid response when i click "test" from the plugin settings page in vanilla, but now i'm stuck... where do i go from here?
to be more clear about the issue, i dont know what my next step is. What I mean is, I know I must be missing something... heres the controller function (or page) i'm using as the endpoint for the plugin :
// 1. Get your client ID and secret here.
$clientID = "1234";
$secret = "1234";
// 2. Grab the current user from your session management system or database here.
//so i check to see if the user is logged in to my codeigniter's auth
//all works fine
// 3. Fill in the user information in a way that Vanilla can understand.
$user = array();
if ($signedIn) {
// i then set these according to the user info of the logged in user
$user['uniqueid'] = '123';
$user['name'] = 'John PHP';
$user['email'] = 'john.php#anonymous.com';
$user['photourl'] = '';
}
// 4. Generate the jsConnect string.
$secure = true;
WriteJsConnect($user, $_GET, $clientID, $secret, $secure);
http://vanillaforums.org/docs/jsconnect is the docs site, which makes no mention of what to do past my current point.
I had to figure this out for myself as well, and did so finally last night. I have written up the files and put them into a github repo so that other people with CodeIgniter can enjoy the JsConnect features with their sites more easily. I really like it now that it is working!
You can download the code and just follow the readme here:
https://github.com/mandersondesign/JSConnect-Codeigniter
If there are any issues that you have, let me know and I will help you out!
Related
I need a way to store temporary data for anonymous users.
Apparently this is not possible with:
\Drupal::service('user.private_tempstore')
Unless you write a custom constructor for the session management and stuff, which seems a little far-fetched to me?
I tried using
\Drupal::service('user.shared_tempstore')
But that saves the temp data for all anonymous users. So it's not linked to a single user.
Using raw $_SESSION['data'] works fine, but I'm not sure if I'm supposed to be doing this in Drupal and how safe/unsafe it is to do this?
Sessions (Drupal 8) are used via the simple Session implementation of SessionInterface interface. See Complete Tutorial of Sessions (Drupal 8).
Example:
use Symfony\Component\HttpFoundation\Session\Session;
$session = new Session();
$session->start();
// set and get session attributes
$session->set('name', 'Yash');
$session->get('name');
// set flash messages
$session->getFlashBag()->add('notice', 'Profile updated');
// retrieve messages
foreach ($session->getFlashBag()->get('notice', array()) as $message) {
echo '<div class="flash-notice">'.$message.'</div>';
}
I am not answering your specific question (regarding $_SESSION) because I have successfully used:
$session = \Drupal::service('user.private_tempstore')->get('your_module');
$session->set('whatever', $whatever);
from within procedural code (i.e. hooks, themes) without problems.
Pay attention that this private tempstore has to be assigned to a module (for the lack of a better way of saying this) which is the purpose of this line
$session = \Drupal::service('user.private_tempstore')->get('your_module')
After you get the private tempostore you can now set and get the session values:
$session->get('whatever');
$session->set('whatever', $whatever);
EDIT
Sorry, you explained correctly. I didn't get the critical part 100% ;)
You can always access the Session object from the request.
$session = \Drupal::request()->getSession();
$session->set('whatever', 'hello');
$value = $session->get('whatever', 'default');
I've been using plain PHP $_SESSION variables for a while now.
Did some research on them and they should be perfectly safe to use.
They're working correctly everywhere I use them and they have been working correctly for a while.
Don't think there's any issue using them in Drupal 8.
I have a (currently working) plugin which creates a user on a third party system when a user registers. This is working fine so far.
I'm trying now to add a param to the user to store the third party id but this doesn't seem to be working:
function onUserAfterSave($user,$isNew,$success,$msg=''){
if(!$isNew || ! $success){
return;
}
jimport('joomla.log.log');
$res = someThirdPartyCall();
//Res is valid here
JLog::add("Res ".print_r($res,true), JLog::WARNING, 'jerror');
$userOb = JUser::getInstance($user['id']);
$userOb->setParam('sugarid', $res['id']);
//User ob is valid here
JLog::add("UserOb ".print_r($userOb,true), JLog::WARNING, 'jerror');
$saveRes = $userOb->save();
//Result is true. Error array is empty.
JLog::add("Result ".print_r($saveRes,true), JLog::WARNING, 'jerror');
JLog::add("Errors ".print_r($userOb->getErrors(),true), JLog::WARNING, 'jerror');
}
Everything looks great, no errors or the like. The only thing not working is that the params aren't set in the db. Is this because I'm trying to save the user in onUserAfterSave?
You have forgot to import the user library in to your plugin to use setParam. So At the beginning of your file do not forget to include user library. Use this line of code.
jimport( 'joomla.user.user' );
Hope this will help.
If save is finished you can't go back and add to it, the save is finished and door is shut. You need to do set things up when you set up the paramters by making a form plugin to add another field to the params. Then you don't need to save at all because params will just save as part of the normal process. I'm assuming this is not something that needs to be encrypted, right? It's just the user name?
Also I should mention that there is Juser::defParam($key, $value) that lets you add parameters via code.
I am trying to post a moments on my Googleplus Business Page though a PHP script.
To call the Google APIs I am using service accounts.
The following code give this error "Fatal error: Call to a member function insert() on a non-object in (last Line)".... could you help me to solve this prob?
require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_PlusService.php';
// Set your client id, service account name, and the path to your private key.
// For more information about obtaining these keys, visit:
// https://developers.google.com/console/help/#service_accountsconst CLIENT_ID = 'MYID';
const SERVICE_ACCOUNT_NAME = 'MYACCOUNT';
// Make sure you keep your key.p12 file in a secure location, and isn't
// readable by others.
const KEY_FILE = 'MYAUTHFILE';
// Load the key in PKCS 12 format (you need to download this from the
// Google API Console when the service account was created.
$client = new Google_Client();
$key = file_get_contents(KEY_FILE);
$client->setClientId(CLIENT_ID);
$client->setAssertionCredentials(new Google_AssertionCredentials(SERVICE_ACCOUNT_NAME,array('https://www.googleapis.com/auth/prediction'),$key));
// Create moment that does not have a URL.
$item_scope = new Google_ItemScope();
$item_scope->setId("MYGOOGLEPAGEID");
$item_scope->setType("http://schemas.google.com/AddActivity");
$item_scope->setName("The Google+ Platform");
$item_scope->setDescription("A page that describes just how awesome Google+ is!");
$item_scope->setImage("https://developers.google.com/+/plugins/snippet/examples/thing.png");
$moment_body = new Google_Moment();
$moment_body->setType("http://schemas.google.com/AddActivity");
$moment_body->setTarget($item_scope);
$momentResult = $plus->moments->insert('me', 'vault', $moment_body);
You can only write moments on behalf of an authenticated user when you use the https://www.googleapis.com/auth/plus.login scope. You can't use a service account to do this. More so you cannot authenticate as a Google+ Page so writing moments isn't possible in your scenario.
Do you think you might be able to edit your post to explain why you want to write moments on behalf of a Page? What is the goal that you are trying to achieve?
It seems you didn't initialize the Plus API Client:
$plus = new Google_PlusService($client);
You will also have to use the correct scope https://www.googleapis.com/auth/plus.login instead of https://www.googleapis.com/auth/prediction
And I'm not sure if writing moments will work with service accounts...
case:
When using kohana driven site from 2 different devices I randomly get both session data on each device. I'm using native sessions to store few objects, but they should be private on each device. What am I doing wrong?
for example:
public function load()
{
$session = Session::instance();
$this->dialog = $session->get('dialog');
}
public function save()
{
$session = Session::instance();
$session->set('dialog', $this->dialog);
}
it looks like some kind of caching problem. I tried to regenerate session id every time. I've got 1st id, then 2nd, then 3rd and when i clicked a link a got 1st id again.
Make sure caching is turned off in your bootstrap file. And the cookie variables are set correctly, especially the Cookie::$domain.
Also verify your session config file too. You can find more info here: http://kohanaframework.org/3.2/guide/kohana/sessions
I have a payment gateway integrated on my website. When user is done with payment he/she is redirected to a particular page say www.example.com/redirect. I want to prevent users from directly entering this url (www.example.com/redirect) in address bar and access the page. I want it asap.
Actually the page is protected from guest users but if logged in user types that url then it will redirect him to that page and hence the payment option will be skipped. I want the user must pay the amount first and then redirected to this page.
Hard to answer precisely since you only give a non-joomla url as an example, but at the top of every Joomla script is the following line:
defined('_JEXEC') or die( 'Restricted access' );
You obviously can't prevent a user from typing in the url, so this will at least detect if a session is already in place. If the user isn't in an active Joomla session, this will fire and prevent access. You could easily adapt it to do whatever you want to happen for your requirement, depending on whatever you have to check with, i.e. if the referrer is your payment gateway, etc.
I had a similar desire. I wanted the page to only display if the users was logged in and if they had filled out the order entry page.
What I decided to do was check to see if there was data in the POST.
controller/place_order.php (snipet)
public function submitOrder()
{
$post = JRequest::get('post');
$model = $this->getModel();
if($post != null && $post != ''){
if($model->placeOrder()){
}
}
JRequest::setVar('layout', 'submitOrder');
parent::display();
}
This prevents the task from executing my placeOder function anything in the model. Then I just add something similar to the submit order page. In your case "redirect".
view/place_order/tmpl/submitOrder.php (snipet)
defined('_JEXEC') or die('Restricted access');
$user =& JFactory::getUser();
if ($user->guest) {
echo "<p>You must login to access this page.</p>";
}
else if($_POST == "" || $_POST == null){
echo "<p>You can not directly access this page.</p>";
}else {
//Your order was submitted successfully HTML (don't forget to close it at the bottom ;)
There are a lot of ways you could do it... you probably don't even need to check in the controller if you don't want to but I do to save on time. With out seeing your code it's hard to tailor the answer but if you grasp the concept here it should help (I hope...).
You might also want to check out this page from Joomla on authorization and privileges.
this should be done in your component's base controller (controller.php). if you look at this code snippet:
// Check for edit form.
if ($vName == 'form' && !$this->checkEditId('com_weblinks.edit.weblink', $id))
{
// Somehow the person just went to the form - we don't allow that.
return JError::raiseError(403,
JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id));
}
this block of code is present in most of core components intended to do exactly what you want. how ever how this actually dos what it does is explained through the $this->checkEditId() function. I hope you are familiar with the JControllerForm class and if you are not check out the API. because creating an edit id for a page and "authorizing user for access to a specific page based on his last page" is done by JControllerForm.