]> mj.ucw.cz Git - pciids.git/commitdiff
Put a menu into all user-oriented forms
authorMichal Vaner <vorner@ucw.cz>
Fri, 29 Aug 2008 21:35:04 +0000 (23:35 +0200)
committerMichal Vaner <vorner@ucw.cz>
Fri, 29 Aug 2008 21:35:04 +0000 (23:35 +0200)
PciIds/Html/List.pm
PciIds/Html/Users.pm
PciIds/Html/Util.pm

index fdd17c23e57fd9a21493e759c578d0ae6a7c15b8..875640b1501a0100ad03df71b9212758ff953f32 100644 (file)
@@ -25,10 +25,10 @@ sub list( $$$$ ) {
        my $id = $address->pretty();
        genHtmlHead( $req, $id, undef );
        print '<h1>'.encode( $id ).'</h1>';
-       genMenu( $address, $args, $auth );
+       genMenu( $req, $address, $args, $auth );
        print htmlDiv( 'name', '<p>'.encode( $name ) ) if( defined( $name ) );
        print htmlDiv( 'note', '<p>'.encode( $note ) ) if( defined( $note ) );
-       genPath( $address, 0 );
+       genPath( $req, $address, 0 );
        my $diss = 0;
        my $history;
        foreach $history ( @{$tables->history( $address->get() )} ) {
index 69c03c109b61bdb4e42d7c09850997b88f7450ef..d665596686c0d2de6699c3c1a5f54ddedf15f3f8 100644 (file)
@@ -5,6 +5,7 @@ use PciIds::Html::Util;
 use PciIds::Html::Forms;
 use PciIds::Email;
 use PciIds::Users;
+use PciIds::Address;
 use CGI;
 use CGI::Cookie;
 use Apache2::Const qw(:common);
@@ -15,10 +16,18 @@ use base 'Exporter';
 
 our @EXPORT = qw(&checkLogin &notLoggedComplaint);
 
+sub genLocMenu( $$$ ) {
+       my( $req, $args, $actions ) = @_;
+       my $addr = PciIds::Address::new( $req->uri() );
+       genCustomMenu( $req, $addr, $args, $actions );
+       genPath( $req, $addr, 1 );
+}
+
 sub genRegisterForm( $$$$ ) {
        my( $req, $args, $error, $values ) = @_;
        genHtmlHead( $req, 'Register a new user', undef );
        print '<h1>Register a new user</h1>';
+       genLocMenu( $req, $args, [ [ 'Log in', 'login' ] ] );
        print '<div class="error">'.$error.'</div>' if( defined $error );
        print '<form name="register" id="register" method="POST" action="">
                <table>';
@@ -60,8 +69,9 @@ sub registerSubmit( $$$ ) {#A registration form has been submited
                "\nThank you\n".
                "\n(This is an autogenerated email, do not respond to it)" );
        genHtmlHead( $req, 'Registration email sent', undef );
-       print '<h1>Register email sent</h1>
-               <p>
+       print "<h1>Register email sent</h1>\n";
+       genLocMenu( $req, $args, [ [ 'Log in', 'login' ] ] );
+       print '<p>
                        An email containing further information has been sent to you.
                        Please follow these instruction to finish the registration process.';
        genHtmlTail();
@@ -72,6 +82,7 @@ sub genConfirmForm( $$$$ ) {
        my( $req, $args, $error, $values ) = @_;
        genHtmlHead( $req, 'Confirm registration', undef );
        print '<h1>Confirm registration</h1>';
+       genLocMenu( $req, $args, [ [ 'Register', 'register' ] ] );
        print '<div class="error">'.$error.'</div>' if( defined $error );
        print '<p>Email address: '.encode( $values->{'email'} );
        print '<form name="register-confirm" id="register-confirm" method="POST" action="">';
@@ -86,21 +97,22 @@ sub genConfirmForm( $$$$ ) {
        return OK;
 }
 
-sub usedAddress( $ ) {
-       my( $req ) = @_;
+sub usedAddress( $$ ) {
+       my( $req, $args ) = @_;
        genHtmlHead( $req, 'Used address', undef );
-       print '<h1>Used address</h1>
-               <div class="error">
+       print "<h1>Used address</h1>\n";
+       genLocMenu( $req, $args, [ [ 'Log in', 'login' ], [ 'Reset password', 'respass' ], [ 'Register', 'register' ] ] );
+       print '<div class="error">
                <p>
                        An account for this address is already registered.
-                       Please, start again with <a href="'.setAddrPrefix( $req->uri(), 'mods' ).'?action=register">requesting a registration email</a> or <a href="'.setAddrPrefix( $req->uri(), 'mods' ).'?action=login">log in</a>.
+                       Please, reset or remember your password or start again with a different address.
                </div>';
        genHtmlTail();
        return 0;
 }
 
-sub checkRegHash( $$$$ ) {
-       my( $req, $tables, $email, $hash ) = @_;
+sub checkRegHash( $$$$$ ) {
+       my( $req, $args, $tables, $email, $hash ) = @_;
        if( ! checkConfirmHash( $email, $hash ) ) {
                genHtmlHead( $req, 'Invalid registration request', undef );
                print '<h1>Invalid registration request</h1>
@@ -112,7 +124,7 @@ sub checkRegHash( $$$$ ) {
                genHtmlTail();
                return 0;
        } elsif( $tables->hasEmail( $email ) ) {
-               return usedAddress( $req );
+               return usedAddress( $req, $args );
        } else {
                return 1;
        }
@@ -121,7 +133,7 @@ sub checkRegHash( $$$$ ) {
 sub confirmForm( $$$$ ) {
        my( $req, $args, $tables, $auth ) = @_;
        return HTTPRedirect( $req, 'https://'.$req->hostname().$req->uri().buildArgs( $args ) ) unless $auth->{'ssl'};
-       if( ! checkRegHash( $req, $tables, $args->{'email'}, $args->{'confirm'} ) ) {
+       if( ! checkRegHash( $req, $args, $tables, $args->{'email'}, $args->{'confirm'} ) ) {
                return OK;
        } else {
                return genConfirmForm( $req, $args, undef, $args );
@@ -150,17 +162,17 @@ sub confirmSubmit( $$$ ) {
                },
                'password' => \&passLenCheck,
                'confirm_password' => undef }, [ \&passSameCheck ] );
-       return OK if( ! checkRegHash( $req, $tables, $data->{'email'}, $data->{'confirm'} ) );#Not much info, but this is an attack anyway
+       return OK if( ! checkRegHash( $req, $args, $tables, $data->{'email'}, $data->{'confirm'} ) );#Not much info, but this is an attack anyway
        return genConfirmForm( $req, $args, $error, $data ) if( defined $error );
        unless( addUser( $tables, $data->{'login'}, $data->{'email'}, $data->{'password'} ) ) {
-               usedAddress( $req );
+               usedAddress( $req, $args );
                return OK;
        }
        genHtmlHead( $req, 'Registered', undef );
-       print '<h1>Registered</h1>
-               <p>
-                       You are now registered.
-                       You can continue by <a href="'.setAddrPrefix( $req->uri(), 'mods' ).buildExcept( 'action', $args ).'?action=login">logging in</a> or continue <a href="http://'.$req->hostname().setAddrPrefix( $req->uri(), 'read' ).buildExcept( 'action', $args ).'?action=list">anonymously</a>.';
+       print "<h1>Registered</h1>\n";
+       genLocMenu( $req, $args, [ [ 'Log in', 'login' ] ] );
+       print '<p>
+                       You have registered successfully.';
        genHtmlTail();
        return OK;
 }
@@ -170,8 +182,7 @@ sub genLoginForm( $$$$ ) {
        $req->headers_out->add( 'Set-Cookie' => new CGI::Cookie( -name => 'cookie-test', -value => 1 ) );
        genHtmlHead( $req, 'Login', undef );
        print '<h1>Login</h1>';
-       my $addr = PciIds::Address::new( $req->uri() );
-       genCustomMenu( $addr, $args, [ [ 'Register', 'register' ], [ 'Reset password', 'respass' ] ] );
+       genLocMenu( $req, $args, [ [ 'Register', 'register' ], [ 'Reset password', 'respass' ] ] );
        print '<div class="error"><p>'.$error.'</div>' if( defined $error );
        print '<form name="login" id="login" method="POST" action="'.setAddrPrefix( $req->uri(), 'mods' ).buildExcept( 'action', $args ).'?action=login"><table>';
        genForm( [ [ 'Login name or email:', 'text', 'login', 'maxlength="255"' ],
@@ -211,8 +222,9 @@ sub loginSubmit( $$$ ) {
                my $url = "http://".$req->hostname().setAddrPrefix( $req->uri(), $prefix ).buildExcept( 'redirectaction', $args );
                genHtmlHead( $req, 'Logged in', undef );
                print '<h1>Logged in</h1>';
+               genPath( $req, PciIds::Address::new( $req->uri() ), 1 );
+               print '<p>You are logged in.';
                print '<div class="lastlog"><p>'.encode( $last ).'</div>' if( defined( $last ) );
-               print "<p><a href='$url'>Continue here</a>";
                genHtmlTail();
                return OK;
        } else {
@@ -248,6 +260,7 @@ sub genResetPasswdForm( $$$$ ) {
        my( $req, $args, $error, $values ) = @_;
        genHtmlHead( $req, 'Reset password', undef );
        print "<h1>Reset password</h1>\n";
+       genLocMenu( $req, $args, [ [ 'Log in', 'login' ], [ 'Register', 'register' ] ] );
        print "<p>If you forgot your password (or didn't create one yet), you can reset it to a new value here.\n";
        print "Provide your email address here and further instructions will be sent to you.\n";
        print '<div class="error">'.$error.'</div>' if( defined $error );
@@ -284,11 +297,12 @@ sub resetPasswdFormSubmit( $$$ ) {
                        "\n(This is an autogenerated email, do not respond to it)" );
                genHtmlHead( $req, 'Reset password', undef );
                print "<h1>Reset password</h1>\n";
-               print "<p>An email with information was sent to your address.\n";
+               genLocMenu( $req, $args, [ [ 'Log in', 'login' ] ] );
+               print "<p>An email with information has been sent to your address.\n";
                genHtmlTail();
                return OK;
        } else {
-               $error = '<p>This email address is not registered. Check it for typos or <a href="'.setAddrPrefix( $req->uri(), 'mods' ).buildExcept( 'action', $args ).'?action=register">register</a> it.';
+               $error = '<p>This email address is not registered. Check it for typos or register it.';
        }
        return genResetPasswdForm( $req, $args, $error, $data ) if( defined( $error ) );
 }
@@ -297,6 +311,7 @@ sub genResetPasswdConfigForm( $$$$$$ ) {
        my( $req, $args, $error, $values, $email, $hash ) = @_;
        genHtmlHead( $req, 'Reset password', undef );
        print "<h1>Reset password</h1>\n";
+       genLocMenu( $req, $args, [ [ 'Log in', 'login' ] ] );
        print '<div class="error">'.$error.'</div>' if( defined $error );
        print "<p>You can enter new password here:\n";
        print '<form name="respass-confirm" id="respass-confirm" method="POST" action="">
@@ -349,7 +364,8 @@ sub resetPasswdConfirmFormSubmit( $$$ ) {
                        changePasswd( $tables, $id, $data->{'password'}, $email );
                        genHtmlHead( $req, 'Reset password', undef );
                        print "<h1>Reset password</h1>\n";
-                       print "<p>Your password was successfuly changed. You can <a href='".$req->uri()."?action=login'>log in</a>.\n";
+                       genLocMenu( $req, $args, [ [ 'Log in', 'login' ] ] );
+                       print "<p>Your password was successfuly changed.\n";
                        genHtmlTail();
                        return OK;
                } else {
@@ -365,6 +381,7 @@ sub genProfileForm( $$$$$ ) {
        delete $data->{'confirm_password'};
        delete $data->{'password'};
        print "<h1>User profile</h1>\n";
+       genLocMenu( $req, $args, [ [ 'Log out', 'logout' ], [ 'Notifications', 'notifications' ] ] );
        print '<div class="error"><p>'.$error.'</div>' if defined $error;
        print "<div class='info'><p>$info</div>\n" if defined $info;
        print '<form name="profile" id="profile" method="POST" action=""><table>';
@@ -378,7 +395,6 @@ sub genProfileForm( $$$$$ ) {
                [ 'Xmpp batch time (min):', 'text', 'xmpp_time', 'maxlength="10"' ],
                [ '', 'submit', 'profile', 'value="Submit"' ] ], $data );
        print '</table></form>';
-       print "<p><a class='navigation' href='http://".$req->hostname().setAddrPrefix( $req->uri(), 'read' ).buildExcept( 'action', $args )."?action=list'>Back to browsing</a>\n";
        genHtmlTail();
        return OK;
 }
index f29f8728ab6e045f33906a0d76ee50cee02134bd..1c4b339c6cde2208df9ec09503a3a79ba28fe604 100644 (file)
@@ -39,21 +39,21 @@ sub item( $$$ ) {
        print "  <li><a href='".$url.$action."'>$label</a>\n";
 }
 
-sub genCustomMenu( $$$ ) {
-       my( $address, $args, $list ) = @_;
+sub genCustomMenu( $$$$ ) {
+       my( $req, $address, $args, $list ) = @_;
        my $url = '/'.$address->get().buildExcept( 'action', $args ).'?action=';
        print "<div class='menu'>\n<ul>\n";
        foreach( @{$list} ) {
                my( $label, $action ) = @{$_};
                my $prefix = '/mods';
                $prefix = '/read' if( !defined( $action ) or ( $action eq 'list' ) or ( $action eq '' ) );
-               item( $prefix.$url, $label, $action );
+               item( 'http://'.$req->hostname().$prefix.$url, $label, $action );
        }
        print "</ul></div>\n";
 }
 
-sub genMenu( $$$ ) {
-       my( $address, $args, $auth ) = @_;
+sub genMenu( $$$$ ) {
+       my( $req, $address, $args, $auth ) = @_;
        my @list;
        if( defined( $auth->{'authid'} ) ) {
                push @list, [ 'Log out', 'logout' ];
@@ -65,7 +65,7 @@ sub genMenu( $$$ ) {
        push @list, [ 'Administrate', 'admin' ] if( hasRight( $auth->{'accrights'}, 'validate' ) );
        push @list, [ 'Profile', 'profile' ] if defined $auth->{'authid'};
        push @list, [ 'Notifications', 'notifications' ] if defined $auth->{'authid'};
-       genCustomMenu( $address, $args, \@list );
+       genCustomMenu( $req, $address, $args, \@list );
 }
 
 sub genTableHead( $$$ ) {
@@ -120,15 +120,15 @@ sub HTTPRedirect( $$ ) {
        return HTTP_SEE_OTHER;
 }
 
-sub genPath( $$ ) {
-       my( $address, $printAddr ) = @_;
+sub genPath( $$$ ) {
+       my( $req, $address, $printAddr ) = @_;
        my $path = $address->path();
-       push @{$path}, $address if( $printAddr );
+       unshift @{$path}, $address if( $printAddr );
        print "<div class='navigation'><ul>\n";
        foreach my $addr ( @{$path} ) {
-               print "  <li><a href='/read/".$addr->get()."/'>".encode( $addr->pretty() )."</a>\n";
+               print "  <li><a href='http://".$req->hostname()."/read/".$addr->get()."/'>".encode( $addr->pretty() )."</a>\n";
        }
-       print "<li><a href='/index.html'>Main page</a>\n";
+       print "<li><a href='http://".$req->hostname()."/index.html'>Main page</a>\n";
        print "</div>\n";
 }