fixed login redirection from login block and improved design of this block

This commit is contained in:
Bachir Soussi Chiadmi 2015-07-02 19:24:43 +02:00
parent 22146c2778
commit 3220ed8e4b
7 changed files with 1707 additions and 1268 deletions

View File

@ -6,61 +6,248 @@
*/
/**
* List destination rules.
* Form for editing an entire login destination at once.
*
* Shows list of all login destination.
*/
function login_destination_overview() {
$header = array(
t('Destination'),
t('Triggers'),
t('Pages'),
t('Roles'),
array('data' => t('Operations'), 'colspan' => 2),
);
$rows = array();
function login_destination_overview_form($form, &$form_state) {
// Get all login destination rules from the database.
$result = db_select('login_destination', 'l')
->fields('l', array('id', 'triggers', 'roles', 'pages_type', 'pages', 'destination'))
->fields('l', array(
'id',
'triggers',
'roles',
'pages_type',
'pages',
'destination',
'weight',
'enabled',
)
)
->orderBy('weight')
->execute()
->fetchAll();
$form['#tree'] = TRUE;
// Loop through the categories and add them to the table.
foreach ($result as $data) {
$triggers = array_map('check_plain', unserialize($data->triggers));
if (empty($triggers))
if (empty($triggers)) {
$triggers = array();
}
$roles = array_map('check_plain', unserialize($data->roles));
if (empty($roles))
if (empty($roles)) {
$roles = array();
}
$form[$data->id]['destination']['#markup'] = theme('login_destination_destination', array('destination' => $data->destination));
$form[$data->id]['triggers']['#markup'] = theme('login_destination_triggers', array('items' => $triggers));
$form[$data->id]['pages']['#markup'] = theme('login_destination_pages', array('pages' => $data->pages, 'pages_type' => $data->pages_type));
$form[$data->id]['roles']['#markup'] = theme('login_destination_roles', array('items' => $roles));
$form[$data->id]['weight'] = array(
'#type' => 'weight',
'#title' => t('Weight'),
'#delta' => 50,
'#default_value' => $data->weight,
'#title_display' => 'invisible',
);
$form[$data->id]['enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Enabled'),
'#default_value' => $data->enabled,
'#title_display' => 'invisible',
);
// Build a list of operations.
$operations = array();
$operations['edit'] = array(
'#type' => 'link',
'#title' => t('edit'),
'#href' => 'admin/config/people/login-destination/edit/' . $data->id,
);
$operations['delete'] = array(
'#type' => 'link',
'#title' => t('delete'),
'#href' => 'admin/config/people/login-destination/delete/' . $data->id,
);
$form[$data->id]['operations'] = $operations;
}
if (element_children($form)) {
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save configuration'),
);
}
else {
$form['#empty_text'] = t('There is no Login Destination Rule.');
}
return $form;
}
/**
* Returns HTML for a login destination list.
*
* @param array $variables
* An associative array containing:
* - form: A render element representing the form.
*
* @ingroup themeable
*/
function theme_login_destination_overview_form($variables) {
$form = $variables['form'];
drupal_add_tabledrag('login-destination-overview', 'order', 'sibling', 'login-destination-weight');
$header = array(
t('Destination'),
t('Triggers'),
t('Pages'),
t('Roles'),
array('data' => t('Enabled'), 'class' => array('checkbox')),
t('Weight'),
array('data' => t('Operations'), 'colspan' => '2'),
);
$rows = array();
foreach (element_children($form) as $ldid) {
if (isset($form[$ldid]['enabled'])) {
$element = &$form[$ldid];
$operations = array();
foreach (element_children($element['operations']) as $op) {
$operations[] = array('data' => drupal_render($element['operations'][$op]), 'class' => array('login-destination-operations'));
}
while (count($operations) < 2) {
$operations[] = '';
}
$row = array();
$row[] = drupal_render($element['destination']);
$row[] = drupal_render($element['triggers']);
$row[] = drupal_render($element['pages']);
$row[] = drupal_render($element['roles']);
$row[] = array(
'data' => drupal_render($element['enabled']),
'class' => array(
'checkbox', 'login-destination-enabled',
),
);
$form[$ldid]['weight']['#attributes']['class'] = array('login-destination-weight');
$row[] = drupal_render($element['weight']);
$row = array_merge($row, $operations);
$row = array_merge(array('data' => $row), array());
$row['class'][] = 'draggable';
$rows[] = $row;
}
}
$output = '';
if (empty($rows)) {
$rows[] = array(
theme('login_destination_destination', array('destination' => $data->destination)),
theme('login_destination_triggers', array('items' => $triggers)),
theme('login_destination_pages', array('pages' => $data->pages, 'pages_type' => $data->pages_type)),
theme('login_destination_roles', array('items' => $roles)),
l(t('Edit'), 'admin/config/people/login-destination/edit/' . $data->id),
l(t('Delete'), 'admin/config/people/login-destination/delete/' . $data->id),
array(
'data' => $form['#empty_text'],
'colspan' => '7',
),
);
}
if (!$rows) {
$rows[] = array(array(
'data' => t('No rules available.'),
'colspan' => 6,
));
}
$build['login-destination_table'] = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
$table_arguments = array(
'header' => $header,
'rows' => $rows,
'attributes' => array(
'id' => 'login-destination-overview',
),
);
return $build;
$output .= theme('table', $table_arguments);
$output .= drupal_render_children($form);
return $output;
}
/**
* Submit handler for the login destination overview form.
*
* This function update the login destination rule attribute
* like rules are enabled/disabled or its weight.
*
* @see login_destination_overview_form()
*/
function login_destination_overview_form_submit($form, &$form_state) {
$element = &$form_state['values'];
foreach (element_children($element) as $ldid) {
if (isset($form[$ldid]['enabled'])) {
$login_destination_rules[$ldid] = $element[$ldid];
$login_destination_rules[$ldid]['ldid'] = $ldid;
}
}
foreach ($login_destination_rules as $ldid => $login_destination_rule) {
_login_destination_update_rules($login_destination_rule);
}
drupal_set_message(t('Your configuration has been saved.'), 'status');
}
/**
* Save all our changed items to the database.
*
* @param array $login_destination_rule
* An associative array representing a login destination item:
* - enabled: (required) can contain 0 or 1, if rule is enabled then
* it should be 1 else 0.
* - weight: (required) can contain any integer value.
*
* @return bool
* The ldid of the saved login destination rule, or FALSE
* if the login destination rule could not be saved.
*/
function _login_destination_update_rules($login_destination_rule) {
if (!(isset($login_destination_rule['enabled']) && isset($login_destination_rule['weight']) && isset($login_destination_rule['ldid']))) {
return FALSE;
}
if ($login_destination_rule['enabled'] != 0 && $login_destination_rule['enabled'] != 1) {
return FALSE;
}
$login_destination_rule['weight'] = intval($login_destination_rule['weight']);
if (!is_int($login_destination_rule['weight'])) {
return FALSE;
}
db_update('login_destination')
->fields(array(
'enabled' => $login_destination_rule['enabled'],
'weight' => $login_destination_rule['weight'],
))
->condition('id', $login_destination_rule['ldid'])
->execute();
return $login_destination_rule['ldid'];
}
/**
* Render a destination of login destination rule.
*/
function theme_login_destination_destination($variables) {
$output = nl2br(check_plain($variables['destination']));
@ -71,6 +258,9 @@ function theme_login_destination_destination($variables) {
return $output;
}
/**
* Render a trigger of login destination rule.
*/
function theme_login_destination_triggers($variables) {
$items = array_map('check_plain', $variables['items']);
@ -82,10 +272,11 @@ function theme_login_destination_triggers($variables) {
foreach ($items as &$item) {
switch ($item) {
case 'login':
$item = 'Login';
$item = t('Login');
break;
case 'logout':
$item = 'Logout';
$item = t('Logout');
break;
}
$output .= $item . "<br/>";
@ -94,9 +285,12 @@ function theme_login_destination_triggers($variables) {
return $output;
}
/**
* Render a page type of login destination rule.
*/
function theme_login_destination_pages($variables) {
$type = $variables['pages_type'];
if ($type == LOGIN_DESTINATION_REDIRECT_PHP) {
return nl2br(check_plain($variables['pages']));
}
@ -120,11 +314,14 @@ function theme_login_destination_pages($variables) {
$output .= "~ ";
}
$output .= $page . "<br/>";
}
}
return $output;
}
/**
* Render a roles of login destination rule.
*/
function theme_login_destination_roles($variables) {
$items = array_values(array_intersect_key(_login_destination_role_options(), $variables['items']));
@ -139,7 +336,7 @@ function theme_login_destination_roles($variables) {
* Category edit page.
*/
function login_destination_edit_form($form, &$form_state, array $rule = array()) {
// default values
// Default values.
$rule += array(
'triggers' => array(),
'roles' => array(),
@ -167,18 +364,29 @@ function login_destination_edit_form($form, &$form_state, array $rule = array())
}
else {
$options = array(
LOGIN_DESTINATION_STATIC => t('Internal page or external URL'),
);
$description = t("Specify page by using its path. Example path is %blog for the blog page. %front is the front page. %current is the current page. Precede with http:// for an external URL. Leave empty to redirect to a default page.", array('%blog' => 'blog', '%front' => '<front>', '%current' => '<current>'));
LOGIN_DESTINATION_STATIC => t('Internal page or external URL'),
);
$description = t("Specify page by using its path. Example path is %blog for the blog page. %front is the front page. %current is the current page. Precede with http:// for an external URL. Leave empty to redirect to a default page.", array(
'%blog' => 'blog',
'%front' => '<front>',
'%current' => '<current>',
)
);
if (module_exists('php') && $access) {
$options += array(LOGIN_DESTINATION_SNIPPET => t('Page returned by this PHP code (experts only)'));
$description .= ' ' . t('If the PHP option is chosen, enter PHP code between %php. It should return either a string value or an array of params that the %function function will understand, e.g. %example. For more information, see the online API entry for <a href="@url">url function</a>. Note that executing incorrect PHP code can break your Drupal site.', array('%php' => '<?php ?>', '%function' => 'url($path = \'\', array $options = array())', '%example' => '<?php return array(\'blog\', array(\'fragment\' => \'overlay=admin/config\', ), ); ?>', '@url' => 'http://api.drupal.org/api/drupal/includes--common.inc/function/url/7'));
$description .= ' ' . t('If the PHP option is chosen, enter PHP code between %php. It should return either a string value or an array of params that the %function function will understand, for example. %example. For more information, see the online API entry for <a href="@url">url function</a>. Note that executing incorrect PHP code can break your Drupal site.', array(
'%php' => '<?php ?>',
'%function' => 'url($path = \'\', array $options = array())',
'%example' => '<?php return array(\'blog\', array(\'fragment\' => \'overlay=admin/config\', ), ); ?>',
'@url' => 'http://api.drupal.org/api/drupal/includes--common.inc/function/url/7',
)
);
}
$form['destination_type'] = array(
'#type' => 'radios',
'#title' => 'Redirect to page',
'#title' => t('Redirect to page'),
'#default_value' => $type,
'#options' => $options,
);
@ -197,9 +405,9 @@ function login_destination_edit_form($form, &$form_state, array $rule = array())
$form['triggers'] = array(
'#type' => 'checkboxes',
'#title' => t('Redirect upon triggers'),
'#options' => array('login' => 'Login, registration, one-time login link', 'logout' => 'Logout'),
'#options' => array('login' => t('Login, registration, one-time login link'), 'logout' => t('Logout')),
'#default_value' => $triggers,
'#description' => 'Redirect only upon selected trigger(s). If you select no triggers, all of them will be used.',
'#description' => t('Redirect only upon selected trigger(s). If you select no triggers, all of them will be used.'),
);
$type = $rule['pages_type'];
@ -216,10 +424,18 @@ function login_destination_edit_form($form, &$form_state, array $rule = array())
}
else {
$options = array(
LOGIN_DESTINATION_REDIRECT_NOTLISTED => t('All pages except those listed'),
LOGIN_DESTINATION_REDIRECT_LISTED => t('Only the listed pages'),
);
$description = t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page. %login is the login form. %register is the registration form. %reset is the one-time login (e-mail validation).", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>', '%login' => 'user', '%register' => 'user/register', '%reset' => 'user/*/edit'));
LOGIN_DESTINATION_REDIRECT_NOTLISTED => t('All pages except those listed'),
LOGIN_DESTINATION_REDIRECT_LISTED => t('Only the listed pages'),
);
$description = t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page. %login is the login form. %register is the registration form. %reset is the one-time login (e-mail validation).", array(
'%blog' => 'blog',
'%blog-wildcard' => 'blog/*',
'%front' => '<front>',
'%login' => 'user',
'%register' => 'user/register',
'%reset' => 'user/*/edit',
)
);
if (module_exists('php') && $access) {
$options += array(LOGIN_DESTINATION_REDIRECT_PHP => t('Pages on which this PHP code returns <code>TRUE</code> (experts only)'));
@ -249,14 +465,7 @@ function login_destination_edit_form($form, &$form_state, array $rule = array())
'#title' => t('Redirect users with roles'),
'#options' => _login_destination_role_options(),
'#default_value' => $default_role_options,
'#description' => 'Redirect only the selected role(s). If you select no roles, all users will be redirected.',
);
$form['weight'] = array(
'#type' => 'weight',
'#title' => t('Weight'),
'#default_value' => $rule['weight'],
'#description' => t('When evaluating login destination rules, those with lighter (smaller) weights get evaluated before rules with heavier (larger) weights.'),
'#description' => t('Redirect only the selected role(s). If you select no roles, all users will be redirected.'),
);
$form['actions'] = array('#type' => 'actions');
@ -279,6 +488,17 @@ function login_destination_edit_form($form, &$form_state, array $rule = array())
* Validate the contact category edit page form submission.
*/
function login_destination_edit_form_validate($form, &$form_state) {
$destination = $form_state['values']['destination'];
$destination_type = $form_state['values']['destination_type'];
// Check user has enter any path.
if (!empty($destination) && $destination_type == 0) {
$destination = preg_replace("/\?.+/", "", $destination);
if (!drupal_valid_path($destination)) {
form_set_error('destination', t('Incorrect path, Please Enter valid Path'));
}
}
}
/**
@ -296,7 +516,7 @@ function login_destination_edit_form_submit($form, &$form_state) {
}
drupal_set_message(t('Login destination to %destination has been saved.', array('%destination' => $form_state['values']['destination'])));
$form_state['redirect'] = 'admin/config/people/login-destination';
}

View File

@ -1,13 +1,11 @@
name = Login Destination
description = Customize the destination that the user is redirected to after login.
core = 7.x
files[] = login_destination.module
files[] = login_destination.admin.inc
configure = admin/config/people/login-destination
; Information added by drupal.org packaging script on 2012-12-18
version = "7.x-1.1"
; Information added by Drupal.org packaging script on 2015-05-11
version = "7.x-1.1+6-dev"
core = "7.x"
project = "login_destination"
datestamp = "1355853150"
datestamp = "1431374284"

View File

@ -58,6 +58,13 @@ function login_destination_schema() {
'default' => 0,
'description' => "The rule's weight.",
),
'enabled' => array(
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 1,
'description' => "The rule enabled/disabled status.",
),
),
'primary key' => array('id'),
'indexes' => array(
@ -69,12 +76,13 @@ function login_destination_schema() {
}
/**
* Implementation of hook_install().
* Implements hook_install().
*/
function login_destination_install() {
// update the alter option of 'user/logout' to TRUE (menu_save invokes necessary hooks)
// Update the alter option of 'user/logout' to TRUE,
// (menu_save invokes necessary hooks).
$result = db_query("SELECT mlid, menu_name FROM {menu_links} WHERE link_path = 'user/logout' OR link_path = 'user/login' OR link_path = 'user' ORDER BY mlid ASC");
foreach($result as $res) {
foreach ($result as $res) {
$item = menu_link_load($res->mlid);
$item['options']['alter'] = TRUE;
db_update('menu_links')
@ -87,13 +95,16 @@ function login_destination_install() {
}
/**
* Implementation of hook_uninstall().
* Implements hook_uninstall().
*/
function login_destination_uninstall() {
variable_del('login_destination_preserve_destination');
variable_del('login_destination_profile_redirect');
}
/**
* Implements hook_update_N().
*/
function login_destination_update_7000() {
$type = variable_get('ld_condition_type', 'always');
$snippet = variable_get('ld_condition_snippet', '');
@ -117,7 +128,7 @@ function login_destination_update_7000() {
if ($type == 'snippet') {
$form_state['values']['destination_type'] = 1;
// syntax for return value has changed.
// Syntax for return value has changed.
$form_state['values']['destination'] = '<?php /* ' . $snippet . ' */ ?>';
}
else {
@ -138,3 +149,17 @@ function login_destination_update_7000() {
variable_del('ld_url_type');
variable_del('ld_url_destination');
}
/**
* Implements hook_update_N().
*/
function login_destination_update_7001() {
$spec = array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 1,
);
db_add_field('login_destination', 'enabled', $spec);
}

View File

@ -5,17 +5,17 @@
* Control where users are directed to, once they login
*/
// Page constants
// Page constants.
define('LOGIN_DESTINATION_REDIRECT_NOTLISTED', 0);
define('LOGIN_DESTINATION_REDIRECT_LISTED', 1);
define('LOGIN_DESTINATION_REDIRECT_PHP', 2);
// Destination constants
// Destination constants.
define('LOGIN_DESTINATION_STATIC', 0);
define('LOGIN_DESTINATION_SNIPPET', 1);
/**
* Implement hook_help().
* Implements hook_help().
*/
function login_destination_help($path, $arg) {
switch ($path) {
@ -24,6 +24,7 @@ function login_destination_help($path, $arg) {
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Login Destination module allows you to customize the destination that the user is redirected to after logging in, registering to the site, using a one-time login link or logging out. The destination can be an internal page or an external URL. You may specify certain conditions like pages or user roles and make the destination depend upon them. You may also use a PHP snippets to provide custom conditions and destinations. Note that PHP Filter module has to be enabled and you have to be granted the "Use PHP for settings" permissions to be able to enter PHP code.') . '</p>';
return $output;
case 'admin/config/people/login-destination':
return '<p>' . t('Login destination rules are evaluated each time a user logs in, registers to the site, uses a one-time login link or logs out. Each rule consists of the destination, path conditions and user roles conditions. First matching rule gets executed.') . '</p>';
}
@ -36,7 +37,8 @@ function login_destination_menu() {
$items['admin/config/people/login-destination'] = array(
'title' => 'Login destinations',
'description' => 'Customize the destination that the user is redirected to after login.',
'page callback' => 'login_destination_overview',
'page callback' => 'drupal_get_form',
'page arguments' => array('login_destination_overview_form'),
'access arguments' => array('administer users'),
'file' => 'login_destination.admin.inc',
'weight' => 10,
@ -102,12 +104,12 @@ function login_destination_load($id) {
if (empty($result['roles'])) {
$result['roles'] = array();
}
return $result;
}
/**
* Implements hook_theme
* Implements hook_theme().
*/
function login_destination_theme() {
return array(
@ -127,11 +129,15 @@ function login_destination_theme() {
'variables' => array('items' => NULL),
'file' => 'login_destination.admin.inc',
),
'login_destination_overview_form' => array(
'file' => 'login_destination.admin.inc',
'render element' => 'form',
),
);
}
/**
* Implements hook_form_alter
* Implements hook_form_alter().
*/
function login_destination_form_alter(&$form, &$form_state, $form_id) {
// We redirect by using the drupal_goto_alter hook. If we simply
@ -152,14 +158,16 @@ function login_destination_form_alter(&$form, &$form_state, $form_id) {
// original submit function from user module.
switch ($form_id) {
case 'user_register_form': // user register page
case 'user_login': // user login page
// User register page and user login page.
case 'user_register_form':
case 'user_login':
$form['#validate'][] = 'login_destination_validate';
break;
}
switch ($form_id) {
case 'user_profile_form': // one-time login, password reset
// One-time login, password reset.
case 'user_profile_form':
if (isset($_GET['pass-reset-token'])) {
// Redirect only from user_pass_reset
// You have to explicitally turn on the option to always redirect from
@ -181,20 +189,21 @@ function login_destination_validate($form, &$form_state) {
$_GET['q'] = 'user/register';
}
break;
case 'user_login':
if (drupal_match_path($_GET['q'], 'user/register')) {
$_GET['q'] = 'user';
}
break;
}
// Fix the current page in case of 403 page.
if ($form['#form_id'] == 'user_login') {
if(drupal_get_http_header('Status') == '403 Forbidden') {
if (drupal_get_http_header('Status') == '403 Forbidden') {
$_GET['current'] = $_GET['destination'];
}
}
}
/**
@ -205,7 +214,7 @@ function login_destination_submit($form, &$form_state) {
}
/**
* Implements hook_menu_link_alter
* Implements hook_menu_link_alter().
*/
function login_destination_menu_link_alter(&$item) {
// Flag a link to be altered by hook_translated_menu_link_alter().
@ -218,7 +227,7 @@ function login_destination_menu_link_alter(&$item) {
}
/**
* Implements hook_translated_menu_link_alter
* Implements hook_translated_menu_link_alter().
*/
function login_destination_translated_menu_link_alter(&$item, $map) {
global $user;
@ -230,7 +239,7 @@ function login_destination_translated_menu_link_alter(&$item, $map) {
}
/**
* Implements hook_page_alter
* Implements hook_page_alter().
*/
function login_destination_page_alter(&$page) {
// Substitute toolbar's pre_render function to change links.
@ -250,7 +259,7 @@ function login_destination_toolbar_pre_render($toolbar) {
}
/**
* Implements hook_user_login
* Implements hook_user_login().
*/
function login_destination_user_login(&$edit, $account) {
if (!isset($_POST['form_id']) || $_POST['form_id'] != 'user_pass_reset' || variable_get('login_destination_immediate_redirect', FALSE)) {
@ -259,7 +268,7 @@ function login_destination_user_login(&$edit, $account) {
}
/**
* Implements hook_user_insert
* Implements hook_user_insert().
*/
function login_destination_user_insert(&$edit, $account, $category) {
global $user;
@ -272,14 +281,14 @@ function login_destination_user_insert(&$edit, $account, $category) {
}
/**
* Implements hook_user_logout
* Implements hook_user_logout().
*/
function login_destination_user_logout($account) {
login_destination_perform_redirect('logout', _login_destination_get_current('logout'));
}
/**
* Implements hook_drupal_goto_alter
* Implements hook_drupal_goto_alter().
*/
function login_destination_drupal_goto_alter(&$path, &$options, &$http_response_code) {
// Note that this functionality cannot be backported do 6.x as Drupal 6 does
@ -289,7 +298,7 @@ function login_destination_drupal_goto_alter(&$path, &$options, &$http_response_
if (isset($GLOBALS['destination'])) {
$destination = $GLOBALS['destination'];
// alter drupal_goto
// Alter drupal_goto.
if (is_array($destination)) {
$path = $destination[0];
$options = array();
@ -307,7 +316,7 @@ function login_destination_drupal_goto_alter(&$path, &$options, &$http_response_
* Pass destination to drupal_goto.
*/
function login_destination_prepare_goto($destination) {
// Check if $_GET['destination'] should overwrite us
// Check if $_GET['destination'] should overwrite us.
if (!isset($_GET['destination']) || !variable_get('login_destination_preserve_destination', FALSE)) {
$GLOBALS['destination'] = $destination;
}
@ -315,14 +324,18 @@ function login_destination_prepare_goto($destination) {
/**
* Evaluate rules and perform redirect.
*
* This function is intended to be used by external modules.
* @param <type> $trigger
* @param <type> $current if null $_GET['q'] is used
*
* @param string $trigger
* Action of login destination rule.
* @param string $current
* Path, if null $_GET['q'] is used.
*/
function login_destination_perform_redirect($trigger = '', $current = NULL) {
$destination = login_destination_get_destination($trigger, $current);
// Check if we redirect
// Check if we redirect.
if ($destination !== FALSE) {
login_destination_prepare_goto($destination);
}
@ -330,13 +343,22 @@ function login_destination_perform_redirect($trigger = '', $current = NULL) {
/**
* Process all destination rules and return destination path.
*
* This function is intended to be used by external modules.
*/
function login_destination_get_destination($trigger = '', $current = NULL) {
// Get all the login destination rules from the database.
$result = db_select('login_destination', 'l')
//->addTag('translatable')
->fields('l', array('triggers', 'roles', 'pages_type', 'pages', 'destination_type', 'destination'))
->fields('l', array(
'triggers',
'roles',
'pages_type',
'pages',
'destination_type',
'destination',
'enabled',
)
)
->orderBy('weight')
->execute()
->fetchAll();
@ -345,16 +367,16 @@ function login_destination_get_destination($trigger = '', $current = NULL) {
$current = $_GET['q'];
}
// examine path matches
// Examine path matches.
foreach ($result as $data) {
// try to match the subsequent rule
// Try to match the subsequent rule.
if (_login_destination_match_rule($data, $trigger, $current)) {
// Note: Matching rule with empty destination will cancel redirect.
return _login_destination_evaluate_rule($data, $trigger);
}
}
// no rule matched
// No rule matched.
return FALSE;
}
@ -370,12 +392,11 @@ function _login_destination_eval($code) {
}
/**
* A helper function to provide role options
* A helper function to provide role options.
*/
function _login_destination_role_options() {
// user role selection, without anonymous and authentificated user roles.
// User role selection, without anonymous user roles.
$role_options = array_map('check_plain', user_roles(TRUE));
unset($role_options[DRUPAL_AUTHENTICATED_RID]);
return $role_options;
}
@ -391,38 +412,46 @@ function _login_destination_get_current($trigger = '') {
return $_GET['q'];
}
// front by default
// Front by default.
return '';
}
/**
* A helper function to determine whether redirection should happen.
*
* @return bool TRUE - apply redirect, FALSE - not to apply redirect.
* @return bool
* TRUE - apply redirect, FALSE - not to apply redirect.
*/
function _login_destination_match_rule($rule, $trigger = '', $current = NULL) {
global $user;
// Check rule is enabled or not.
if ($rule->enabled == 0) {
return FALSE;
}
$type = $rule->pages_type;
$pages = $rule->pages;
$triggers = unserialize($rule->triggers);
if (empty($triggers))
if (empty($triggers)) {
$triggers = array();
}
$roles = unserialize($rule->roles);
if (empty($roles))
if (empty($roles)) {
$roles = array();
}
// remove non-existent roles
// Remove non-existent roles.
$roles = array_intersect_key(_login_destination_role_options(), $roles);
// examine trigger match
// Examine trigger match.
if (!(empty($triggers) || array_key_exists($trigger, $triggers))) {
return FALSE;
}
// examine role matches
// Examine role matches.
$roles_intersect = array_intersect_key($roles, $user->roles);
if (!empty($roles) && empty($roles_intersect)) {
@ -456,34 +485,34 @@ function _login_destination_match_rule($rule, $trigger = '', $current = NULL) {
*/
function _login_destination_evaluate_rule($rule, $trigger = '') {
if ($rule->destination_type == LOGIN_DESTINATION_STATIC) {
// take only 1st line
if (preg_match("!^(.*?)$!", $rule->destination, $matches) === 1 ) {
// Take only 1st line.
if (preg_match("!^(.*?)$!", $rule->destination, $matches) === 1) {
$path = $matches[1];
if (empty($path)) {
return FALSE;
}
// Current path
// Current path.
elseif ($path == '<current>') {
return _login_destination_get_current($trigger);
}
// External URL
// External URL.
elseif (strpos($path, '://') !== FALSE) {
return $path;
}
// Internal URL
// Internal URL.
else {
$destination = drupal_parse_url($path);
$options = array();
$options['query'] = $destination['query'];
$options['fragment'] = $destination['fragment'];
// drupal_goto cares about <front>
// Drupal api, drupal_goto cares about <front>.
return array($destination['path'], $options);
}
}
else {
// error - multiple lines
// Error - multiple lines.
return '';
}
}

View File

@ -204,25 +204,12 @@ function materio_user_form_alter(&$form, &$form_state, $form_id) {
$form['actions']['#type'] = "container";
$form['actions']['submit']['#value'] = t('Join');
// $form['termsofservices'] = array(
// '#type' => 'checkbox',
// '#title' => t('I accept') .' '. l(t('the materiO terms of services'), 'node/11183'),
// '#required' => true,
// );
// $form['#submit'][] = "materio_user_user_register_form_submit";
}
if($form_id == "user_login" ){
// dsm($form);
$form['actions']['#type'] = "container";
// $form['actions']['submit']['#value'] = t('Join');
// if( $_GET['q'] == 'node/11187' ){
// $form['#submit'][] = "materio_user_user_login_form_submit";
// }
}
# https://drupal.org/comment/6293810#comment-6293810

File diff suppressed because it is too large Load Diff

View File

@ -275,18 +275,27 @@ $headerouterheight:$headerheight+$headerpaddingtop+$headerpaddingbottom;
@include fs10;
}
// label{width:30%;}
input.form-text{width:150px;}
input.form-text{
width:150px; height:2em;
}
#edit-actions{
.form-actions{
margin: 5px 0; padding: 0; background-color:transparent; text-align: right;
input.form-submit{
@include fs12;
padding: 10px;
// @include fs12;
@include fs16; padding: 0.1em 0.6em 0.2em; @include rounded(0.3em);
font-weight:bold;
margin-bottom:4px;
border: 2px solid #E6DE1C; background-color:#E6DE1C; color:#fff; // noire/jaune
@include shadowTextBtnBlack();
}
}
div.newpass a{
@include fs12;
color:#686868;
div.newpass{
text-align: right;
a{
@include fs12;
color:#686868;
}
}
// div.register a{