rev 1508 - in trunk/siesta: . lib/Template/Plugin

[prev] [thread] [next] [lurker] [Date index for 2004/04/06]

From: richardc
Subject: rev 1508 - in trunk/siesta: . lib/Template/Plugin
Date: 17:27 on 06 Apr 2004
Author: richardc
Date: 2004-04-06 17:27:35 +0100 (Tue, 06 Apr 2004)
New Revision: 1508

Modified:
   trunk/siesta/TODO
   trunk/siesta/lib/Template/Plugin/Siesta.pm
Log:
force subscriptions to go via the sub pipeline

Modified: trunk/siesta/TODO
===================================================================
--- trunk/siesta/TODO	2004-04-06 16:03:54 UTC (rev 1507)
+++ trunk/siesta/TODO	2004-04-06 16:27:35 UTC (rev 1508)
@@ -24,8 +24,6 @@
 
 =head3 setting prefs - constrained input based on type field
 
-=head3 subscription should invoke the sub queue, not do the subscribe itself
-
 =head2 Integration with Mariachi
 
 password-protected archives should be easy via the mod_perl handler

Modified: trunk/siesta/lib/Template/Plugin/Siesta.pm
===================================================================
--- trunk/siesta/lib/Template/Plugin/Siesta.pm	2004-04-06 16:03:54 UTC (rev 1507)
+++ trunk/siesta/lib/Template/Plugin/Siesta.pm	2004-04-06 16:27:35 UTC (rev 1508)
@@ -88,43 +88,38 @@
 
     unless (defined $pass1) {
         $self->error("Passwords must be at least $MIN_PASS long");
+        return;
     }
     if ( defined($pass1) && defined($pass2) && $pass1 ne $pass2) {
         $self->error("Password and confirmation must match");
+        return;
     }
 
-    my $user = Siesta::Member->load($email);
-    if ($user) {
-        $self->error("This email address is already subscribed");
-    }
+    my $user = Siesta::Member->load( $email ) ||=
+      Siesta::Member->create({ email => $email, password => $pass1 });
 
     # should return a list of the ticked checkboxes need to confirm
     # they are public lists, as you shouldnt be able to sub to private
     # lists before you are subscribed I guess.
     my @subscriptions = $self->cgi->param('subscribe');
 
-    $user ||= Siesta::Member->create({ email => $email });
-    $user->password($pass1);
-    $user->update;
-
     foreach my $list_name (@subscriptions) {
-        #print "list name $list_name";
-        my($list) =  Siesta::List->load( $list_name );
-        unless ($list) {
-            $self->error( "Failed to find a list called $list_name" );
-            next;
-        }
-        $list->add_member($user);
+        my $list = Siesta::List->load( $list_name );
+        my $sub_address = $list->address( 'sub' );
+        eval {
+            Siesta->process(
+                action => 'sub',
+                list   => $list_name,
+                mail   => <<END,
+From: $email
+To: $sub_address
+Subject: Web subscription
 
-        my $mail = Siesta::Message->new();
-        $mail->reply( to   => $list->owner->email,
-                      from => $list->address( 'bounce' ),
-                      subject => 'web subscription',
-                      body => Siesta->bake('subscribe_notify',
-                                           list    => $list,
-                                           user    => $user,
-                                           message => $mail ),
-                     );
+Little pig, little pig, let me in
+END
+               );
+        };
+        $self->error( $@ ) if $@;
     }
     return 1; # success
 }

Generated at 13:57 on 01 Jul 2004 by mariachi 0.52