diff options
Diffstat (limited to 'cgi-bin/invite')
| -rwxr-xr-x | cgi-bin/invite | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/cgi-bin/invite b/cgi-bin/invite new file mode 100755 index 0000000..cf29b1b --- /dev/null +++ b/cgi-bin/invite @@ -0,0 +1,123 @@ +#!/usr/bin/perl +######################################### +# invite +######################################### +# id hash state attest created expired username password realname email grass keywords + +use localbucky; + +use invite; +use Digest::MD5 qw (md5_hex); + +$dbh = DBI->connect ($dsn); + +our ($USER, $lastlog) = checkin(); +our $loggedin = ($USER != -1); + +our ($command, $hash, $id) = invite_init(); +invite_run($command, $hash, $id); + +sub invite_init + { + my $command = exists($input->{c}) ? scrub($input->{c}) : -1; + my $hash = -1; + if (defined($input->{object_from_uri})) + { $hash = scrub($input->{object_from_uri}); } + elsif (exists($input->{hash})) + { $hash = scrub($input->{hash}); } + elsif (exists($input->{invite})) + { $hash = scrub($input->{invite}); } + elsif (exists($input->{i})) + { $hash = scrub($input->{i}); } + my $id = exists($input->{id}) ? scrub($input->{id}) : -1; + return ($command, $hash, $id); + } + +sub invite_run + { + my ($command, $hash, $id) = @_; + + if ($loggedin) + { invite_process_user($command, $hash, $id); } + else + { invite_process_outsider($command, $hash); } + } + +sub invite_process_outsider + { + my ($command, $hash) = @_; + + # validate invite + if ($command eq "validate") + { + validate_invite($hash); + } + # add request + elsif ($command eq "request") + { + request_invite(); + } + # redeem invite + elsif ($hash != -1) + { + my $invite = get_invite_from_hash($hash); + unless (invite_is_active($invite)) + { error("Bad invite key!"); } + registration_form($invite); + } + # registration form + else + { + registration_form(); + } + } + +sub invite_process_user + { + my ($command, $hash, $id) = @_; + my $result = -1; + my $invite = -1; + if ($hash != -1) + { $invite = get_invite_from_hash($hash); } + elsif ($id) + { $invite = get_invite_from_id($id); } + + # new invite + if ($command eq "new") + { + $hash = generate_invite(); + $result = ($hash != -1) ? 1 : 0; + } + # approve/delete/extend invites + elsif ($command eq "approve" && $USER->{ulevel} == 3) + { $result = validate_approve($invite); } + elsif ($command eq "reject" && $USER->{ulevel} == 3) + { $result = set_invite_state($invite, $BUCKY_INVITE_REJECTED); } + elsif ($command eq "cancel" && $invite->{attest} eq $USER->{username}) + { $result = set_invite_state($invite, $BUCKY_INVITE_EXPIRED); } + elsif ($command eq "renew" && $invite->{attest} eq $USER->{username}) + { $result = set_invite_expired($invite, ($invite->{expired} + 86400*7)); } + + header("invite manager"); + menu(); + + print qq(<table width="100%" cellpadding=0 cellspacing=0 border=0>); + print qq(<tr><td align=center valign=top>\n); + + display_personal_invites($user_invites); + print "<p>"; + display_approve_list() if ($USER->{ulevel} == 3); + + print qq(</td>\n<td width="200" align=right valign=top>\n); + + invite_result_box($command, $hash, $result) if ($command != -1); + invite_create_box(); + + print qq(</td></tr></table>\n\n); + + footer(); + } + +$dbh->disconnect (); + + |
