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 dd54aff9 Assos Assos
<?php
2 32700c57 Assos Assos
3 dd54aff9 Assos Assos
/**
4
 * @file
5
 * User-facing page callbacks for the LDAP Authentication module.
6
 */
7
8
/**
9
 * Form constructor for updating the profile.
10 32700c57 Assos Assos
 *
11
 * @see ldap_authentication_profile_update_form_validate()
12
 * @see ldap_authentication_profile_update_form_submit()
13 dd54aff9 Assos Assos
 */
14
function ldap_authentication_profile_update_form($form, &$form_state) {
15 32700c57 Assos Assos
  $form['mail'] = [
16 dd54aff9 Assos Assos
    '#type' => 'textfield',
17
    '#required' => TRUE,
18
    '#title' => t('Email Address'),
19 32700c57 Assos Assos
  ];
20
  $form['submit'] = [
21 dd54aff9 Assos Assos
    '#type' => 'submit',
22
    '#value' => t('Update Profile'),
23 32700c57 Assos Assos
  ];
24 dd54aff9 Assos Assos
  return $form;
25
}
26
27
/**
28
 * Form validator for updating the profile.
29 32700c57 Assos Assos
 *
30
 * @see ldap_authentication_profile_update_form()
31 dd54aff9 Assos Assos
 */
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 32700c57 Assos Assos
 *
50
 * @see ldap_authentication_profile_update_form()
51 dd54aff9 Assos Assos
 */
52
function ldap_authentication_profile_update_form_submit($form, &$form_state) {
53
  global $user;
54 32700c57 Assos Assos
  if (user_save($user, [
55 dd54aff9 Assos Assos
    'mail' => $form_state['values']['mail'],
56 32700c57 Assos Assos
  ])) {
57
    // Prevents the cached setting from being used again.
58 dd54aff9 Assos Assos
    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
}