use PciIds::Html::Forms;
use PciIds::Email;
use PciIds::Users;
+use PciIds::Address;
use CGI;
use CGI::Cookie;
use Apache2::Const qw(:common);
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 '<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>';
"\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();
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="">';
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>
genHtmlTail();
return 0;
} elsif( $tables->hasEmail( $email ) ) {
- return usedAddress( $req );
+ return usedAddress( $req, $args );
} else {
return 1;
}
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 );
},
'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;
}
$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"' ],
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 {
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 );
"\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 ) );
}
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="">
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 {
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>';
[ '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;
}
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' ];
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( $$$ ) {
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";
}