csna.pages.inc
2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/**
* @file
* Menu callbacks for the CSNA module.
*/
/**
* Menu callback: Set email address and password after successful user login
*/
function csna_complete_register_form($form, &$form_state, $account) {
global $user;
if ($account->mail) {
drupal_goto('user');
}
$form_state['user'] = $account;
$form['mail'] = array(
'#type' => 'textfield',
'#title' => t('E-mail address'),
'#maxlength' => EMAIL_MAX_LENGTH,
'#description' => t('A valid e-mail address. All e-mails from the system will be sent to this address. The e-mail address is not made public and will only be used if you wish to receive a new password or wish to receive certain news or notifications by e-mail.'),
'#required' => TRUE,
);
$form['pass'] = array(
'#type' => 'password_confirm',
'#size' => 25,
'#description' => t('Provide a password for the new account in both fields.'),
'#required' => TRUE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
function csna_complete_register_form_validate($form, &$form_state) {
$account = $form_state['user'];
// Trim whitespace from mail, to prevent confusing 'e-mail not valid'
// warnings often caused by cutting and pasting.
$mail = trim($form_state['values']['mail']);
form_set_value($form['mail'], $mail, $form_state);
// Validate the e-mail address, and check if it is taken by an existing user.
if ($error = user_validate_mail($form_state['values']['mail'])) {
form_set_error('mail', $error);
}
elseif ((bool) db_select('users')->fields('users', array('uid'))->condition('uid', $account->uid, '<>')->condition('mail', db_like($form_state['values']['mail']), 'LIKE')->range(0, 1)->execute()->fetchField()) {
form_set_error('mail', t('The e-mail address %email is already taken.', array('%email' => $form_state['values']['mail'])));
}
}
function csna_complete_register_form_submit($form, &$form_state) {
$account = $form_state['user'];
$edit = array(
'mail' => $form_state['values']['mail'],
'pass' => $form_state['values']['pass'],
);
user_save($account, $edit);
}