/[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 88 - (show annotations)
Mon Feb 5 18:46:13 2007 UTC (17 years, 1 month ago) by dpavlin
File size: 1529 byte(s)
hush warns, move some to debug log
1 use strict;
2 use warnings;
3
4 package SQLSession::CurrentUser;
5 use base qw/Jifty::CurrentUser/;
6
7 =head2 _init
8
9 This function will load user data from database and turn on admin mode in
10 Jifty if user has C<admin> role.
11
12 =cut
13
14 sub _init {
15 my $self = shift;
16 my %args = (@_);
17
18 if ( delete $args{'_bootstrap'} ) {
19 $self->is_bootstrap_user(1);
20 } elsif( keys %args ) {
21 $self->user_object( SQLSession::Model::User->new( current_user => $self ) );
22 $self->user_object->load_by_cols( %args );
23
24 }
25
26 $self->SUPER::_init(%args);
27
28 if ( $self->current_user->id ) {
29 my $r = SQLSession::Model::Role->new();
30 $r->load_by_cols(
31 user_id => $self->current_user->id,
32 role => 'admin',
33 );
34 if ($r->id) {
35 Jifty->log->debug("turn on AdminMode for ", $self->current_user->user_object->email);
36 $self->is_superuser(1);
37 }
38 }
39
40 # honor AdminMode from config.yml
41 $self->is_superuser(1) if Jifty->config->framework('AdminMode');
42 }
43
44 =head2 role
45
46 Test if user has role
47
48 Jifty->web->current_user->role( 'edit' );
49
50 =cut
51
52 sub role {
53 my $self = shift;
54 my $role = shift;
55
56 return 0 unless ($self->current_user->id);
57
58 return 1 if ($role eq 'admin' && $self->current_user->is_superuser);
59
60 return 1 if ($role eq 'edit' && $self->current_user->user_object->email_confirmed);
61
62 my $r = SQLSession::Model::Role->new();
63 $r->load_by_cols(
64 user_id => $self->current_user->id,
65 role => $role
66 );
67
68 Jifty->log->debug("role is '$role' for ",
69 $self->current_user->user_object->email, " ",
70 $r->id ? 'OK' : 'DENY'
71 );
72
73 return $r->id;
74 }
75
76 1;

  ViewVC Help
Powered by ViewVC 1.1.26