You are here

function photos_access_pass_validate in Album Photos 7.3

Same name and namespace in other branches
  1. 8.5 photos_access/photos_access.module \photos_access_pass_validate()
  2. 8.4 photos_access/photos_access.module \photos_access_pass_validate()
  3. 6.0.x photos_access/photos_access.module \photos_access_pass_validate()

Check password on node page.

2 calls to photos_access_pass_validate()
photos_access_init in photos_access/photos_access.module
Implements hook_init().
_photos_access in ./photos.module
Photos menu access callback.

File

photos_access/photos_access.module, line 691

Code

function photos_access_pass_validate($t) {
  global $user;

  // Check if admin or author.
  if ($user->uid == 1 || isset($t['view']->uid) && $t['view']->uid == $user->uid) {
    return TRUE;
  }
  if (isset($t['update']->pass)) {

    // Check if collaborator.
    $result = db_query('SELECT uid FROM {photos_access_user} WHERE id = :id', array(
      ':id' => $t['update']->id,
    ));
    foreach ($result as $a) {
      if ($a->uid == $user->uid) {
        return TRUE;
      }
    }
  }
  if ($t['view']->nid) {
    if (isset($_SESSION[$t['view']->nid . '_' . session_id()])) {

      // Check if password matches node password.
      if ($_SESSION[$t['view']->nid . '_' . session_id()] == $t['view']->pass) {
        return TRUE;
      }

      // If password is set, but does not match re enter password.
      drupal_set_message(t('Password has expired.'));
      drupal_goto('privacy/pass/' . $t['view']->type . '/' . $t['view']->nid, array(
        'query' => array(
          'destination' => $_GET['q'],
        ),
      ));
    }
    else {

      // If password is not set, password is required.
      drupal_set_message(t('Password required.'));
      drupal_goto('privacy/pass/' . $t['view']->type . '/' . $t['view']->nid, array(
        'query' => array(
          'destination' => $_GET['q'],
        ),
      ));
    }
  }
}