[ZendTo] Changing a user's email address - Followup

Nigel Kendrick linker3000 at gmail.com
Tue Oct 23 12:16:35 BST 2012


Hi Jules/Everyone,

As a follow-up to my earlier question about changing a user's Zendto email
address, I modified a copy of one of the existing apps to create
changeemail.php and added a small section to SQLite.php to support it as
below. I'm not using MySQL so I didn't amend its PHP function library.

Comments or thoughts?

Cheers,

Nigel

:

/opt/zendto/bin/changeemail.php

#!/usr/bin/php
<?PHP

if (count($argv)==3 && getenv('ZENDTOPREFS')) {
  array_splice($argv, 1, 0, getenv('ZENDTOPREFS'));
}

if ( count($argv) != 4 ) {
  $prefs=getenv('ZENDTOPREFS');
  if ($prefs=='') {
    printf("
  usage:

     %s '<username>' '<email_address>'

   The ZendTo preferences.php file path should be canonical, not relative.
   (It must start with a \"/\")
   Alternatively, do
     export ZENDTOPREFS=<full file path of preferences.php>
     %s '<username>' '<email_address>'

",$argv[0],$argv[0]);
  } else {
    printf("
  usage:

   %s '<username>' '<email_address>'

   The ZendTo preferences.php file path is pointed to by the environment
   variable ZENDTOPREFS, which is currently set to
   %s

",$argv[0],$prefs);
  }
  return 0;
}

if ( ! preg_match('/^\/.+/',$argv[1]) ) {
  echo "ERROR:  You must provide a canonical path to the preference
file.\n";
  return 1;
}

include $argv[1];
require_once(NSSDROPBOX_LIB_DIR."Smartyconf.php");
include_once(NSSDROPBOX_LIB_DIR."NSSDropoff.php");

if ( $theDropbox = new NSSDropbox($NSSDROPBOX_PREFS, FALSE, TRUE) ) {
  $username = $argv[2];
  $emailaddr = $argv[3];

  $result = $theDropbox->database->DBUpdatePasswordLocalUser($username,
                                                             $emailaddr);

  if ($result == '') {
    $emprint = $emailaddr;
    if ($emailaddr == '') {
      $emprint = 'WARNING: No email address!';
    }
    printf("Username  : $username\n");
    printf("Email addr: $emprint\n");
    return 0;
  } else {
    printf("Failed: $result\n");
    return 1;
  }
}

?>



Added to SQLite.php:

// Update an existing user's email address
// Returns '' on success.

public function DBUpdateEmailAddressLocalUser ( $username, $emailaddr ) {
  if (!$this->DBReadLocalUser($username)) {
    return "Aborting updating user $username as that user does not exist";
  }

  $query = sprintf("UPDATE usertable
                    SET mail='%s'
                    WHERE username='%s'",
                    sqlite_escape_string($emailaddr),
                    sqlite_escape_string($username));
  if (!$this->database->queryExec($query)) {
    return "Failed to update email address for user $username";
  }
  return '';
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ecs.soton.ac.uk/pipermail/zendto/attachments/20121023/fdab55c2/attachment.html 


More information about the ZendTo mailing list