Facebook.pm 1.37 KB
Newer Older
Yadd's avatar
Yadd committed
1
2
3
4
5
6
package Lemonldap::NG::Portal::UserDB::Facebook;

use strict;
use Mouse;
use Lemonldap::NG::Portal::Main::Constants qw(PE_OK PE_MISSINGREQATTR);

Yadd's avatar
Yadd committed
7
extends 'Lemonldap::NG::Common::Module';
Yadd's avatar
Yadd committed
8
9
10
11
12
13
14
15
16
17
18
19
20

our $VERSION = '2.0.0';

has vars => (
    is      => 'rw',
    builder => sub {
        return {
            %{ $_[0]->conf->{exportedVars} },
            %{ $_[0]->conf->{facebookExportedVars} }
        };
    }
);

Yadd's avatar
Yadd committed
21
22
# INITIALIZATION

Yadd's avatar
Yadd committed
23
24
sub init {
    my ($self) = @_;
Yadd's avatar
Yadd committed
25
    unless ( $self->p->getModule( undef, 'auth' ) =~ /^Facebook/ ) {
Yadd's avatar
Yadd committed
26
27
        $self->error(
"UserDBFacebook isn't useable unless authentication module is set to Facebook"
Yadd's avatar
Yadd committed
28
29
30
31
32
33
        );
        return 0;
    }
    return 1;
}

Yadd's avatar
Yadd committed
34
35
# RUNNING METHODS

Yadd's avatar
Yadd committed
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
sub getUser {

    # All is done by Auth::Facebook
    PE_OK;
}

sub setSessionInfo {
    my ( $self, $req ) = @_;

    foreach my $k ( keys %{ $self->vars } ) {
        my $v        = $self->{vars}->{$k};
        my $attr     = $k;
        my $required = ( $attr =~ s/^!// ) ? 1 : 0;
        $req->{sessionInfo}->{$attr} = $req->datas->{_facebookDatas}->{$v};
        if ( $required and not( defined $self->{sessionInfo}->{$attr} ) ) {
            $self->lmLog(
"Required parameter $v is not provided by Facebook server, aborted",
                'warn'
            );

            $req->mustRedirect(0);
            return PE_MISSINGREQATTR;
        }
    }
    PE_OK;
}

sub setGroups {
    PE_OK;
}

1;