feat(activation): Adds resend activation email cmd

Look in scripts dir
This commit is contained in:
nikolark committed 2016-02-06 20:55:44 +01:00
1 parent 324612852f
commit 43bca1d54f
3 files changed
+76 -3

No files matched your search

+65
View File
@@ -0,0 +1,65 @@
<?php
/**
* Resend activation email which contains the user activation.
*
* Usage:
* $ php resend_activation_email.php USER_ID
*
**/
set_include_path("../includes/");
set_include_path("../inside/");
require_once("functions.php");
require_once("User.php");
set_include_path("../includes/");
require_once("DB.php");
require_once("../snapporder/config.php");
require_once("../snapporder/lib/functions.php");
/* Connect to database */
$options = array( 'debug' => 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";
+4
View File
@@ -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');
?>
+7 -3
View File
@@ -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;