magento community forgot password not working - magento

I have inherited a Magento Community site, at some point in it's history it was upgraded and it seems that one of the upgrades did not successfully run Forgot Password SQL scripts. The rp_token and rp_token_created_at attributes are missing from the eav_attribute table. So right now if you use the forgot password feature and enter in an email address that is in the system Magento throws an error and you get a blank page.
I tried adding these fields in manually but Magento must be doing some extra work behind the scene when adding attributes, so my question is how can I run the upgrade scripts to get this feature working?
The scripts that it looks like did not complete successfully are:
app\\code\\core\\Mage\\Customer\\sql\\customer_setup\\mysql4-upgrade-1.6.0.0-1.6.1.0.php
These attributes are not in the eav_attribute table.
// Add reset password link token attribute
$installer->addAttribute('customer', 'rp_token', array(
'type' => 'varchar',
'input' => 'hidden',
'visible' => false,
'required' => false
));
// Add reset password link token creation date attribute
$installer->addAttribute('customer', 'rp_token_created_at', array(
'type' => 'datetime',
'input' => 'date',
'validate_rules' => 'a:1:{s:16:\"input_validation\";s:4:\"date\";}',
'visible' => false,
'required' => false
));
app\\code\\core\\Mage\\Admin\\sql\\admin_setup\\upgrade-1.6.0.0-1.6.1.0.php
These are not in the admin_user table.
// Add reset password link token column
$installer->getConnection()->addColumn($installer->getTable('admin/user'), 'rp_token', array(
'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
'length' => 256,
'nullable' => true,
'default' => null,
'comment' => 'Reset Password Link Token'
));
// Add reset password link token creation date column
$installer->getConnection()->addColumn($installer->getTable('admin/user'), 'rp_token_created_at', array(
'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP,
'nullable' => true,
'default' => null,
'comment' => 'Reset Password Link Token Creation Date'
));'

My best guess is SMTP could have been deactivated. Do let me know if am wrong.

Related

Save custom attribute to order object at Checkout in Magento - How can I confirm this?

I've been having trouble with this for a few days, essentially I need to add a custom organisation_id attribute (that I have created via an installer script) to be added to both the customer object and order object at the end of the onepage checkout.
The installer script works fine (I can see the values within the eav_attribute and core_resources table in the database.
During the checkout phase on the final 'Order Review' section, once the Place Order button is clicked this executes the following observer:
sales_order_place_after
Once this has been executed it runs the following function within an Observer:
public function afterOrderPlaced($observer)
{
// this id below comes from a select dropdown within the checkout onepage & already saved to session
$organisation_id = Mage::getSingleton('customer/session')->getCustomerOrganisationId();
$this->_order = $observer->getEvent()->getOrder();
$this->_order->setOrganisationId($organisation_id)->save(); // e.g 25621
// Customer stuff
$this->_customer_id = $this->_order->getCustomerId();
$this->_customer = $this->_order->getCustomer();
$this->_customer->setOrganisationId($organisation_id)->save(); // e.g 25621
}
In this instance, I simply want to set the organisationId value on both the customer and order objects to '25621'.
Once I have completed the checkout process and hit the 'order confirmation' page I'd like to be able to confirm this organisation_id has indeed been correctly added to the customer and order object, can anyone confirm the easiest/best way to do this? I presume this will need to include some modification to the admin html for Sales to include this information as well.
Please note - My Magento skillset is rather limited
My Installer Script below:
$installer = new Mage_Eav_Model_Entity_Setup();
$installer->startSetup();
$installer = new Mage_Eav_Model_Entity_Setup();
$installer->startSetup();
$installer->addAttribute('customer', 'organisation_id', array(
'input' => 'select', //or select or whatever you like
'type' => 'int', //or varchar or anything you want it
'label' => 'Organisation ID',
'visible' => 1,
'required' => 0, //mandatory? then 1
'user_defined' => 1,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
));
$installer->addAttribute('quote', 'organisation_id', array(
'input' => 'select', //or select or whatever you like
'type' => 'int', //or varchar or anything you want it
'label' => 'Organisation ID',
'visible' => 1,
'required' => 0, //mandatory? then 1
'user_defined' => 1,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
));
$installer->addAttribute('order', 'organisation_id', array(
'input' => 'select', //or select or whatever you like
'type' => 'int', //or varchar or anything you want it
'label' => 'Organisation ID',
'visible' => 1,
'required' => 0, //mandatory? then 1
'user_defined' => 1,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
));
$installer->endSetup();
You can check your custom value in your database sales_flat_order_address table and sales_flat_quote_address table .
Let me know if you have any query

CakePHP when using $model->save() validate rules and skip other rules

I'm using CakePHP 2.0 and I have a model that I use validation on it like this:
var $validate = array(
'title' => array(
'unique_rule'=>array(
'rule' => 'isUnique',
'on' => 'create',
'message' => 'This title has already been taken.'
),
'required_rule'=>array(
'required' => true,
'allowEmpty' => false,
'message' => 'The title field is required.'
)
)
);
, and in the controller I have an edit action and I use $model->save() to save date from $this->request->data, but it fails the isUnique validation rule, although it is not a new record insertion.
Is there any way to specify that it is an existing record, not a new one ?
If I got the question right you have to set the model's ID before calling $model->save(); so cakephp knows it's an update.
See http://book.cakephp.org/2.0/en/models/saving-your-data.html:
"Creating or updating is controlled by the model’s id field. If $Model->id is set, the record with this primary key is updated. Otherwise a new record is created:"
<?php
// Create: id isn't set or is null
$this->Recipe->create();
$this->Recipe->save($this->request->data);
// Update: id is set to a numerical value
$this->Recipe->id = 2;
$this->Recipe->save($this->request->data);
your validation array is wrong you haven't set a rule for 'required_rule' wich might trigger the isUnique error message.
var $validate = array(
'title' => array(
'unique_rule'=>array(
'rule' => 'isUnique',
'on' => 'create',
'message' => 'This title has already been taken.',
'last' => true
),
'required_rule'=>array(
'rule' => array('notEmpty'),
'message' => 'The title field is required.'
)
)
);
Also remember that using required=>true will NOT result check for actual data, it only wants the field to be present in the data-array and "" is also considered as present

Magento admin grid sending data from Action to Controller

I'm trying to write a custom action to run off of an admin grid that I have built. Is it possible to send a value from a column in the grid to the controller via either get or post?
I've tried googling, but I cannot find a proper explanation for this anywhere. A link to an explanation of the column settings ('getter', 'type' etc.) would also be useful if this is available.
Add this code to your Grid.php:
$this->addColumn('action',
array(
'header' => Mage::helper('yourmodulename')->__('Action'),
'width' => '100',
'type' => 'action',
'getter' => 'getId',
'actions' => array(
array(
'caption' => Mage::helper('yourmodulename')->__('Edit'),
'url' => array('base'=> '*/*/edit'),
'field' => 'id'
)
),
'filter' => false,
'sortable' => false,
'index' => 'stores',
'is_system' => true,
));
That will build an "Edit" URL with the Id of the selected row as part of the URL. It will look something like <frontname>/<controllername>/edit/id/<value> where value is returned by the getter getId().
The getter field will execute any of the standard Magento magic getters, ie any attribute is gettable. So you could have getName or getProductUrl or getIsLeftHanded if you wanted and your controller can parse the attribute.
The controller can then retrieve that passed value using Mage::app()->getRequest()->getParam('attributename');
In terms of documentation/tutorials, have a read of this article on the website of #AlanStorm as it might help.
HTH,
JD

Codeigniter Custom Form Validation

this is my register method on controller to register a new user.
function register() {
$config_rules = array(
array(
'field' => 'txtEmail',
'label' => 'Email',
'rules' => 'required|valid_email'
),
array(
'field' => 'txtPassword',
'label' => 'Password',
'rules' => 'required|min_length[6]'
),
array(
'field' => 'txtRePassword',
'label' => 'Re-type Password',
'rules' => 'required|min_length[6]'
)
);
$this->form_validation->set_rules($config_rules);
if(isset($_POST['btnSubmit']) && $this->form_validation->run() == TRUE)
{
// insert query and redirect to registration success page
}
$this->load->view('users/register_form');
}
All the rules for form validation are work fine.
But, the problem is I can't do is to validate password and re-type password.
How make a custom form validation such as to check either
password and re-type password are same or not. Then return false for the validation and give error message telling that password and re-type password are not same through validation_errors().
You can specify the rule something like this:
$rules['password'] = "required|matches[passconf]";
In the above example, the field password will be matched with password confirm field passconf.
See the docs for more information.
http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html
add:
matches[txtRePassword]
to the password rules, then you can use:
$this->validation->set_message('matches', 'New Passwords don\'t match');
to make a customer error message

cakePHP optional validation for file upload

How to make file uploading as optional with validation?
The code below validates even if i didn't selected any file.
I want to check the extension only if i selected the the file.
If i am not selecting any file it should not return any validation error.
class Catalog extends AppModel{
var $name = 'Catalog';
var $validate = array(
'name' => array(
'rule' => '/^[a-z0-9 ]{0,}$/i',
'allowEmpty' => false,
'message' => 'Invalid Catalog name'
),
'imageupload' => array(
'rule' => array('extension',array('jpeg','jpg','png','gif')),
'required' => false,
'allowEmpty' => true,
'message' => 'Invalid file'
),
);
}
thanks in advance
"I assign $this->data['Catalog']['image'] = $this->data['Catalog']['imageupload']['name'];"
So by the time you save your data array, it looks something like this I assume:
array(
'image' => 'foobar',
'imageupload' => array(
'name' => 'foobar',
'size' => 1234567,
'error' => 0,
...
)
)
Which means, the imageupload validation rule is trying to work on this data:
array(
'name' => 'foobar',
'size' => 1234567,
'error' => 0,
...
)
I.e. the value it's trying to validate is an array of stuff, not just a string. And that is unlikely to pass the specified validation rule. It's also probably never "empty".
Either you create a custom validation rule that can handle this array, or you need to do some more processing in the controller before you try to validate it.
Concept:
In Controller, before validating, or saving (which does validation automatically by default) check if any file is uploaded. If not uploaded, then unset validator for the file field.
Sample code:
Controller
// is any image uploaded?
$isNoFileUploaded = ($this->request->data['Model']['field_name']['error'] == UPLOAD_ERR_NO_FILE) ? true : false ;
if ($isNoFileUploaded) {
$this->Model->validator()->remove('field_name');
}
Notes:
This solution comes under preprocessing as one of the two alternative approaches (preprocessing in controller, custom validation in model) suggested by #deceze's answer

Resources