|
发表于 2004-4-16 10:40:25
|
显示全部楼层
去掉Drupal注册用户时的E-mail验证(v4.4.0rc)
去掉Drupal注册用户时的E-mail验证(v4.4.0rc)
Submitted by fwolf on Tue, 2004/03/09 - 14:00. drupal | PHP
由于很多虚拟主机无法发送邮件,导致用Drupal建的网站无法注册新用户,其实很简单,把注册用户是发送邮件的部分改为直接显示用户密码就可以了。 打开modules/user.module,在第830行左右(我用的是Drupal v4.4.0rc),找到如下两行:
user_mail($edit['mail'], $subject, $body, "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from");
return t("Your password and further instructions have been sent to your e-mail address.");
把这两行注释掉,再添加自己的内容,结果如下:
//user_mail($edit['mail'], $subject, $body, "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from");
//return t("Your password and further instructions have been sent to your e-mail address.");
$output .= "<p>Welcome to Drupal. <p> Your username is <strong>$account->name</strong>. </p><p> Your password is <strong>$pass</strong>. You may change your password on the next page.</p><p><font color='#FF0000'>Don't forget your username and password information, login and modify to your own password.</font></p><p>lease login below.</p>";
$output .= form_hidden("destination", "user/edit");
$output .= form_hidden('name', $account->name);
$output .= form_hidden('pass', $pass);
$output .= form_submit(t("Log in"));
return form($output);
这是解决了注册时的得到系统分配的密码的问题,但是这个系统分配的密码不好记,还是需要改成自己的密码,下面就来调整用户修改的部分,还是user.module,在第706行左右,找到如下代码:
if ($account) {
$from = variable_get("site_mail", ini_get("sendmail_from"));
$pass = user_password();
/*
** Save new password:
*/
user_save($account, array('pass' => $pass));
/*
** Mail new password:
*/
$variables = array("%username" => $account->name, "%site" => variable_get("site_name", "drupal"), "%password" => $pass, "%uri" => $base_url, "%uri_brief" => substr($base_url, strlen("http://")), "%mailto" => $account->mail, "%date" => format_date(time()), '%login_uri' => url('user/login', NULL, NULL, TRUE), '%edit_uri' => url('user/edit', NULL, NULL, TRUE));
$subject = _user_mail_text("pass_subject", $variables);
$body = _user_mail_text("pass_body", $variables);
$headers = "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from";
$mail_success = user_mail($account->mail, $subject, $body, $headers);
if ($mail_success) {
watchdog('user', "mail password: '". $account->name ."' <". $account->mail .">");
return t("Your password and further instructions have been sent to your e-mail address.");
}
else {
watchdog('error', "error mailing new password: '". $account->name ."' <". $account->mail .">");
return t("Unable to send mail. Please contact the site admin.");
}
}
改为:
if ($account && user_access("authenticated user")) {
$from = variable_get("site_mail", ini_get("sendmail_from"));
$pass = user_password();
/*
** Save new password:
*/
user_save($account, array('pass' => $pass));
/*
** Mail new password:
*/
// $variables = array("%username" => $account->name, "%site" => variable_get("site_name", "drupal"), "%password" => $pass, "%uri" => $base_url, "%uri_brief" => substr($base_url, strlen("http://")), "%mailto" => $account->mail, "%date" => format_date(time()), '%login_uri' => url('user/login', NULL, NULL, TRUE), '%edit_uri' => url('user/edit', NULL, NULL, TRUE));
// $subject = _user_mail_text("pass_subject", $variables);
// $body = _user_mail_text("pass_body", $variables);
// $headers = "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from";
// $mail_success = user_mail($account->mail, $subject, $body, $headers);
//
// if ($mail_success) {
// watchdog('user', "mail password: '". $account->name ."' <". $account->mail .">");
// return t("Your password and further instructions have been sent to your e-mail address.");
// }
// else {
// watchdog('error', "error mailing new password: '". $account->name ."' <". $account->mail .">");
// return t("Unable to send mail. Please contact the site admin.");
// }
$output .= "<p> Your new password is <strong>$pass</strong>. </p><p><font color='#FF0000'>Don't forget your username and password information forever.</font></p>";
return form($output);
}
用户就可以自行修改密码了。 这样用户在注册时就会直接得到系统自动分配的密码,如果需要,Login以后改为自己的密码就可以了,而不再需要麻烦再去收邮件了。唯一麻烦的是, Drupal本来注册时是发送密码到邮箱,而修改密码大概是把新密码发送到邮箱或者发送一个链接到邮箱进行确认,现在这两个都改成了直接显示和直接实现了,问题虽然不大,但如果忘记密码,想通过EMAIL取回密码则无法进行了(因为邮箱验证被去掉了),希望大家要记好了,不要忘记密码啊。
from:http://fwolf.51j.cn/?q=node/view/3 |
|