Hi,
I am trying to develop a module for Drupal 4.7 to have a custom reset password node. This is how it would work :
When the user has logged on to the account, to change the password he would have to goto a node where i have 3 fields: old password, new password and new password confirm. the old password is compared to the current password stored in a filemaker database. if it matches, the current password is replaced by the new password (from the form).
Now, when i added this module to my modules directory, the admin page (the one that lists the modules) fails to show up on the site. if i remove the module, it comes back up ... i was wondering if someone could help me with finding and rectifying the bug.
I am attaching the code...
----------------------------------------------------------------------------------------------------------------------------------
/**
* Password Reset Module
* User enters current password and the new password.
* The new password needs to be validated (typed in twice)
* The current password field is matched with the password in the database
* If they match, the existing password will be replaced by the new password.
*/
/**
* Implementation of hook_help().
*
* Throughout Drupal, hook_help() is used to display help text at the top of
* pages. Some other parts of Drupal pages get explanatory text from these hooks
* as well. We use it here to provide a description of the module on the
* module administration page.
*/
function reset_password_help($section='') {
$output = '';
switch ($section) {
case "admin/modules#description":
$output = t('The reset_password module adds activites to fm db.');
break;
}
return $output;
} // function reset_password_help
/**
* Implementation of hook_perm().
*
*/
function reset_password_perm() {
return array('my_users');
} // function reset_password_perm
function reset_password_menu($may_cache) {
$items = array();
$access = user_access('my_users');
if (!$may_cache) {
// This determines the path used to show the form and also makes a menu entry
// This first path is for the entry form
$items[] = array('path' => 'reset_password',
'title' => t('Reset Password'),
'callback' => reset_password_form,
'access' => $access);
$items[] = array('path' => 'reset_password/complete',
'title' => t('Password Reset Successful'),
'type' => MENU_DYNAMIC_ITEM,
'callback' => reset_password_complete,
'access' => $access);
}
return $items;
}
function reset_password() {
global $user;
$form = array();
$webmasterEmailAddress = '1@2.com'; // If you set the above to TRUE, enter the appropriate email address on this line.
$emailFromAddress = '3@4.com'; // Sets who the error message will show as the sender.
$fx = reset_password_connect_to_fm('web');
$layout = $fx->FMView();
$scheme = 'http';
$form['account'] = array('#type' => 'fieldset',
'#title' => t('Account information'));
$form['account']['password_current'] = array(
'#type' => 'password',
'#default_value' => '',
'#maxlength' => 15,
'#size' => 15,
'#prefix' => '<tr><td>',
'#suffix' => '</td>',
'#title' => t('Enter Current Password'));
$form['account']['password_new'] = array(
'#type' => 'password',
'#default_value' => '',
'#maxlength' => 15,
'#size' => 15,
'#prefix' => '<td>',
'#suffix' => '</td></tr></table><br/><br/><br/><br/>',
'#title' => t('Enter New Password'));
$form['account']['password_confirm'] = array(
'#type' => 'password',
'#default_value' => '',
'#maxlength' => 15,
'#size' => 15,
'#prefix' => '<td>',
'#suffix' => '</td></tr></table><br/><br/><br/><br/>',
'#title' => t('Confirm New Password'));
$form['Page1']['back'] = array( // Back Button
'#type' => 'button',
'#value' => t('Back'),
'#weight' => 35,
);
$form['Page1']['submit'] = array('#type' => 'submit', '#value' => t('submit'));
// drupal_get_form produces the form which return to the drupal system which produces the page
// The first parameter to drupal_get_form is the form id. It also determines the default validation and submit function names
// In this case
// Validation: mypageform_sample_validate()
// Submit: my_form_submit()
return drupal_get_form('reset_password', $form);
}
function reset_password_validate($form_id, $form_values) { // Checking for empty values
foreach($form_values as $field=>$value) {
if($value != '') continue;
switch($field) {
case 'password_current':
case 'password_new':
case 'password_confirm';
form_set_error($field,t('The value for '.$field.' cannot be blank.'));
break;
}
}
if($form_values['password_new'] !='' || $form_values['password_confirm']!='') {
if($form_values['password_new'] != $form_values['password_confirm']) {
form_set_error('password',t('Please enter matching passwords.'));
form_set_error('password_confirm','',true);
}
}
else{
form_set_error('password',t('Passwords cannot be blank.'));
}
if (ereg(' ', $form_values['password_new'])) return t('The password cannot contain spaces.');
if (ereg("[^\x80-\xF7[:graph:]]", $form_values['password_new'])) return t('The password contains an illegal character.');
if (preg_match('/[\x{80}-\x{A0}'. // Non-printable ISO-8859-1 + NBSP
'\x{AD}'. // Soft-hyphen
'\x{2000}-\x{200F}'. // Various space characters
'\x{2028}-\x{202F}'. // Bidirectional text overrides
'\x{205F}-\x{206F}'. // Various text hinting characters
'\x{FEFF}'. // Byte order mark
'\x{FF01}-\x{FF60}'. // Full-width latin
'\x{FFF9}-\x{FFFD}]/u', // Replacement characters
$form_values['password_new'])) {
return t('The password contains an illegal character.');
}
}
function reset_password_connect_to_fm($layout) {
$serverIP = 'x.x.x.x';
$webCompanionPort = 80; // for FM7SA, this should we the web server port
$dataSourceType = 'FMPro7';
$webUN = 'abcd'; // defaults for fmfile in FM7; both should be blank for Book_List in FM5/6
$webPW = 'abcd';
$FMFile = 'xyz.fp7';
$scheme = 'http'; // generally this will be 'http'; 'https' for SSL connections to FileMaker
$fm = new FX($serverIP, $webCompanionPort, $dataSourceType); // This line creates an instance of the FX class
$fm->SetDBData($FMFile, $layout); // The '->' indicates that SetDBData is part of // the FX instance we just created.
$fm->SetDBUserPass ($webUN, $webPW); // Set the user name and password for the desired access.
return $fm;
}
function reset_password_submit($form_id, $form_values) {
$resetPassword = reset_password_connect_to_fm("web");
$checkPass = reset_password_connect_to_fm("web");
$currentPass = $form_values['password_current'];
$newPass = $form_values['password_new'];
$checkPass->AddDBParam('iearnpeople::drupal_uid',$user->uid,'eq');
$checkPass->AddDBParam('iearnpeople::password',$currentPass,'eq');
$rst = $checkPass->FMFind();
if($rst['foundCount']!=1){ // != or <
form_set_error('password_current',t("Please enter your current password correctly!");
$pass=$currentPass;
}
else{
$pass=$newPass;
}
$view = $resetPassword->FMView();
$resetPassword->->AddDBParam('-recid',$currentRecord);
$resetPassword->->AddDBParam('iearnpeople::password',$pass);
$resetPassword->->AddDBParam('iearnpeople::webxstatus','pending');
$result = $resetPassword->FMEdit();
drupal_set_message(t('The password has been changed.'));
drupal_goto('user/'. $account->uid .'/edit');
//return reset_password;
}
----------------------------------------------------------------------------------------------------------------------------------
thanks
Comments
Error likely related to a PHP error
Error likely related to a PHP error, most commonly a syntax error or missing function.
I would suggest looking at the Drupal logs and making sure it is not be logged, if it is being logged the message should help pin point the problem.
One thing I note is
->->in the code, that will cause a problem.If that does not help here is a more general approach.
Before starting the process below, please back up your original source file(s) for the module
If that does not help, create an empty version of the module.
thanks for spotting the
thanks for spotting the syntax error :)
i managed to get the module on the admin page and also set access rights .. however i get a blank page when i try to load the node by http://xxx.yyy.com/reset_password ...
i am sorry for these naive questions but i just started using drupal ..
Some pointers
Generally the callback value should be a function name as a string, so
'callback' => reset_password_form,should be'callback' => 'reset_password_form',.Also the function should exist, in your case I believe your function reset_password should be reset_password_form.
Also in general if your function that builds the function is reset_password_form, then your validation function should be reset_password_form_validate and the submit function reset_password_form_submit (there are exceptions to this )
Note after changing the menu hook you will want to visit "Administer" -> "Site buiiding" -> "Menus" to force the menus to be rebuilt.
thanks a bunch for your help
thanks a bunch for your help ...
one last question ... can you confirm whether this logic of mine is right ??? it doesnt seem to change the password ..
All i am trying is sending the password entered and the username (or should i just send the password ?) to compare to the plaintext password stored in filemaker. if userid and password match, foundCount is 1 and in that condition the password would be changed to newpassword ..
also, i am not sure if i have the correct record id .. am i retreiving it right ??? any idea on how to retreive the current record number ?
thanks a million ...
Do you mean save in Drupal or filemaker
If you mean filemaker that is not something I have any experience in.
If you mean Drupal, why do use form_alter to modify the existing reset password form?