Register.pm 16.5 KB
Newer Older
Yadd's avatar
Yadd committed
1
2
3
package Lemonldap::NG::Portal::Plugins::Register;

use strict;
Yadd's avatar
Yadd committed
4
use Encode;
Yadd's avatar
Yadd committed
5
use Mouse;
Yadd's avatar
Yadd committed
6
use POSIX qw(strftime);
Yadd's avatar
Yadd committed
7
use Lemonldap::NG::Common::FormEncode;
Yadd's avatar
Yadd committed
8
use Lemonldap::NG::Portal::Main::Constants qw(
9
10
11
12
13
14
15
16
17
18
19
20
21
22
    PE_BADMAILTOKEN
    PE_CAPTCHAEMPTY
    PE_CAPTCHAERROR
    PE_MALFORMEDUSER
    PE_MAILCONFIRMATION_ALREADY_SENT
    PE_MAILCONFIRMOK
    PE_MAILERROR
    PE_MAILOK
    PE_NOTOKEN
    PE_OK
    PE_REGISTERALREADYEXISTS
    PE_REGISTERFIRSTACCESS
    PE_REGISTERFORMEMPTY
    PE_TOKENEXPIRED
Yadd's avatar
Yadd committed
23
24
);

Yadd's avatar
Yadd committed
25
our $VERSION = '2.0.1';
Yadd's avatar
Yadd committed
26
27

extends 'Lemonldap::NG::Portal::Main::Plugin',
28
    'Lemonldap::NG::Portal::Lib::SMTP';
Yadd's avatar
Yadd committed
29

Yadd's avatar
Yadd committed
30
31
# PROPERTIES

Yadd's avatar
Yadd committed
32
# Sub module (Demo, LDAP,...)
Yadd's avatar
Yadd committed
33
34
has registerModule => ( is => 'rw' );

Yadd's avatar
Yadd committed
35
# Register url to set in the mail
Yadd's avatar
Yadd committed
36
37
has registerUrl => (
    is      => 'rw',
38
    lazy    => 1,
Yadd's avatar
Yadd committed
39
40
41
42
43
44
45
    default => sub {
        my $p = $_[0]->conf->{portal};
        $p =~ s#/*$##;
        return "$p/register";
    }
);

Yadd's avatar
Yadd committed
46
47
# Mail timeout token generator
has mailott => (
Yadd's avatar
Yadd committed
48
    is      => 'rw',
49
    lazy    => 1,
Yadd's avatar
Yadd committed
50
    default => sub {
51
52
        my $ott = $_[0]->{p}
            ->loadModule('Lemonldap::NG::Portal::Lib::OneTimeToken');
Yadd's avatar
Yadd committed
53
        $ott->cache(0);
Yadd's avatar
Yadd committed
54
        $ott->timeout( $_[0]->conf->{registerTimeout}
55
                || $_[0]->conf->{timeout} );
56
        return $ott;
Yadd's avatar
Yadd committed
57
58
59
    }
);

Yadd's avatar
Yadd committed
60
61
62
63
# Form timout token generator (used if requireToken is set)
has ott => ( is => 'rw' );

# Captcha generator
Yadd's avatar
Yadd committed
64
65
has captcha => ( is => 'rw' );

Yadd's avatar
Yadd committed
66
67
68
69
# INITIALIZATION

sub init {
    my ($self) = @_;
Yadd's avatar
Yadd committed
70
71

    # Declare REST route
Yadd's avatar
Yadd committed
72
    $self->addUnauthRoute( register => 'register', [ 'POST', 'GET' ] );
Yadd's avatar
Yadd committed
73
74

    # Initialize Captcha if needed
Yadd's avatar
Yadd committed
75
    if ( $self->conf->{captcha_register_enabled} ) {
Yadd's avatar
Yadd committed
76
        $self->captcha( $self->p->loadModule('::Lib::Captcha') ) or return 0;
Yadd's avatar
Yadd committed
77
    }
Yadd's avatar
Yadd committed
78

Yadd's avatar
Yadd committed
79
80
81
82
    # Initialize form token if needed (captcha provides also a token)
    elsif ( $self->conf->{requireToken} ) {
        $_[0]->ott(
            $_[0]->p->loadModule('Lemonldap::NG::Portal::Lib::OneTimeToken') )
83
            or return 0;
Yadd's avatar
Yadd committed
84
        $_[0]->ott->timeout( $_[0]->conf->{formTimeout} );
Yadd's avatar
Yadd committed
85
    }
Yadd's avatar
Yadd committed
86

Yadd's avatar
Yadd committed
87
    # Load registered module
Yadd's avatar
Yadd committed
88
89
    $self->registerModule(
        $self->p->loadPlugin( '::Register::' . $self->conf->{registerDB} ) )
90
        or return 0;
Yadd's avatar
Yadd committed
91
92
93
94
95
96

    return 1;
}

# RUNNIG METHODS

Yadd's avatar
Yadd committed
97
# Handle register requests
Yadd's avatar
Yadd committed
98
99
sub register {
    my ( $self, $req ) = @_;
Yadd's avatar
Yadd committed
100

101
102
    $self->p->controlUrl($req);

Yadd's avatar
Yadd committed
103
    # Check parameters
Yadd's avatar
Yadd committed
104
    $req->error( $self->_register($req) );
Yadd's avatar
Yadd committed
105
106

    # Display form
Yadd's avatar
Yadd committed
107
108
109
110
    my ( $tpl, $prms ) = $self->display($req);
    return $self->p->sendHtml( $req, $tpl, params => $prms );
}

Yadd's avatar
Yadd committed
111
# Parameters check
Yadd's avatar
Yadd committed
112
113
sub _register {
    my ( $self, $req ) = @_;
114
    my %tplPrms;
Yadd's avatar
Yadd committed
115

Yadd's avatar
Yadd committed
116
    # Check if it's a first access
117
118
119
    unless ( ( $req->method =~ /^POST$/i and $req->param('mail') )
        or $req->param('register_token') )
    {
Yadd's avatar
Yadd committed
120
121
122

        # Set captcha or token
        $self->setSecurity($req);
Yadd's avatar
Yadd committed
123
        $self->logger->debug('First access to register form');
Yadd's avatar
Yadd committed
124
        return PE_REGISTERFIRSTACCESS if ( $req->method eq 'GET' );
Yadd's avatar
Yadd committed
125
126
127
        return PE_REGISTERFORMEMPTY;
    }

Yadd's avatar
Yadd committed
128
    # Get register token (mail link)
Yadd's avatar
Yadd committed
129
    $req->data->{register_token} = $req->param('register_token');
Yadd's avatar
Yadd committed
130
131

    # If a register token is present, find the corresponding info
Yadd's avatar
Yadd committed
132
    if ( $req->data->{register_token} ) {
Yadd's avatar
Yadd committed
133

Yadd's avatar
Yadd committed
134
        $self->logger->debug(
Yadd's avatar
Yadd committed
135
            "Token given for register: " . $req->data->{register_token} );
Yadd's avatar
Yadd committed
136
137

        # Get the corresponding session
138
139
        if ( my $data
            = $self->mailott->getToken( $req->data->{register_token} ) )
Yadd's avatar
Yadd committed
140
        {
Yadd's avatar
Yadd committed
141
            $self->logger->debug(
Yadd's avatar
Yadd committed
142
                'Token ' . $req->data->{register_token} . ' found' );
Yadd's avatar
Yadd committed
143
            foreach (qw(mail firstname lastname ipAddr)) {
Yadd's avatar
Yadd committed
144
                $req->data->{registerInfo}->{$_} = $data->{$_};
Yadd's avatar
Yadd committed
145
            }
Yadd's avatar
Yadd committed
146
            $self->logger->debug( "User associated to token: "
147
                    . $req->data->{registerInfo}->{mail} );
Yadd's avatar
Yadd committed
148
        }
Yadd's avatar
Yadd committed
149
150
151
        else {
            return PE_BADMAILTOKEN;
        }
Yadd's avatar
Yadd committed
152
    }
Yadd's avatar
Yadd committed
153
154

    # Case else: user tries to register
Yadd's avatar
Yadd committed
155
156
157
    else {

        # Use submitted value
Yadd's avatar
Yadd committed
158
159
160
161
        $req->data->{registerInfo}->{mail}      = $req->param('mail');
        $req->data->{registerInfo}->{firstname} = $req->param('firstname');
        $req->data->{registerInfo}->{lastname}  = $req->param('lastname');
        $req->data->{registerInfo}->{ipAddr}    = $req->address;
Yadd's avatar
Yadd committed
162

Yadd's avatar
Yadd committed
163
        # Check captcha/token only if register session does not already exist
Yadd's avatar
Yadd committed
164
        if ( $req->data->{registerInfo}->{mail}
Yadd's avatar
Yadd committed
165
            and
Yadd's avatar
Yadd committed
166
            !$self->getRegisterSession( $req->data->{registerInfo}->{mail} ) )
Yadd's avatar
Yadd committed
167
        {
Yadd's avatar
Yadd committed
168
169
170
171
172
173
            # Check if token exists
            my $token;
            if ( $self->ott or $self->captcha ) {
                $token = $req->param('token');
                unless ($token) {
                    $self->setSecurity($req);
174
                    $self->userLogger->warn('Register try without token');
Yadd's avatar
Yadd committed
175
176
                    return PE_NOTOKEN;
                }
Yadd's avatar
Yadd committed
177
178
            }

Yadd's avatar
Yadd committed
179
180
181
182
183
            # Captcha for register form
            if ( $self->captcha ) {
                my $captcha = $req->param('captcha');

                unless ($captcha) {
184
                    $self->userLogger->warn(
Yadd's avatar
Yadd committed
185
186
187
188
189
190
191
192
                        'Register try with captcha not filled');

                    # Set captcha or token
                    $self->setSecurity($req);
                    return PE_CAPTCHAEMPTY;
                }

                # Check captcha
193
194
                unless ( $self->captcha->validateCaptcha( $token, $captcha ) )
                {
195
                    $self->userLogger->info('Captcha failed: wrong code');
Yadd's avatar
Yadd committed
196
197
198
199
200

                    # Set captcha or token
                    $self->setSecurity($req);
                    return PE_CAPTCHAERROR;
                }
Yadd's avatar
Yadd committed
201
                $self->logger->debug("Captcha code verified");
Yadd's avatar
Yadd committed
202
203
204
205
            }
            elsif ( $self->ott ) {
                unless ( $self->ott->getToken($token) ) {
                    $self->setSecurity($req);
Yadd's avatar
Yadd committed
206
207
                    $self->userLogger->notice(
                        'Register try with expired/bad token');
Yadd's avatar
Yadd committed
208
209
                    return PE_TOKENEXPIRED;
                }
Yadd's avatar
Yadd committed
210
211
212
213
214
215
            }
        }
    }

    # Check mail
    return PE_MALFORMEDUSER
216
217
        unless ( $req->data->{registerInfo}->{mail}
        =~ m/$self->{conf}->{userControl}/o );
Yadd's avatar
Yadd committed
218
219
220

    # Search for user using UserDB module
    # If the user already exists, register is forbidden
Yadd's avatar
Yadd committed
221
    $req->user( $req->data->{registerInfo}->{mail} );
222
    if ( $self->p->_userDB->getUser( $req, useMail => 1 ) == PE_OK ) {
Yadd's avatar
Yadd committed
223
        $self->userLogger->error(
224
            "Register: refuse mail $req->{data}->{registerInfo}->{mail} because already exists in UserDB"
Yadd's avatar
Yadd committed
225
226
227
        );
        return PE_REGISTERALREADYEXISTS;
    }
228
229
230
231
    my $register_session
        = $self->getRegisterSession( $req->data->{registerInfo}->{mail} );
    $req->data->{mail_already_sent}
        = ( $register_session and !$req->id ) ? 1 : 0;
Yadd's avatar
Yadd committed
232
233

    # Skip this step if confirmation was already sent
Yadd's avatar
Yadd committed
234
    unless ( $req->data->{register_token} or $register_session ) {
Yadd's avatar
Yadd committed
235

Yadd's avatar
Yadd committed
236
237
        # Create mail token
        $register_session = $self->mailott->createToken(
238
            {   mail      => $req->data->{registerInfo}->{mail},
Yadd's avatar
Yadd committed
239
240
241
                firstname => $req->data->{registerInfo}->{firstname},
                lastname  => $req->data->{registerInfo}->{lastname},
                ipAddr    => $req->data->{registerInfo}->{ipAddr},
Yadd's avatar
Yadd committed
242
243
244
                _type     => 'register',
            }
        );
Yadd's avatar
Yadd committed
245
        $self->logger->debug("Token $register_session created");
Yadd's avatar
Yadd committed
246
247
248
249
250
    }

    # Send confirmation mail

    # Skip this step if user clicked on the confirmation link
Yadd's avatar
Yadd committed
251
    unless ( $req->data->{register_token} ) {
Yadd's avatar
Yadd committed
252
253

        # Check if confirmation mail has already been sent
Yadd's avatar
Yadd committed
254
        $self->logger->debug('No register_token');
Yadd's avatar
Yadd committed
255
256
257
258

        # Read session to get creation and expiration dates
        $req->id($register_session) unless $req->id;

Yadd's avatar
Yadd committed
259
        $self->logger->debug("Register session found: $register_session");
Yadd's avatar
Yadd committed
260
261

        # Mail session expiration date
262
263
264
        my $expTimestamp
            = ( $self->{conf}->{registerTimeout} || $self->conf->{timeout} )
            + time;
Yadd's avatar
Yadd committed
265

Yadd's avatar
Yadd committed
266
        $self->logger->debug("Register expiration timestamp: $expTimestamp");
Yadd's avatar
Yadd committed
267

268
269
270
271
        $req->data->{expMailDate}
            = strftime( "%d/%m/%Y", localtime $expTimestamp );
        $req->data->{expMailTime}
            = strftime( "%H:%M", localtime $expTimestamp );
Yadd's avatar
Yadd committed
272
273

        # Mail session start date
Yadd's avatar
Yadd committed
274
        my $startTimestamp = time;
Yadd's avatar
Yadd committed
275

Yadd's avatar
Yadd committed
276
        $self->logger->debug("Register start timestamp: $startTimestamp");
Yadd's avatar
Yadd committed
277

278
279
280
281
        $req->data->{startMailDate}
            = strftime( "%d/%m/%Y", localtime $startTimestamp );
        $req->data->{startMailTime}
            = strftime( "%H:%M", localtime $startTimestamp );
Yadd's avatar
Yadd committed
282
283

        # Ask if user want another confirmation email
Yadd's avatar
Yadd committed
284
        if ( $req->data->{mail_already_sent}
Yadd's avatar
Yadd committed
285
            and !$req->param('resendconfirmation') )
Yadd's avatar
Yadd committed
286
287
288
289
290
        {
            return PE_MAILCONFIRMATION_ALREADY_SENT;
        }

        # Build confirmation url
291
292
        my $req_url = $req->data->{_url};
        my $skin    = $self->p->getSkin($req);
293
294
295
        my $url
            = $self->registerUrl . '?'
            . build_urlencoded(
Yadd's avatar
Yadd committed
296
            register_token => $req->{id},
297
298
            skin           => $skin,
            ( $req_url ? ( url => $req_url ) : () ),
299
            );
Yadd's avatar
Yadd committed
300
301

        # Build mail content
302
        $tplPrms{MAIN_LOGO} = $self->conf->{portalMainLogo};
303
        my $tr      = $self->translate($req);
Yadd's avatar
Yadd committed
304
        my $subject = $self->conf->{registerConfirmSubject};
305
306
307
308
        unless ($subject) {
            $subject = 'registerConfirmSubject';
            $tr->( \$subject );
        }
Yadd's avatar
Yadd committed
309
310
311
312
        my $body;
        my $html = 1;

        # Use HTML template
313
314
315
316
317
        $body = $self->loadTemplate(
            'mail_register_confirm',
            filter => $tr,
            params => \%tplPrms
        );
Yadd's avatar
Yadd committed
318
319

        # Replace variables in body
Yadd's avatar
Yadd committed
320
321
        $body =~ s/\$expMailDate/$req->data->{expMailDate}/g;
        $body =~ s/\$expMailTime/$req->data->{expMailTime}/g;
Yadd's avatar
Yadd committed
322
        $body =~ s/\$url/$url/g;
Yadd's avatar
Yadd committed
323
        $body =~ s/\$(\w+)/$req->data->{registerInfo}->{$1}/eg;
Yadd's avatar
Yadd committed
324
325
326

        # Send mail
        return PE_MAILERROR
327
            unless $self->send_mail( $req->data->{registerInfo}->{mail},
Yadd's avatar
Yadd committed
328
329
            $subject, $body, $html );

Yadd's avatar
Yadd committed
330
        $self->logger->debug('Register message sent');
Yadd's avatar
Yadd committed
331
        return PE_MAILCONFIRMOK;
Yadd's avatar
Yadd committed
332
333
334
335
336
    }

    # Generate a complex password
    my $password = $self->gen_password( $self->conf->{randomPasswordRegexp} );

Yadd's avatar
Yadd committed
337
    $self->logger->debug( "Generated password: " . $password );
Yadd's avatar
Yadd committed
338

Yadd's avatar
Yadd committed
339
340
    $req->data->{registerInfo}->{password} = $password;
    $req->data->{forceReset} = 1;
Yadd's avatar
Yadd committed
341
342

    # Find a login
Yadd's avatar
Yadd committed
343
    my $result = $self->registerModule->computeLogin($req);
Yadd's avatar
Yadd committed
344
    unless ( $result == PE_OK ) {
Yadd's avatar
Yadd committed
345
        $self->logger->error( "Could not compute login for "
346
                . $req->data->{registerInfo}->{mail} );
Yadd's avatar
Yadd committed
347
348
349
350
        return $result;
    }

    # Create user
Yadd's avatar
Yadd committed
351
    $self->logger->debug(
Yadd's avatar
Yadd committed
352
        'Create new user ' . $req->data->{registerInfo}->{login} );
Yadd's avatar
Yadd committed
353
354
    $result = $self->registerModule->createUser($req);
    unless ( $result == PE_OK ) {
Yadd's avatar
Yadd committed
355
        $self->logger->error(
Yadd's avatar
Yadd committed
356
            "Could not create user " . $req->data->{registerInfo}->{login} );
Yadd's avatar
Yadd committed
357
358
359
        return $result;
    }

360
    # Build mail content
361
    $tplPrms{MAIN_LOGO} = $self->conf->{portalMainLogo};
362
    my $tr      = $self->translate($req);
Yadd's avatar
Yadd committed
363
    my $subject = $self->conf->{registerDoneSubject};
364
365
366
367
    unless ($subject) {
        $subject = 'registerDoneSubject';
        $tr->( \$subject );
    }
Yadd's avatar
Yadd committed
368
369
370
371
    my $body;
    my $html = 1;

    # Use HTML template
372
373
374
375
376
    $body = $self->loadTemplate(
        'mail_register_done',
        filter => $tr,
        params => \%tplPrms
    );
Yadd's avatar
Yadd committed
377

378
379
380
    # Build portal url
    my $url = $self->conf->{portal};
    $url =~ s#/*$##;
381
382
    my $req_url = $req->data->{_url};
    my $skin    = $self->p->getSkin($req);
Yadd's avatar
Yadd committed
383
    $url .= '/?'
384
        . build_urlencoded(
385
386
        skin => $skin,
        ( $req_url ? ( url => $req_url ) : () ),
387
        );
388

Yadd's avatar
Yadd committed
389
    # Replace variables in body
390
    $body =~ s/\$url/$url/g;
Yadd's avatar
Yadd committed
391
    $body =~ s/\$(\w+)/$req->data->{registerInfo}->{$1}/ge;
Yadd's avatar
Yadd committed
392
393
394

    # Send mail
    return PE_MAILERROR
395
        unless $self->send_mail( $req->data->{registerInfo}->{mail},
Yadd's avatar
Yadd committed
396
        $subject, $body, $html );
Yadd's avatar
Yadd committed
397
398
399
400
401
402
403

    return PE_MAILOK;
}

sub display {
    my ( $self, $req ) = @_;
    my %templateParams = (
Christophe Maudoux's avatar
Christophe Maudoux committed
404
        SKIN_PATH       => $self->conf->{staticPrefix},
405
        SKIN            => $self->p->getSkin($req),
Yadd's avatar
Yadd committed
406
        SKIN_BG         => $self->conf->{portalSkinBackground},
407
        MAIN_LOGO       => $self->conf->{portalMainLogo},
Yadd's avatar
Yadd committed
408
409
        AUTH_ERROR      => $req->error,
        AUTH_ERROR_TYPE => $req->error_type,
Yadd's avatar
Yadd committed
410
        AUTH_URL        => $req->data->{_url},
Yadd's avatar
Yadd committed
411
        CHOICE_PARAM    => $self->conf->{authChoiceParam},
Yadd's avatar
Yadd committed
412
413
414
415
416
417
        CHOICE_VALUE    => $req->data->{_authChoice},
        EXPMAILDATE     => $req->data->{expMailDate},
        EXPMAILTIME     => $req->data->{expMailTime},
        STARTMAILDATE   => $req->data->{startMailDate},
        STARTMAILTIME   => $req->data->{startMailTime},
        MAILALREADYSENT => $req->data->{mail_already_sent},
418
419
        MAIL            => $self->p->checkXSSAttack( 'mail',
            $req->data->{registerInfo}->{mail} ) ? ""
Yadd's avatar
Yadd committed
420
        : $req->data->{registerInfo}->{mail},
Yadd's avatar
Yadd committed
421
        FIRSTNAME => $self->p->checkXSSAttack( 'firstname',
Yadd's avatar
Yadd committed
422
423
            $req->data->{registerInfo}->{firstname} ) ? ""
        : $req->data->{registerInfo}->{firstname},
Yadd's avatar
Yadd committed
424
        LASTNAME => $self->p->checkXSSAttack( 'lastname',
Yadd's avatar
Yadd committed
425
426
            $req->data->{registerInfo}->{lastname} ) ? ""
        : $req->data->{registerInfo}->{lastname},
Yadd's avatar
Yadd committed
427
        REGISTER_TOKEN => $self->p->checkXSSAttack( 'register_token',
Yadd's avatar
Yadd committed
428
429
            $req->data->{register_token} ) ? ""
        : $req->data->{register_token},
Yadd's avatar
Yadd committed
430
431
432
    );

    # Display form the first time
433
    if ((      $req->error == PE_REGISTERFORMEMPTY
Yadd's avatar
Yadd committed
434
435
436
            or $req->error == PE_REGISTERFIRSTACCESS
            or $req->error == PE_CAPTCHAERROR
            or $req->error == PE_CAPTCHAEMPTY
Yadd's avatar
Yadd committed
437
438
            or $req->error == PE_NOTOKEN
            or $req->error == PE_TOKENEXPIRED
Yadd's avatar
Yadd committed
439
440
        )
        and !$req->param('mail_token')
441
442
        )
    {
Yadd's avatar
Yadd committed
443
444
445
446
447
448
449
450
451
452
453
        %templateParams = (
            %templateParams,
            DISPLAY_FORM            => 1,
            DISPLAY_RESEND_FORM     => 0,
            DISPLAY_CONFIRMMAILSENT => 0,
            DISPLAY_MAILSENT        => 0,
            DISPLAY_PASSWORD_FORM   => 0,
        );
    }

    # Display captcha if it's enabled
Yadd's avatar
Yadd committed
454
455
456
457
458
459
    if ( $req->captcha ) {
        $templateParams{CAPTCHA_SRC} = $req->captcha;
        $templateParams{CAPTCHA_SIZE} = $self->conf->{captcha_size} || 6;
    }
    if ( $req->token ) {
        $templateParams{TOKEN} = $req->token;
Yadd's avatar
Yadd committed
460
461
    }

462
463
464
465
466
467
468
469
470
471
472
    if ( $req->error == PE_REGISTERALREADYEXISTS ) {
        %templateParams = (
            %templateParams,
            DISPLAY_FORM            => 0,
            DISPLAY_RESEND_FORM     => 0,
            DISPLAY_CONFIRMMAILSENT => 0,
            DISPLAY_MAILSENT        => 0,
            DISPLAY_PASSWORD_FORM   => 0,
        );
    }

Yadd's avatar
Yadd committed
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
    # Display mail confirmation resent form
    if ( $req->{error} == PE_MAILCONFIRMATION_ALREADY_SENT ) {
        %templateParams = (
            %templateParams,
            DISPLAY_FORM            => 0,
            DISPLAY_RESEND_FORM     => 1,
            DISPLAY_CONFIRMMAILSENT => 0,
            DISPLAY_MAILSENT        => 0,
            DISPLAY_PASSWORD_FORM   => 0,
        );
    }

    # Display confirmation mail sent
    if ( $req->{error} == PE_MAILCONFIRMOK ) {
        %templateParams = (
            %templateParams,
            DISPLAY_FORM            => 0,
            DISPLAY_RESEND_FORM     => 0,
            DISPLAY_CONFIRMMAILSENT => 1,
            DISPLAY_MAILSENT        => 0,
            DISPLAY_PASSWORD_FORM   => 0,
        );
    }

    # Display mail sent
    if ( $req->{error} == PE_MAILOK ) {
        %templateParams = (
            %templateParams,
            DISPLAY_FORM            => 0,
            DISPLAY_RESEND_FORM     => 0,
            DISPLAY_CONFIRMMAILSENT => 0,
            DISPLAY_MAILSENT        => 1,
            DISPLAY_PASSWORD_FORM   => 0,
        );
    }

    # Display password change form
    if (    $req->param('mail_token')
        and $req->{error} != PE_MAILERROR
        and $req->{error} != PE_BADMAILTOKEN
        and $req->{error} != PE_MAILOK )
    {
        %templateParams = (
            %templateParams,
            DISPLAY_FORM            => 0,
            DISPLAY_RESEND_FORM     => 0,
            DISPLAY_CONFIRMMAILSENT => 0,
            DISPLAY_MAILSENT        => 0,
            DISPLAY_PASSWORD_FORM   => 1,
        );
    }
524

Yadd's avatar
Yadd committed
525
526
527
    return ( 'register', \%templateParams );
}

Yadd's avatar
Yadd committed
528
529
530
531
532
533
534
535
536
537
sub setSecurity {
    my ( $self, $req ) = @_;
    if ( $self->captcha ) {
        $self->captcha->setCaptcha($req);
    }
    elsif ( $self->ott ) {
        $self->ott->setToken($req);
    }
}

Yadd's avatar
Yadd committed
538
1;