/[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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 69 - (hide annotations)
Thu Jan 25 20:42:11 2007 UTC (17 years, 4 months ago) by dpavlin
File size: 1521 byte(s)
allow all users with confirmed e-mail address to edit and create new queries, thus turning
this application into wiki SQL editor :-)

1 dpavlin 45 use strict;
2     use warnings;
3    
4     package SQLSession::CurrentUser;
5     use base qw/Jifty::CurrentUser/;
6    
7 dpavlin 58 =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 dpavlin 45 sub _init {
15     my $self = shift;
16     my %args = (@_);
17    
18     warn "_init";
19    
20     if ( delete $args{'_bootstrap'} ) {
21     $self->is_bootstrap_user(1);
22     } elsif( keys %args ) {
23     $self->user_object( SQLSession::Model::User->new( current_user => $self ) );
24     $self->user_object->load_by_cols( %args );
25 dpavlin 58
26 dpavlin 45 }
27    
28     $self->SUPER::_init(%args);
29 dpavlin 58
30     if ( $self->current_user->id ) {
31     my $r = SQLSession::Model::Role->new();
32     $r->load_by_cols(
33     user_id => $self->current_user->id,
34     role => 'admin',
35     );
36     if ($r->id) {
37     warn "turn on AdminMode for ", $self->current_user->user_object->email, $/;
38     $self->is_superuser(1);
39     }
40     }
41 dpavlin 60
42     # honor AdminMode from config.yml
43     $self->is_superuser(1) if Jifty->config->framework('AdminMode');
44 dpavlin 45 }
45    
46 dpavlin 47 =head2 role
47    
48     Test if user has role
49    
50     Jifty->web->current_user->role( 'edit' );
51    
52     =cut
53    
54 dpavlin 45 sub role {
55     my $self = shift;
56     my $role = shift;
57    
58     return 0 unless ($self->current_user->id);
59    
60 dpavlin 58 return 1 if ($role eq 'admin' && $self->current_user->is_superuser);
61    
62 dpavlin 69 return 1 if ($role eq 'edit' && $self->current_user->user_object->email_confirmed);
63    
64 dpavlin 47 my $r = SQLSession::Model::Role->new();
65     $r->load_by_cols(
66     user_id => $self->current_user->id,
67     role => $role
68     );
69 dpavlin 45
70 dpavlin 47 warn "role is '$role' for ", $self->current_user->user_object->email, " ",
71     $r->id ? 'OK' : 'DENY', $/;
72 dpavlin 45
73 dpavlin 47 return $r->id;
74 dpavlin 45 }
75    
76 dpavlin 59 1;

  ViewVC Help
Powered by ViewVC 1.1.26