/[SQLSession]/trunk/lib/SQLSession/CurrentUser.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/lib/SQLSession/CurrentUser.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 47 - (show annotations)
Sun Jan 21 12:41:35 2007 UTC (17 years, 3 months ago) by dpavlin
File size: 853 byte(s)
added role model and implement checking of roles
1 use strict;
2 use warnings;
3
4 package SQLSession::CurrentUser;
5 use base qw/Jifty::CurrentUser/;
6
7 sub _init {
8 my $self = shift;
9 my %args = (@_);
10
11 warn "_init";
12
13 if ( delete $args{'_bootstrap'} ) {
14 $self->is_bootstrap_user(1);
15 } elsif( keys %args ) {
16 $self->user_object( SQLSession::Model::User->new( current_user => $self ) );
17 $self->user_object->load_by_cols( %args );
18 }
19
20 $self->SUPER::_init(%args);
21 }
22
23 =head2 role
24
25 Test if user has role
26
27 Jifty->web->current_user->role( 'edit' );
28
29 =cut
30
31 sub role {
32 my $self = shift;
33 my $role = shift;
34
35 return 0 unless ($self->current_user->id);
36
37 my $r = SQLSession::Model::Role->new();
38 $r->load_by_cols(
39 user_id => $self->current_user->id,
40 role => $role
41 );
42
43 warn "role is '$role' for ", $self->current_user->user_object->email, " ",
44 $r->id ? 'OK' : 'DENY', $/;
45
46 return $r->id;
47
48 return 0;
49 }
50
51

  ViewVC Help
Powered by ViewVC 1.1.26