Projet

Général

Profil

Paste
Télécharger (1,84 ko) Statistiques
| Branche: | Révision:

root / htmltest / sites / all / modules / ldap / ldap_authentication / ldap_authentication.pages.inc @ dd54aff9

1
<?php
2
/**
3
 * @file
4
 * User-facing page callbacks for the LDAP Authentication module.
5
 */
6

    
7
/**
8
 * Form constructor for updating the profile.
9
 * 
10
 * @see ldap_authentication_profile_update_form_validate().
11
 * @see ldap_authentication_profile_update_form_submit().
12
 */
13
function ldap_authentication_profile_update_form($form, &$form_state) {
14
  $form['mail'] = array(
15
    '#type' => 'textfield',
16
    '#required' => TRUE,
17
    '#title' => t('Email Address'),
18
  );
19
  $form['submit'] = array(
20
    '#type' => 'submit',
21
    '#value' => t('Update Profile'),
22
  );
23
  return $form;
24
}
25

    
26
/**
27
 * Form validator for updating the profile.
28
 * 
29
 * @see ldap_authentication_profile_update_form().
30
 */
31
function ldap_authentication_profile_update_form_validate($form, &$form_state) {
32
  if (!filter_var($form_state['values']['mail'], FILTER_VALIDATE_EMAIL)) {
33
    form_set_error('mail', t('You must specify a valid email address.'));
34
  }
35
  $existing = user_load_by_mail($form_state['values']['mail']);
36
  if ($existing) {
37
    form_set_error('mail', t('This email address is already in user.'));
38
  }
39
  $auth = ldap_authentication_get_valid_conf();
40
  $regex = '`' . $auth->templateUsagePromptRegex . '`i';
41
  if (preg_match($regex, $form_state['values']['mail'])) {
42
    form_set_error('mail', t('This email address still matches the invalid email template.'));
43
  }
44
}
45

    
46
/**
47
 * Form submit handler for updating the profile.
48
 * 
49
 * @see ldap_authentication_profile_update_form().
50
 */
51
function ldap_authentication_profile_update_form_submit($form, &$form_state) {
52
  global $user;
53
  if (user_save($user, array(
54
    'mail' => $form_state['values']['mail'],
55
  ))) {
56
    // prevents the cached setting from being used again.
57
    unset($_SESSION['ldap_authentication_template']);
58
    $form_state['redirect'] = isset($_GET['next']) ? $_GET['next'] : '<front>';
59
    drupal_set_message(t('Your profile has been updated.'));
60
  }
61
}