I installed sfDoctrineGuardUser for Symfony 1.4.11, but I can't find the action.class, where register user. I find only class sfGuardCreateUserTask :
protected function execute($arguments = array(), $options = array())
{
$databaseManager = new sfDatabaseManager($this->configuration);
$user = new sfGuardUser();
$user->setEmailAddress($arguments['email_address']);
$user->setUsername($arguments['username']);
$user->setPassword($arguments['password']);
$user->setFirstName($arguments['first_name']);
$user->setLastName($arguments['last_name']);
$user->setIsActive(true);
$user->setIsSuperAdmin($options['is-super-admin']);
$user->save();
$this->logSection('guard', sprintf('Create user "%s"', $arguments['username']));
}
but this isn't this...
I can't find anywhere for example $user->setFirstName($arguments['first_name']); and modified to:
$user->setFirstName($arguments['first_name'] . '#');
Where is the action.class in sfDoctrineGuardPlugin for create new user?
Basically, you don't need that action (or to customize it) in order to create new users. Just create a custom action that generates your registration form and handles the post:
$user = new sfGuardUser();
$user-> // manipulate however you like
$user->save();
try
cache\frontend\prod\modules\autoSfGuardUser\actions
or something similar
if this is what you're looking for, don't rewrite it in there!!
Instead, copy the action to your normal sfGuard module and edit it there
Everything you need is already published by the symfony team :
http://symfony.com/blog/call-the-expert-simple-registration-with-sfdoctrineguardplugin
for further information : http://symfony.com/blog/call-the-expert-customizing-sfdoctrineguardplugin
Related
Good afternoon colleagues ...
I need to be able to update another collection from a custom hook,
The following happens that if I use ItemsService or TableGatewayFactory it uses the acl of the container ... in this case the user will be from a customer role, but this does not have the permission to edit orders, I would like to keep it that way ...
It doesn't matter if I have to update the item with another user using their token, or any other alternative ...
Thanks in advance....
'item.update.transactionlog' => function ($data) { <br>
$container = Application::getInstance()->getContainer(); <br>
$itemsService = new \Directus\Services\ItemsService($container);<br>
$acl = $container->get('acl');<br>
$params = [];<br>
$orden = ['status' => 'paid'];<br>
$orderUpdate = $itemsService->update('orders', $data['orderid'], $orden, $params);<br>
}
I am adding AWeber as an autoresponder in a web application. Using AWeber API, I am able to add a new subscriber to list with a known name which is in this case is firstlist:
$app = new MyApp();
$app->findSubscriber('whtever#aol.com');
$list = $app->findList('firstlist');
$subscriber = array(
'email' => 'someemail#gmail.com',
'name' => 'Name here'
);
$app->addSubscriber($subscriber, $list);
Function definition for findList() is:
function findList($listName) {
try {
$foundLists = $this->account->lists->find(array('name' => $listName));
return $foundLists[0];
}
catch(Exception $exc) {
print $exc;
}
}
As I am developing a public application, so I need to provide users an option to select from their available lists.
Please guide me how I can retrieve all the lists name.
You are returning $foundLists[0] so it will return single list. Try to return foundLists and check what it returns.
This may help you: https://labs.aweber.com/snippets/lists
In short, I pulled the lists by first finding the Aweber User Id so that I could use it in the URL https://api.aweber.com/1.0/accounts/<id>/lists
To find the User ID, I first got the account.
$this->aweber->getAccount($token['access'], $token['secret']);
Then, I retrieve the user's information.
$aweber_user = $this->aweber->loadFromUrl('https://api.aweber.com/1.0/accounts');
From that, I grabbed the user ID with...
$id = $aweber_user->data['entries'][0]['id'];
Once I had the user ID, I could then retrieve their lists with...
$lists = $this->aweber->loadFromUrl('https://api.aweber.com/1.0/accounts/'.$id.'/lists');
This example is more of a procedural approach, of course, I recommend utilizing classes.
How do I use the Form for creating a Cohort in Moodle in my own plugin?
I want to use the form, create the Cohort and return to a URL specified by with the Cohort id as a GET parameter ie http://myip/moodle/myplugin/myscrip.php?cohort_id=0
I've taken a look at the moodle files for the form but it's all chinese for me as i'm a complete novice as it comes to moodle development. What is the 'nice' way of using it?
The forms take a bit of getting used to, they are based on quickforms.
https://docs.moodle.org/dev/Form_API
https://docs.moodle.org/dev/lib/formslib.php_Usage
https://docs.moodle.org/dev/lib/formslib.php_Form_Definition
Usually there is a file named edit.php which uses the class in edit_form.php - but the file names can be anything.
You could take a copy of /cohort/edit.php and put it into your local plugin. If you are only creating cohorts and not updating them, then remove the update and delete code and keep the add cohort code:
$cohortid = cohort_add_cohort($data);
if ($usetags) {
if (isset($data->otags)) {
tag_set('cohort', $cohortid, tag_get_name($data->otags));
} else {
tag_set('cohort', $cohortid, array());
}
}
//update textarea
$data = file_postupdate_standard_editor($data, 'description', $editoroptions, $context, 'cohort', 'cohort', $cohortid);
$DB->set_field('cohort', 'description', $data->description, array('id' => $cohortid));
Then redirect to your link
$url = new moodle_url('/myplugin/myscrip.php', array('cohort_id' => $cohortid));
redirect($url);
I'm developing a custom Moodle authentification plugin for Moodle 2.7.
When a user is authenticated I want them to be added to a specific cohort. If that cohort does not exist I need it to be created automatically. I use the user_authenticated_hook() function in my authentification plugin to achieve this.
My code for creating the cohort is this
$data = new stdClass();
$data->name = 'Name string';
$data->idnumber = 'ID string';
$data->description = 'Description string';
$cohortId = cohort_add_cohort($data);
I have included cohort/lib.php in the auth.php file and I have declared the global variables $DB, $CFG and $SESSION at the first line of the user_authenticated_hook() function.
The authentification works without the part about cohorts. But with the cohort part in place authentication fails and I am redirected to the login page.
The page title is changed to "Error" but that is the only error message I get.
What Am I doing wrong? I hope somebody will be able to help me create cohorts and add members.
It might be because the global $USER object doesn't exist yet or hasn't been populated.
Do you have debug switched on in your config.php?
$CFG->debug = 32767;
$CFG->debugdisplay = 1;
It might be better to respond to the user_created event. So if a user is created by another method, they will still be added to the cohort. eg:
Create a local plugin eg:
/local/add_cohorts
Create an events.php
/local/add_cohorts/db/events.php
Which has something like this
$handlers = array (
'user_created' => array (
'handlerfile' => '/local/add_cohorts/lib.php',
'handlerfunction' => 'local_add_cohorts_user_created',
'schedule' => 'instant',
'internal' => 1,
),
);
Then in /local/add_cohorts/lib.php have
function local_add_cohorts_user_created($user) {
// Do your cohort processing here and add the user
// Use $user->id to add to the cohort members
}
Then create a version.php and install the plugin, then the event handler will be registered.
Events api - https://docs.moodle.org/dev/Events_API
I'm developing a Joomla 3.x plugin, and want to be able to change the plugin parameter set in the plugin's manifest file programmatically. I believe I need to use a JRegistry object, but I'm not sure about the syntax.
Here's the issue:
// token A is set in plugin params as defined in plugin's XML manifest
var_dump($this->params->get('token')); // prints token "A" as expected
// do some stuff to get a fresh access token, called token "B"
$tokenB = $function_to_get_fresh_token();
// set the new token
if ($tokenB) $this->params->set('token', $tokenB);
var_dump($this->params->get('apptoken')); // prints token "B" as expected
the problem is that on subsequent page reloads, the token reverts to tokenA rather than what I assumed would be the stored value of tokenB.
How do I store the tokenB value in the plugin's parameters in the database?
This is a working example of how to change plugin params from within the plugin (J! 3.4):
// Load plugin called 'plugin_name'
$table = new JTableExtension(JFactory::getDbo());
$table->load(array('element' => 'plugin_name'));
// Params can be changed like this
$this->params->set('new_param', 'new value'); // if you are doing change from a plugin
$table->set('params', $this->params->toString());
// Save the change
$table->store();
Note: If new params are added by plugin dynamically and the plugin is saved afterwards, these new params gets deleted. So one way to deal with it is to add those params as hidden fields to plugin's config XML.
This is just an outline, but something along these lines
$extensionTable = new JtableExtension();
$pluginId = $extensionTable->find('element', 'my_plugin');
$pluginRow = $extensionTable->load($pluginId);
// Do the jregistry work that is needed
// do some stuff to get a fresh access token, called token "B"
$tokenB = $function_to_get_fresh_token();
// set the new token
if ($tokenB) $this->params->set('token', $tokenB);
// more stuff
$extensionTable->save($pluginRow);
I spent a lot of time googling and reading and found no real answer to this. Oddly enough this doesn't seem to have been provided for in Joomla. So here's what I ended up doing:
1) build a function to get your plugin ID, since it will change from one installation to another
private function getPlgId(){
// stupid hack since there doesn't seem to be another way to get plugin id
$db = JFactory::getDBO();
$sql = 'SELECT `extension_id` FROM `#__extensions` WHERE `element` = "my_plugin" AND `folder` = "my_plugin_folder"'; // check the #__extensions table if you don't know your element / folder
$db->setQuery($sql);
if( !($plg = $db->loadObject()) ){
return false;
} else {
return (int) $plg->extension_id;
}
}
2) use the plugin id to load the table object:
$extension = new JTableExtension($db);
$ext_id = $this->getPlgId();
// get the existing extension data
$extension->load($ext_id);
3) when you're ready to store the value, add it to the params, then store it:
$this->params->set('myvalue', $newvalue);
$extension->bind( array('params' => $this->params->toString()) );
// check and store
if (!$extension->check()) {
$this->setError($extension->getError());
return false;
}
if (!$extension->store()) {
$this->setError($extension->getError());
return false;
}
If anyone knows a better way to do this please let me know!