diff --git a/scripts/resend_activation_email.php b/scripts/resend_activation_email.php new file mode 100644 index 0000000..ec7d55f --- /dev/null +++ b/scripts/resend_activation_email.php @@ -0,0 +1,65 @@ + 2, 'portability' => DB_PORTABILITY_ALL ); +$conn = DB::connect(getDSN(), $options); +if(DB :: isError($conn)) { + echo $conn->toString(); + set_response_code(500); + echo $crypt->json_encode_and_encrypt(array('error' => 'Could not connect to DB')); + die(); +} +$conn->setFetchMode(DB_FETCHMODE_ASSOC); + +if( !defined("CLI_SERVER_NAME") || !defined('CLI_SCHEME')) { + echo "CLI_SERVER_NAME or CLI_SCHEME is not configured. Check snapporder/config.php\n"; + die(1); +} +if(PHP_SAPI !== 'cli') { + echo "Not allowed. Run this on the command line.\n"; + die(1); +} +if($argc < 2) { + echo "Invalid number of arguments.\n"; + die(1); +} +if( !is_numeric($argv[1]) ) { + echo "User ID is not a number.\n"; + die(1); +} + +$user = get_user($argv[1]); +if( $user == NULL ) { + echo "User with user ID $argv[1] not found.\n"; + die(1); +} + +/* Add register url */ +if($user['registration_status'] !== "partial") { + echo "User ".$user['memberid']." has invalid registration status '".$user['registration_status']."' (not partial).\n"; + die(1); +} +$server_name = CLI_SERVER_NAME; +$scheme = CLI_SCHEME; +$user['registration_url'] = generate_registration_url($user, SECRET_KEY); + +/* Send email */ +send_activation_email(array(), $user); +echo "Email sent to ". $user['email'].".\n"; diff --git a/snapporder/config-sample.php b/snapporder/config-sample.php index 3e5a3f8..a0340c3 100644 --- a/snapporder/config-sample.php +++ b/snapporder/config-sample.php @@ -6,4 +6,8 @@ define("MAILCHIMP_API_KEY", ""); define("MAILCHIMP_LIST_ID", "004f53d7c6"); define("TEKSTMELDING_API_KEY", 'qwertyuiop'); + + /* Used in scripts (resend activation email) */ + define("CLI_SERVER_NAME", 'inside.dev'); + define('CLI_SCHEME', 'http'); ?> diff --git a/snapporder/lib/functions.php b/snapporder/lib/functions.php index c522088..e0d7024 100644 --- a/snapporder/lib/functions.php +++ b/snapporder/lib/functions.php @@ -326,10 +326,14 @@ function check_token($user, $token, $secret_key) { return true; } -function generate_registration_url($user, $secret_key) { +function generate_registration_url($user, $secret_key, $server_name=NULL, $scheme=NULL) { $token = create_token($user, $secret_key); - $server_name = isset($_SERVER['HTTP_X_FORWARDED_SERVER']) ? $_SERVER['HTTP_X_FORWARDED_SERVER'] : $_SERVER['SERVER_NAME']; - $scheme ="http".((empty($_SERVER['HTTPS']) or $_SERVER['HTTPS'] == 'off')?'':'s'); + if($server_name == NULL) { + $server_name = isset($_SERVER['HTTP_X_FORWARDED_SERVER']) ? $_SERVER['HTTP_X_FORWARDED_SERVER'] : $_SERVER['SERVER_NAME']; + } + if($scheme == NULL) { + $scheme = "http" . ((empty($_SERVER['HTTPS']) or $_SERVER['HTTPS'] == 'off') ? '' : 's'); + } $url = "$scheme://".$server_name."/snapporder/activate.php?userid=".$user['memberid']."&token=$token"; return $url;