Projet

Général

Profil

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

root / drupal7 / sites / all / modules / cas / cas.user.inc @ a2baadd1

1
<?php
2

    
3
/**
4
 * @file
5
 * Provides CAS user registration administrative pages.
6
 */
7

    
8
/**
9
 * Creates a CAS user registration page.
10
 */
11
function cas_add_user_form() {
12
  $form = array();
13

    
14
  $form['account']['cas_name'] = array(
15
    '#type' => 'textfield',
16
    '#title' => t('CAS username'),
17
    '#required' => TRUE,
18
    '#default_value' => '',
19
    '#description' => t('Registration will proceed as if the user with the specified CAS username just logged in.'),
20
    '#element_validate' => array('_cas_name_element_validate'),
21
    '#weight' => -10,
22
  );
23

    
24
  $form['actions'] = array('#type' => 'actions');
25
  $form['actions']['submit'] = array(
26
    '#type' => 'submit',
27
    '#value' => t('Create new account'),
28
  );
29
  return $form;
30
}
31

    
32
function cas_add_user_form_submit($form, &$form_state) {
33
  $options = array(
34
    'invoke_cas_user_presave' => TRUE,
35
  );
36
  $account = cas_user_register($form_state['values']['cas_name'], $options);
37

    
38
  // Terminate if an error occurred while registering the user.
39
  if (!$account) {
40
    drupal_set_message(t("Error saving user account."), 'error');
41
    $form_state['redirect'] = '';
42
    return;
43
  }
44

    
45
  // Set these in case another module needs the values.
46
  $form_state['user'] = $account;
47
  $form_state['values']['uid'] = $account->uid;
48

    
49
  $uri = entity_uri('user', $account);
50
  drupal_set_message(t('Created a new user account for <a href="@url">%name</a>. No e-mail has been sent.', array('@url' => url($uri['path'], $uri['options']), '%name' => $account->name)));
51
}