move email registration code to DomainStatusNetworkPlugin

This commit is contained in:
Evan Prodromou 2011-06-06 12:25:26 -04:00
parent 506958f2c8
commit 17294a4627
2 changed files with 40 additions and 29 deletions

View File

@ -195,6 +195,32 @@ class DomainStatusNetworkPlugin extends Plugin
_m('A plugin that maps a single status_network to an email domain.')); _m('A plugin that maps a single status_network to an email domain.'));
return true; return true;
} }
static function registerEmail($email, $sendWelcome, $template)
{
$domain = self::toDomain($email);
$sn = self::siteForDomain($domain);
if (empty($sn)) {
$installer = new DomainStatusNetworkInstaller($domain);
// Do the thing
$installer->main();
$sn = $installer->getStatusNetwork();
$config = $installer->getConfig();
Status_network::$wildcard = $config['WILDCARD'];
}
StatusNet::switchSite($sn->nickname);
$confirm = EmailRegistrationPlugin::registerEmail($email);
return $confirm;
}
} }
// The way addPlugin() works, this global variable gets disappeared. // The way addPlugin() works, this global variable gets disappeared.

View File

@ -39,39 +39,24 @@ require_once INSTALLDIR.'/scripts/commandline.inc';
$email = $args[0]; $email = $args[0];
$domain = DomainStatusNetworkPlugin::toDomain($email); $sendWelcome = have_option('w', 'welcome');
$sn = DomainStatusNetworkPlugin::siteForDomain($domain); if ($sendWelcome && have_option('t', 'template')) {
$template = get_option_value('t', 'template');
if (empty($sn)) {
$installer = new DomainStatusNetworkInstaller($domain);
$installer->verbose = have_option('v', 'verbose');
// Do the thing
$installer->main();
$sn = $installer->getStatusNetwork();
$config = $installer->getConfig();
Status_network::$wildcard = $config['WILDCARD'];
} }
StatusNet::switchSite($sn->nickname); try {
$confirm = EmailRegistrationPlugin::registerEmail($email); $confirm = DomainStatusNetworkPlugin::registerEmail($email);
if (have_option('w', 'welcome')) { if ($sendWelcome) {
if (have_option('t', 'template')) { EmailRegistrationPlugin::sendConfirmEmail($confirm, $template);
// use the provided template
EmailRegistrationPlugin::sendConfirmEmail($confirm, get_option_value('t', 'template'));
} else {
// use the default template
EmailRegistrationPlugin::sendConfirmEmail($confirm);
} }
$confirmUrl = common_local_url('register', array('code' => $confirm->code));
print $confirmUrl."\n";
} catch (Exception $e) {
print "ERROR: " . $e->getMessage() . "\n";
} }
$confirmUrl = common_local_url('register', array('code' => $confirm->code));
print $confirmUrl."\n";