/[drupal]/contributions/modules/sympal_password_hijack/sympal_password_hijack.module
ViewVC logotype

Contents of /contributions/modules/sympal_password_hijack/sympal_password_hijack.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Thu Feb 15 19:47:46 2007 UTC (2 years, 9 months ago) by ber
Branch: MAIN
CVS Tags: DRUPAL-4-7--1-0, HEAD
Branch point for: DRUPAL-4-7
File MIME type: text/x-php
## Readme for sympal_password_hijack


## About
Hijacks the new password mail, and mails to a configurable mailaddress instead of to the users mail.

In addition a freetextfield for a message to the administrator is added, so that the person requesting the password can include a note.

It also features a configurable help-text on the password request field, so that you can explain what is going on there, to your users, in your own words.

Use in case your users don't have emailaddresses set, or in case you simply don't want people to be able to reset their passwords.

Many modules, including logintoboggan, ldapauth, even core DrupalID, openID, etceteras allow users to register without a valid password.

Currently this will break the behaviour on password requests.

## credits
By Bèr Kessels, webschuur.com ber@webschuur.com
For
First released for Drupal 4.7
[Homepage](http://drupal.org/projects)
                                     _         _
     ___ _   _ _ __ ___  _ __   __ _| |  _ __ | |
    / __| | | | '_ ` _ \| '_ \ / _` | | | '_ \| |
    \__ \ |_| | | | | | | |_) | (_| | |_| | | | |
    |___/\__, |_| |_| |_| .__/ \__,_|_(_)_| |_|_|
         |___/          |_|

 -readme written in markdown-
1 <?php
2 // $Id$
3
4 /**
5 * @file Lost password hijack for ldap
6 */
7 function sympal_password_hijack_help($section) {
8 $output = '';
9
10 switch ($section) {
11 case 'admin/modules#sympal_password_hijack':
12 $output = t('Hijacks the new password mail, and mails to a configurable mailaddress instead');
13 break;
14 }
15
16 return $output;
17 }
18
19 function sympal_password_hijack_form_alter($form_id, &$form) {
20 if ($form['#id'] == 'user_pass') {
21 // Display form:
22 $form['#theme'] = 'sympal_password_hijack_form';
23 $form['#submit'] = array('sympal_password_hijack_submit' => array());
24 $form['#validate'] = array('sympal_password_hijack_validate' => array());
25
26 $form['name'] = array('#type' => 'textfield',
27 '#title' => t('Username'),
28 '#size' => 30,
29 '#maxlength' => 60,
30 );
31 $form['mail'] = array('#type' => 'textfield',
32 '#title' => t('E-mail address'),
33 '#size' => 30,
34 '#maxlength' => 64,
35 );
36 $form['sph_message'] = array('#type' => 'textarea',
37 '#title' => t('Message for administrator'),
38 '#size' => 30,
39 '#maxlength' => 64,
40 );
41 $form['submit'] = array('#type' => 'submit',
42 '#value' => t('E-mail the request'),
43 '#weight' => 2,
44 );
45 }
46 }
47
48 function sympal_password_hijack_settings() {
49 $form['sph_mail_requests'] = array('#type' => 'textfield',
50 '#title' => t('E-mail address for requests'),
51 '#default_value' => variable_get('sph_help_text', variable_get('site_mail', ini_get('sendmail_from'))),
52 '#size' => 30,
53 '#maxlength' => 64,
54 );
55 $form['sph_help_text'] = array('#type' => 'textarea',
56 '#title' => t('Help message'),
57 '#default_value' => variable_get('sph_help_text', ''),
58 );
59 return $form;
60 }
61
62 function theme_sympal_password_hijack_form($form) {
63 $output = '<p>'. variable_get('sph_help_text', '') .'</p>';
64 $output .= form_render($form);
65 return $output;
66 }
67
68 function sympal_password_hijack_submit($form_id, $form_values) {
69 global $base_url;
70
71 $account = $form_values['account'];
72 $from = variable_get('site_mail', ini_get('sendmail_from'));
73 $to = variable_get('sph_help_text', variable_get('site_mail', ini_get('sendmail_from')));
74
75 // Mail one time login URL and instructions.
76 $variables = array('%username' => $account->name, '%site' => variable_get('site_name', 'drupal'), '%login_url' => user_pass_reset_url($account), '%uri' => $base_url, '%uri_brief' => substr($base_url, strlen('http://')), '%mailto' => $account->mail, '%date' => format_date(time()), '%login_uri' => url('user', NULL, NULL, TRUE), '%edit_uri' => url('user/'. $account->uid .'/edit', NULL, NULL, TRUE));
77 $subject = _user_mail_text('pass_subject', $variables);
78
79
80 $body = _user_mail_text('pass_body', $variables);
81 $body .= "\n ------------------------------------- \n";
82 $body .= $form_values['sph_message'];
83
84 $headers = "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from";
85 $mail_success = user_mail($to, $subject, $body, $headers);
86
87 if ($mail_success) {
88 watchdog('user', t('Password reset instructions mailed to the adminsitrator.'));
89 drupal_set_message(t('The administrator received a mail with your request and will deal with this as soon as possible.'));
90 }
91 else {
92 watchdog('user', t('Error mailing password reset instructions to the administrator.'), WATCHDOG_ERROR);
93 drupal_set_message(t('Unable to send mail. Please contact the site admin.'));
94 }
95 return 'user';
96 }
97
98 function sympal_password_hijack_validate() {
99 global $form_values;
100
101 $name = $form_values['name'];
102 $mail = $form_values['mail'];
103 if (!($form_values['account'] = user_load(array('name' => $name, 'status' => 1)))) {
104 form_set_error('name', t('Sorry. The username %name is not recognized.', array('%name' => theme('placeholder', $name))));
105 }
106 else if (!$mail || !$name) {
107 form_set_error('password', t('You must provide a username and e-mail address.'));
108 }
109 }

  ViewVC Help
Powered by ViewVC 1.1.2