Request.pm 5.71 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

Yadd's avatar
Yadd committed
10 11
our $VERSION = '2.0.0';

Yadd's avatar
Yadd committed
12 13
extends 'Lemonldap::NG::Common::PSGI::Request';

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

Yadd's avatar
Yadd committed
17 18 19
# Authentication result
has authResult => ( is => 'rw' );

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

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

28 29 30
# Embedded response
has response => ( is => 'rw' );

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

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

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

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

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

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

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

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

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

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

Yadd's avatar
Yadd committed
69 70
# Error type
sub error_type {
Yadd's avatar
Yadd committed
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 104 105
    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
106 107 108 109

    #TODO
}

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

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

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

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

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

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

=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
216
L<http://lemonldap-ng.org/>, L<Lemonldap::NG::Common::PSGI::Request>
Yadd's avatar
Yadd committed
217 218 219 220 221

=head1 AUTHORS

=over

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

=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
238
See COPYING file for details.
Yadd's avatar
Yadd committed
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253

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