chiark / gitweb /
wip login/logout handling
[nj-awaymsg.git] / mason / autohandler
index 22b062a0b3683f5dffbac68595d3c9c0e3306cde..a7d58a44946f99c05d6245f3f1e131392cc5a952 100644 (file)
@@ -1,8 +1,37 @@
 <%once>
 use CGI::Auth::Flexible;
-my $verifier = CGI::Auth::Flexible->new_verifier(
-   dir => "/home/ian/things/Nj-awaymsg/nj-awaymsg.git/data",
-   CGI::Auth::Flexible->mason_params();
-   );
-my $authreq = $verifier->new_mason_request(\%ARGS);
-</%perl>
+
+sub do_redirect_mason ($$$$) {
+    my ($c, $ar, $new_url, $cookie) = @_;
+    $m->auto_send_headers(0);
+    CGI::Auth::Flexible::do_redirect_cgi($c,$ar,$new_url,$cookie);
+}
+
+sub login_ok_self ($$) {
+    my ($c, $ar) = @_;
+    my $password = $c->param('password');
+    return $password eq 'sesame' ? ('self',undef) : (undef,'wrong');
+}
+
+our $verifier = CGI::Auth::Flexible->new_verifier(
+    dir => "$ENV{'NJAWAYMSG'}/data",
+#    do_redirect => \&do_redirect_mason,
+    handle_divert => sub { $m->auto_send_headers(0); return 0; },
+#    print => sub { my ($c,$ar,@t) = @_; $m->print(@t); },
+    encrypted_only => 0,
+    username_param_names => [],
+    login_ok => \&login_ok_self,
+    );
+</%once>
+<%shared>
+our $cgi = $m->cgi_object();
+our $ar = $verifier->new_request($cgi);
+</%shared>
+% if ($ar->check_ok()) {
+%    $m->call_next();
+<hr>
+<form method="POST" action="<% $ENV{'URL'} %>">
+<% $ar->secret_hidden_html() %>
+<input type="submit" name="caf_logout" value="Logout">
+</form>
+% }