Request.pm 3.91 KB
Newer Older
Yadd's avatar
Yadd committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# Lemonldap::NG::Portal::Main::Request extends Lemonldap::NG::Common::PSGI::Request
# to add all parameters needed to manage authentication:
#
#  - steps: list of methods to call
#  - datas: free hash ref where plugins can store their datas
#  - user infos:
#    * id: Apache::Session id
#    * sessionInfo: hash ref that will be stored in session DB
#    * user: username given by authentication module, used by userDB module
#  - query elements:
#    * mustRedirect: boolean to indicate that response must be a redirection
#    * urlNotBase64: boolean to indicate that url isn't Base64 encoded
#  - menu elements:
#    * info: info to display at login
#    * menuError
#    * notification: see notification plugin
#    * errorType: returns positive/warning/negative depending on error (stored
#                 in error property)
Yadd's avatar
Yadd committed
19 20
package Lemonldap::NG::Portal::Main::Request;

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

Yadd's avatar
Yadd committed
24 25
use strict;
use Mouse;
Yadd's avatar
Yadd committed
26
use Lemonldap::NG::Portal::Main::Constants ':all';
Yadd's avatar
Yadd committed
27 28 29

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

Yadd's avatar
Yadd committed
30
# List of methods to call
Yadd's avatar
Yadd committed
31
has steps => ( is => 'rw' );
Yadd's avatar
Yadd committed
32 33

# Datas shared between methods
Yadd's avatar
Yadd committed
34
has datas => ( is => 'rw' );
Yadd's avatar
Yadd committed
35 36

# Session datas when created
Yadd's avatar
Yadd committed
37
has id          => ( is => 'rw' );
Yadd's avatar
Yadd committed
38
has sessionInfo => ( is => 'rw' );
Yadd's avatar
Yadd committed
39
has user        => ( is => 'rw' );
Yadd's avatar
Yadd committed
40 41

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

44 45 46
# Embedded response
has response => ( is => 'rw' );

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

Yadd's avatar
Yadd committed
50
# Custom template parameters
Yadd's avatar
Yadd committed
51
has customParameters => ( is => 'rw' );
Yadd's avatar
Yadd committed
52

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

Yadd's avatar
Yadd committed
56
# Store URL for redirections
Yadd's avatar
Yadd committed
57 58 59 60 61 62 63
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
64

Yadd's avatar
Yadd committed
65 66 67
# "check logins "flag"
has checkLogins => ( is => 'rw' );

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

Yadd's avatar
Yadd committed
71 72 73 74 75 76 77 78
# Info to display at login
has info => ( is => 'rw' );

# Menu error
has menuError => ( is => 'rw' );

# Error type
sub error_type {
Yadd's avatar
Yadd committed
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 106 107 108 109 110 111 112 113
    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
114 115 116 117

    #TODO
}

Yadd's avatar
Yadd committed
118 119
sub init {
    my ($self) = @_;
Yadd's avatar
Yadd committed
120 121
    $self->{$_} = {} foreach (qw(datas customParameters sessionInfo));
    $self->{$_} = [] foreach (qw(respCookies));
Yadd's avatar
Yadd committed
122 123
}

Yadd's avatar
Yadd committed
124
sub errorString {
Yadd's avatar
Yadd committed
125
    print STDERR "TODO Request::errorString()\n";
Yadd's avatar
Yadd committed
126 127 128
}

sub loginInfo {
Yadd's avatar
Yadd committed
129 130 131 132
    print STDERR "TODO Request::loginInfo()\n";
}

sub info {
Yadd's avatar
Yadd committed
133 134 135
    my ( $self, $info ) = @_;
    $self->datas->{_info} .= $info if ( defined $info );
    return $self->datas->{_info};
Yadd's avatar
Yadd committed
136 137 138
}

# TODO: oldpassword
Yadd's avatar
Yadd committed
139
1;