lemonldap-ng/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Request.pm

254 lines
5.7 KiB
Perl
Raw Normal View History

2016-03-30 21:51:15 +02:00
package Lemonldap::NG::Portal::Main::Request;
2016-04-03 08:33:50 +02:00
# Developpers, be careful: new() is never called so default values will not be
2016-05-31 13:47:10 +02:00
# taken in account (see Portal::Run::handler()): set default values in init()
2016-04-03 08:33:50 +02:00
2016-03-30 21:51:15 +02:00
use strict;
use Mouse;
2016-05-22 14:22:59 +02:00
use Lemonldap::NG::Portal::Main::Constants ':all';
2016-03-30 21:51:15 +02:00
2017-02-28 21:53:19 +01:00
our $VERSION = '2.0.0';
2016-03-30 21:51:15 +02:00
extends 'Lemonldap::NG::Common::PSGI::Request';
2016-04-02 22:17:39 +02:00
# List of methods to call
2016-04-03 08:33:50 +02:00
has steps => ( is => 'rw' );
2016-04-02 22:17:39 +02:00
2017-02-19 08:17:48 +01:00
# Authentication result
has authResult => ( is => 'rw' );
2016-04-02 22:17:39 +02:00
# Session datas when created
2016-04-01 12:10:42 +02:00
has id => ( is => 'rw' );
2016-04-01 07:24:27 +02:00
has sessionInfo => ( is => 'rw' );
2016-04-04 07:08:26 +02:00
has user => ( is => 'rw' );
2016-04-02 22:17:39 +02:00
# Response cookies (list of strings built by cookie())
2016-04-01 12:10:42 +02:00
has respCookies => ( is => 'rw' );
2016-03-31 22:08:43 +02:00
# Embedded response
has response => ( is => 'rw' );
2016-04-02 22:17:39 +02:00
# Template to display (if not defined, login or menu)
2016-04-03 08:33:50 +02:00
has template => ( is => 'rw' );
2016-05-23 23:52:29 +02:00
# Custom template parameters
2016-05-23 23:52:32 +02:00
has customParameters => ( is => 'rw' );
2016-05-23 23:52:29 +02:00
2016-04-03 08:33:50 +02:00
# Boolean to indicate that response must be a redirection
has mustRedirect => ( is => 'rw' );
2016-05-23 18:55:23 +02:00
# Store URL for redirections
2016-11-22 13:34:09 +01:00
has urldc => ( is => 'rw' );
has postUrl => ( is => 'rw' );
has postFields => ( is => 'rw' );
has portalHiddenFormValues => ( is => 'rw' );
# Flag that permit to a auth module to return PE_OK without setting $user
has continue => ( is => 'rw' );
2016-05-23 18:55:23 +02:00
2016-09-22 22:12:56 +02:00
# "check logins "flag"
has checkLogins => ( is => 'rw' );
2016-04-03 08:33:50 +02:00
# Boolean to indicate that url isn't Base64 encoded
has urlNotBase64 => ( is => 'rw' );
2016-04-02 22:17:39 +02:00
2016-04-07 23:31:56 +02:00
# Menu error
has menuError => ( is => 'rw' );
2017-01-20 07:19:54 +01:00
# Frame flag (used by Run to not send Content-Security-Policy header)
has frame => ( is => 'rw' );
2017-01-24 23:05:07 +01:00
# Security
#
# Captcha
has captcha => ( is => 'rw' );
# Token
has token => ( is => 'rw' );
2016-04-07 23:31:56 +02:00
# Error type
sub error_type {
2016-04-11 07:00:34 +02:00
my $req = shift;
my $code = shift || $req->error;
# Positive errors
return "positive"
if (
scalar(
grep { /^$code$/ } (
PE_REDIRECT, PE_DONE,
PE_OK, PE_PASSWORD_OK,
PE_MAILOK, PE_LOGOUT_OK,
PE_MAILFIRSTACCESS, PE_PASSWORDFIRSTACCESS,
PE_MAILCONFIRMOK, PE_REGISTERFIRSTACCESS,
)
)
);
# Warning errors
return "warning"
if (
scalar(
grep { /^$code$/ } (
PE_INFO, PE_SESSIONEXPIRED,
PE_FORMEMPTY, PE_FIRSTACCESS,
PE_PP_GRACE, PE_PP_EXP_WARNING,
PE_NOTIFICATION, PE_BADURL,
PE_CONFIRM, PE_MAILFORMEMPTY,
PE_MAILCONFIRMATION_ALREADY_SENT, PE_PASSWORDFORMEMPTY,
PE_CAPTCHAEMPTY, PE_REGISTERFORMEMPTY,
)
)
);
# Negative errors (default)
return "negative";
2016-04-07 23:31:56 +02:00
#TODO
}
2016-05-31 13:47:10 +02:00
sub init {
my ($self) = @_;
2016-11-22 09:05:43 +01:00
$self->{$_} = {} foreach (qw(datas customParameters sessionInfo));
$self->{$_} = [] foreach (qw(respCookies));
2016-05-31 13:47:10 +02:00
}
2016-04-07 23:31:56 +02:00
sub errorString {
2016-11-22 13:34:09 +01:00
print STDERR "TODO Request::errorString()\n";
2016-04-07 23:31:56 +02:00
}
sub loginInfo {
2016-11-22 13:34:09 +01:00
print STDERR "TODO Request::loginInfo()\n";
}
sub info {
my ( $self, $info ) = @_;
$self->datas->{_info} .= $info if ( defined $info );
return $self->datas->{_info};
2016-04-07 23:31:56 +02:00
}
2017-01-13 15:35:02 +01:00
sub addCookie {
my ( $self, $cookie ) = @_;
push @{ $self->respHeaders }, 'Set-Cookie' => $cookie;
}
2016-04-07 23:31:56 +02:00
# TODO: oldpassword
2016-03-30 21:51:15 +02:00
1;
2016-12-19 13:18:26 +01:00
__END__
=head1 NAME
=encoding utf8
Lemonldap::NG::Portal::Main::Request - HTTP request object used in LLNG
portal methods.
=head1 SYNOPSIS
# Somewhere in a plugin...
sub run {
my ( $self, $req ) = @_;
# $req is a Lemonldap::NG::Portal::Main::Request object
...
}
=head1 DESCRIPTION
2017-01-04 21:51:46 +01:00
Lemonldap::NG::Portal::Main::Request extends
L<Lemonldap::NG::Common::PSGI::Request> to add all parameters needed to manage
portal jobs.
2016-12-19 13:18:26 +01:00
=head1 METHODS
=head2 Accessors
=head3 steps()
Stack of methods to call for this requests. It can be modified to change
authentication process
=head3 datas()
Free hash ref where plugins can store their datas. Using it is a LLNG best
practice
=head3 User information
=head4 id()
Session id (main cookie value).
=head4 sessionInfo()
Hash ref that will be stored in session DB.
=head4 user()
Username given by authentication module, used by userDB module.
=head3 mustRedirect()
Boolean to indicate that response must be a redirection (used for example when
request is a POST).
=head3 urlNotBase64
Boolean to indicate that url isn't Base64 encoded.
=head2 Other methods
=head3 info()
Store info to display in response.
=head3 menuError()
=head3 notification()
see notification plugin.
=head3 errorType()
Returns positive/warning/negative depending on value stored in error property.
=head1 SEE ALSO
2017-01-04 21:51:46 +01:00
L<http://lemonldap-ng.org/>, L<Lemonldap::NG::Common::PSGI::Request>
2016-12-19 13:18:26 +01:00
=head1 AUTHORS
=over
2017-01-04 21:51:46 +01:00
=item LemonLDAP::NG team L<http://lemonldap-ng.org/team>
2016-12-19 13:18:26 +01:00
=back
=head1 BUG REPORT
Use OW2 system to report bug or ask for features:
2017-11-11 14:06:23 +01:00
L<https://gitlab.ow2.org/lemonldap-ng/lemonldap-ng/issues>
2016-12-19 13:18:26 +01:00
=head1 DOWNLOAD
Lemonldap::NG is available at
L<http://forge.objectweb.org/project/showfiles.php?group_id=274>
=head1 COPYRIGHT AND LICENSE
2017-01-04 21:51:46 +01:00
See COPYING file for details.
2016-12-19 13:18:26 +01:00
This library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see L<http://www.gnu.org/licenses/>.
=cut