Request.pm 5.69 KB
Newer Older
Yadd's avatar
Yadd committed
1 2
package Lemonldap::NG::Portal::Main::Request;

Yadd's avatar
Yadd committed
3
# Developpers, be careful: new() is never called so default values will not be
Yadd's avatar
Yadd committed
4
# taken in account (see Portal::Run::handler()): set default values in init()
Yadd's avatar
Yadd committed
5

Yadd's avatar
Yadd committed
6 7
use strict;
use Mouse;
Yadd's avatar
Yadd committed
8
use Lemonldap::NG::Portal::Main::Constants ':all';
Yadd's avatar
Yadd committed
9 10 11

extends 'Lemonldap::NG::Common::PSGI::Request';

Yadd's avatar
Yadd committed
12
# List of methods to call
Yadd's avatar
Yadd committed
13
has steps => ( is => 'rw' );
Yadd's avatar
Yadd committed
14 15

# Datas shared between methods
Yadd's avatar
Yadd committed
16
has datas => ( is => 'rw' );
Yadd's avatar
Yadd committed
17 18

# Session datas when created
Yadd's avatar
Yadd committed
19
has id          => ( is => 'rw' );
Yadd's avatar
Yadd committed
20
has sessionInfo => ( is => 'rw' );
Yadd's avatar
Yadd committed
21
has user        => ( is => 'rw' );
Yadd's avatar
Yadd committed
22 23

# Response cookies (list of strings built by cookie())
Yadd's avatar
Yadd committed
24
has respCookies => ( is => 'rw' );
Yadd's avatar
Yadd committed
25

26 27 28
# Embedded response
has response => ( is => 'rw' );

Yadd's avatar
Yadd committed
29
# Template to display (if not defined, login or menu)
Yadd's avatar
Yadd committed
30 31
has template => ( is => 'rw' );

Yadd's avatar
Yadd committed
32
# Custom template parameters
Yadd's avatar
Yadd committed
33
has customParameters => ( is => 'rw' );
Yadd's avatar
Yadd committed
34

Yadd's avatar
Yadd committed
35 36 37
# Boolean to indicate that response must be a redirection
has mustRedirect => ( is => 'rw' );

Yadd's avatar
Yadd committed
38
# Store URL for redirections
Yadd's avatar
Yadd committed
39 40 41 42 43 44 45
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' );
Yadd's avatar
Yadd committed
46

Yadd's avatar
Yadd committed
47 48 49
# "check logins "flag"
has checkLogins => ( is => 'rw' );

Yadd's avatar
Yadd committed
50 51
# Boolean to indicate that url isn't Base64 encoded
has urlNotBase64 => ( is => 'rw' );
Yadd's avatar
Yadd committed
52

Yadd's avatar
Yadd committed
53 54 55
# Menu error
has menuError => ( is => 'rw' );

Yadd's avatar
Yadd committed
56 57 58
# Frame flag (used by Run to not send Content-Security-Policy header)
has frame => ( is => 'rw' );

Yadd's avatar
Yadd committed
59 60 61 62 63 64 65 66
# Security
#
# Captcha
has captcha => ( is => 'rw' );

# Token
has token => ( is => 'rw' );

Yadd's avatar
Yadd committed
67 68
# Error type
sub error_type {
Yadd's avatar
Yadd committed
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
    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";
Yadd's avatar
Yadd committed
104 105 106 107

    #TODO
}

Yadd's avatar
Yadd committed
108 109
sub init {
    my ($self) = @_;
Yadd's avatar
Yadd committed
110 111
    $self->{$_} = {} foreach (qw(datas customParameters sessionInfo));
    $self->{$_} = [] foreach (qw(respCookies));
Yadd's avatar
Yadd committed
112 113
}

Yadd's avatar
Yadd committed
114
sub errorString {
Yadd's avatar
Yadd committed
115
    print STDERR "TODO Request::errorString()\n";
Yadd's avatar
Yadd committed
116 117 118
}

sub loginInfo {
Yadd's avatar
Yadd committed
119 120 121 122
    print STDERR "TODO Request::loginInfo()\n";
}

sub info {
Yadd's avatar
Yadd committed
123 124 125
    my ( $self, $info ) = @_;
    $self->datas->{_info} .= $info if ( defined $info );
    return $self->datas->{_info};
Yadd's avatar
Yadd committed
126 127
}

Yadd's avatar
Yadd committed
128 129 130 131 132
sub addCookie {
    my ( $self, $cookie ) = @_;
    push @{ $self->respHeaders }, 'Set-Cookie' => $cookie;
}

Yadd's avatar
Yadd committed
133
# TODO: oldpassword
Yadd's avatar
Yadd committed
134
1;
Yadd's avatar
Yadd committed
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
__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

Yadd's avatar
Yadd committed
155 156 157
Lemonldap::NG::Portal::Main::Request extends
L<Lemonldap::NG::Common::PSGI::Request> to add all parameters needed to manage
portal jobs.
Yadd's avatar
Yadd committed
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213

=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

Yadd's avatar
Yadd committed
214
L<http://lemonldap-ng.org/>, L<Lemonldap::NG::Common::PSGI::Request>
Yadd's avatar
Yadd committed
215 216 217 218 219

=head1 AUTHORS

=over

Yadd's avatar
Yadd committed
220
=item LemonLDAP::NG team L<http://lemonldap-ng.org/team>
Yadd's avatar
Yadd committed
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235

=back

=head1 BUG REPORT

Use OW2 system to report bug or ask for features:
L<http://jira.ow2.org>

=head1 DOWNLOAD

Lemonldap::NG is available at
L<http://forge.objectweb.org/project/showfiles.php?group_id=274>

=head1 COPYRIGHT AND LICENSE

Yadd's avatar
Yadd committed
236
See COPYING file for details.
Yadd's avatar
Yadd committed
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251

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