From: Michal Vaner Date: Fri, 29 Aug 2008 21:35:04 +0000 (+0200) Subject: Put a menu into all user-oriented forms X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=877f5a25bfcc6785028587f4e98b66080132d9ad;p=pciids.git Put a menu into all user-oriented forms --- diff --git a/PciIds/Html/List.pm b/PciIds/Html/List.pm index fdd17c2..875640b 100644 --- a/PciIds/Html/List.pm +++ b/PciIds/Html/List.pm @@ -25,10 +25,10 @@ sub list( $$$$ ) { my $id = $address->pretty(); genHtmlHead( $req, $id, undef ); print '

'.encode( $id ).'

'; - genMenu( $address, $args, $auth ); + genMenu( $req, $address, $args, $auth ); print htmlDiv( 'name', '

'.encode( $name ) ) if( defined( $name ) ); print htmlDiv( 'note', '

'.encode( $note ) ) if( defined( $note ) ); - genPath( $address, 0 ); + genPath( $req, $address, 0 ); my $diss = 0; my $history; foreach $history ( @{$tables->history( $address->get() )} ) { diff --git a/PciIds/Html/Users.pm b/PciIds/Html/Users.pm index 69c03c1..d665596 100644 --- a/PciIds/Html/Users.pm +++ b/PciIds/Html/Users.pm @@ -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 ¬LoggedComplaint); +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 '

Register a new user

'; + genLocMenu( $req, $args, [ [ 'Log in', 'login' ] ] ); print '
'.$error.'
' if( defined $error ); print '
'; @@ -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 '

Register email sent

-

+ print "

Register email sent

\n"; + genLocMenu( $req, $args, [ [ 'Log in', 'login' ] ] ); + print '

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 '

Confirm registration

'; + genLocMenu( $req, $args, [ [ 'Register', 'register' ] ] ); print '
'.$error.'
' if( defined $error ); print '

Email address: '.encode( $values->{'email'} ); print ''; @@ -86,21 +97,22 @@ sub genConfirmForm( $$$$ ) { return OK; } -sub usedAddress( $ ) { - my( $req ) = @_; +sub usedAddress( $$ ) { + my( $req, $args ) = @_; genHtmlHead( $req, 'Used address', undef ); - print '

Used address

-
+ print "

Used address

\n"; + genLocMenu( $req, $args, [ [ 'Log in', 'login' ], [ 'Reset password', 'respass' ], [ 'Register', 'register' ] ] ); + print '

An account for this address is already registered. - Please, start again with requesting a registration email or log in. + Please, reset or remember your password or start again with a different address.

'; 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 '

Invalid registration request

@@ -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 '

Registered

-

- You are now registered. - You can continue by logging in or continue anonymously.'; + print "

Registered

\n"; + genLocMenu( $req, $args, [ [ 'Log in', 'login' ] ] ); + print '

+ 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 '

Login

'; - my $addr = PciIds::Address::new( $req->uri() ); - genCustomMenu( $addr, $args, [ [ 'Register', 'register' ], [ 'Reset password', 'respass' ] ] ); + genLocMenu( $req, $args, [ [ 'Register', 'register' ], [ 'Reset password', 'respass' ] ] ); print '

'.$error.'

' if( defined $error ); print '
'; 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 '

Logged in

'; + genPath( $req, PciIds::Address::new( $req->uri() ), 1 ); + print '

You are logged in.'; print '

'.encode( $last ).'

' if( defined( $last ) ); - print "

Continue here"; genHtmlTail(); return OK; } else { @@ -248,6 +260,7 @@ sub genResetPasswdForm( $$$$ ) { my( $req, $args, $error, $values ) = @_; genHtmlHead( $req, 'Reset password', undef ); print "

Reset password

\n"; + genLocMenu( $req, $args, [ [ 'Log in', 'login' ], [ 'Register', 'register' ] ] ); print "

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 '

'.$error.'
' 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 "

Reset password

\n"; - print "

An email with information was sent to your address.\n"; + genLocMenu( $req, $args, [ [ 'Log in', 'login' ] ] ); + print "

An email with information has been sent to your address.\n"; genHtmlTail(); return OK; } else { - $error = '

This email address is not registered. Check it for typos or register it.'; + $error = '

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 "

Reset password

\n"; + genLocMenu( $req, $args, [ [ 'Log in', 'login' ] ] ); print '
'.$error.'
' if( defined $error ); print "

You can enter new password here:\n"; print ' @@ -349,7 +364,8 @@ sub resetPasswdConfirmFormSubmit( $$$ ) { changePasswd( $tables, $id, $data->{'password'}, $email ); genHtmlHead( $req, 'Reset password', undef ); print "

Reset password

\n"; - print "

Your password was successfuly changed. You can log in.\n"; + genLocMenu( $req, $args, [ [ 'Log in', 'login' ] ] ); + print "

Your password was successfuly changed.\n"; genHtmlTail(); return OK; } else { @@ -365,6 +381,7 @@ sub genProfileForm( $$$$$ ) { delete $data->{'confirm_password'}; delete $data->{'password'}; print "

User profile

\n"; + genLocMenu( $req, $args, [ [ 'Log out', 'logout' ], [ 'Notifications', 'notifications' ] ] ); print '

'.$error.'

' if defined $error; print "

$info

\n" if defined $info; print '
'; @@ -378,7 +395,6 @@ sub genProfileForm( $$$$$ ) { [ 'Xmpp batch time (min):', 'text', 'xmpp_time', 'maxlength="10"' ], [ '', 'submit', 'profile', 'value="Submit"' ] ], $data ); print '
'; - print "

Back to browsing\n"; genHtmlTail(); return OK; } diff --git a/PciIds/Html/Util.pm b/PciIds/Html/Util.pm index f29f872..1c4b339 100644 --- a/PciIds/Html/Util.pm +++ b/PciIds/Html/Util.pm @@ -39,21 +39,21 @@ sub item( $$$ ) { print "

  • $label\n"; } -sub genCustomMenu( $$$ ) { - my( $address, $args, $list ) = @_; +sub genCustomMenu( $$$$ ) { + my( $req, $address, $args, $list ) = @_; my $url = '/'.$address->get().buildExcept( 'action', $args ).'?action='; print "\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 "\n"; }