File: UserDBDemo.pm

package info (click to toggle)
lemonldap-ng 1.3.3-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 13,084 kB
  • ctags: 2,440
  • sloc: perl: 25,708; makefile: 622; sh: 176; php: 6; sql: 5
file content (82 lines) | stat: -rw-r--r-- 1,670 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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
## @file
# Demo userDB mechanism

## @class
# Demo userDB mechanism class
package Lemonldap::NG::Portal::UserDBDemo;

use strict;
use Lemonldap::NG::Portal::Simple;

our $VERSION = '1.3.0';

## @apmethod int userDBInit()
# Check AuthDemo use
# @return Lemonldap::NG::Portal constant
sub userDBInit {
    my $self = shift;

    if ( $self->get_module('auth') =~ /^Demo/ ) {

        # Call authInit if demo accounts not found
        $self->authInit() unless defined $self->{_demoAccounts};

        return PE_OK;
    }
    else {
        $self->lmLog( "Use UserDBDemo only with AuthDemo", 'error' );
        return PE_ERROR;
    }

    PE_OK;
}

## @apmethod int getUser()
# Check known accounts
# @return Lemonldap::NG::Portal constant
sub getUser {
    my $self = shift;

    # Search by login
    if ( $self->{user} ) {
        return PE_OK
          if ( defined $self->{_demoAccounts}->{ $self->{user} } );
    }

    # Search by mail
    if ( $self->{mail} ) {
        foreach my $user ( keys %{ $self->{_demoAccounts} } ) {
            if ( $self->{_demoAccounts}->{$user}->{mail} eq $self->{mail} ) {
                $self->{user} = $user;
                return PE_OK;
            }
        }
    }

    PE_USERNOTFOUND;
}

## @apmethod int setSessionInfo()
# Get sample data
# @return Lemonldap::NG::Portal constant
sub setSessionInfo {
    my $self = shift;

    foreach ( keys %{ $self->{exportedVars} } ) {
        $self->{sessionInfo}->{$_} =
          $self->{_demoAccounts}->{ $self->{user} }->{$_}
          || "";
    }

    PE_OK;
}

## @apmethod int setGroups()
# Do nothing
# @return Lemonldap::NG::Portal constant
sub setGroups {
    PE_OK;
}

1;