Projet

Général

Profil

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

root / drupal7 / sites / all / modules / ldap / ldap_authentication / ldap_authentication.pages.inc @ 91af538d

1
<?php
2

    
3
/**
4
 * @file
5
 * User-facing page callbacks for the LDAP Authentication module.
6
 */
7

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

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

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