| 1 | # $Id: Subscribe.pm 1335 2003-08-13 13:08:05Z richardc $ | ||||||||||
| 2 | package Siesta::Plugin::Subscribe; | ||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 4 | ▶ | use Siesta::Plugin; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 4 | ▶ | use String::Random; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 4 | ▶ | use base 'Siesta::Plugin'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | sub description { | ||||||||
|
Subroutine
description: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 9 | 1 | 'A system plugin used for subscribing a member to the list'; | |||||||||
| 10 | } | ||||||||||
| 11 | |||||||||||
| 12 | 1 | ▶ | sub process { | ||||||||
|
Subroutine
process: called CC=4 SCAR=16.1
Pod
documented
| |||||||||||
| 13 | 1 | my $self = shift; | |||||||||
| 14 | 1 | my $mail = shift; | |||||||||
| 15 | 1 | my $list = $self->list; | |||||||||
| 16 | 1 | my $email = $mail->from; | |||||||||
| 17 | |||||||||||
| 18 | # check to see if they're already subbed | ||||||||||
| 19 | 1 | ▶ | if ( $list->is_member($email) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | 0 | $mail->reply( body => Siesta->bake('subscribe_already', | |||||||||
| 21 | list => $list, | ||||||||||
| 22 | message => $mail) ); | ||||||||||
| 23 | 0 | return 1; | |||||||||
| 24 | } | ||||||||||
| 25 | |||||||||||
| 26 | 1 | my $user = Siesta::Member->load( $email ); | |||||||||
| 27 | 1 | my $newuser; | |||||||||
| 28 | 1 | ▶ | unless ($user) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | 0 | my $password = String::Random->new->randpattern('......'); | |||||||||
| 30 | 0 | $user = Siesta::Member->create({ email => $email, | |||||||||
| 31 | password => $password }); | ||||||||||
| 32 | 0 | $newuser = 1; | |||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | # add the user to the list and if that fails, send an error | ||||||||||
| 36 | 1 | ▶ | unless ( $list->add_member( $user ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | # mail them and reject them | ||||||||||
| 38 | 0 | $mail->reply( body => Siesta->bake('subscribe_already', | |||||||||
| 39 | list => $list, | ||||||||||
| 40 | message => $mail) ); | ||||||||||
| 41 | 0 | return 1; | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | # mail the listowner and tell them that someone subbed | ||||||||||
| 45 | 1 | $mail->reply( to => $list->owner->email, | |||||||||
| 46 | body => Siesta->bake('subscribe_notify', | ||||||||||
| 47 | list => $list, | ||||||||||
| 48 | user => $user, | ||||||||||
| 49 | message => $mail ) | ||||||||||
| 50 | ); | ||||||||||
| 51 | |||||||||||
| 52 | # mail the person and tell them that they've been subbed | ||||||||||
| 53 | 1 | $mail->reply( body => Siesta->bake('subscribe_reply', | |||||||||
| 54 | list => $list, | ||||||||||
| 55 | message => $mail, | ||||||||||
| 56 | user => $user, | ||||||||||
| 57 | newuser => $newuser, | ||||||||||
| 58 | ) | ||||||||||
| 59 | ); | ||||||||||
| 60 | 1 | return 1; | |||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | |||||||||||
| 64 | 4 | 1; | |||||||||
| 65 | |||||||||||