token integration

bignab - September 9, 2009 - 16:04
Project:Node Access Password
Version:6.x-2.1
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:postponed (maintainer needs more info)
Description

I was needing integration with the token module so I could automatically email the node password to specified users. Here it is if it's useful for anyone else.

Here's what I came up with:

nodeaccess_password.token.inc

<?php

function nodeaccess_password_token_list($type = 'all') {
  $tokens = array();
  if ($type == 'node' || $type == 'all') {
    $tokens['node']['nodeaccess-password']=t('The Node Access Passwords.');
    return $tokens;
  }
}

function nodeaccess_password_token_values($type, $object = NULL, $options = array()) {
  $values = array();
  switch ($type) {
    case 'node':
                $node = $object;
                $thenode = node_load($node->nid);
                foreach ($thenode->nodeaccess_password as $realm => $password) {
                        $values['nodeaccess-password'] .= $realm . " password : " . $password . "\n";
                }
      break;
  }
  return $values;
}

added to nodeaccess_password.module:

/**
* Implementation of hook_init().
*/

function nodeaccess_password_init() {
  if (module_exists('token') && !function_exists('nodeaccess_password_token_values')) {
    module_load_include('inc', 'nodeaccess_password', 'nodeaccess_password.token');
  }
}

#1

danielb - September 9, 2009 - 23:24

Awesome dude, I've never integrated with token before, so I don't really understand this. Are those 2 functions some sort of token hooks? If so we probably don't need the conditional init stuff to add them in.

#2

danielb - September 20, 2009 - 10:27
Status:active» postponed (maintainer needs more info)

I'm concerned about the security issue of having a token available that shows you the passwords of the node, and all at once? Can any member with access to tokens use these tokens to discover a password they shouldn't?

 
 

Drupal is a registered trademark of Dries Buytaert.