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

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

Yadd's avatar
Yadd committed
6 7
use strict;
use Mouse;
Yadd's avatar
Yadd committed
8
use Lemonldap::NG::Portal::Main::Constants;
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', default => sub { {} } );
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

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

# Boolean to indicate that response must be a redirection
has mustRedirect => ( is => 'rw' );

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

Yadd's avatar
Yadd committed
35 36 37 38 39 40 41 42 43 44 45 46
# Info to display at login
has info => ( is => 'rw' );

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

# Notification
has notification => ( is => 'rw' );

has _authChoice   => ( is => 'rw' );
has _openidPortal => ( is => 'rw' );

Yadd's avatar
Yadd committed
47 48 49 50
sub wantJSON {
    return $_[0]->accept =~ m#(?:application|text)/json# ? 1 : 0;
}

Yadd's avatar
Yadd committed
51 52
# Error type
sub error_type {
Yadd's avatar
Yadd committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
    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
88 89 90 91 92 93 94 95 96 97 98 99 100

    #TODO
}

sub errorString {

    #TODO
}

sub loginInfo {
}

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