1 |
use strict; |
2 |
use warnings; |
3 |
|
4 |
package Transports::Model::User::Schema; |
5 |
use Jifty::DBI::Schema; |
6 |
use Transports::Model::UserOnLandscapeCollection; |
7 |
|
8 |
# Your column definitions go here. See L<Jifty::DBI::Schema> for |
9 |
# documentation about how to write column definitions. |
10 |
|
11 |
column name => |
12 |
type is 'text', |
13 |
label is 'Name', |
14 |
is mandatory, |
15 |
is distinct; |
16 |
|
17 |
column email => |
18 |
type is 'text', |
19 |
label is 'Email address', |
20 |
is mandatory, |
21 |
is distinct; |
22 |
|
23 |
column password => |
24 |
type is 'text', |
25 |
label is 'Password', |
26 |
is mandatory, |
27 |
render_as 'password'; |
28 |
|
29 |
column admin => |
30 |
type is 'boolean', |
31 |
label is 'User is administrator', |
32 |
is mandatory, |
33 |
default is 0, |
34 |
since '0.0.8'; |
35 |
|
36 |
column can_import => |
37 |
type is 'boolean', |
38 |
label is 'User can import requests', |
39 |
is mandatory, |
40 |
default is 0, |
41 |
since '0.0.12'; |
42 |
|
43 |
column landscapes => |
44 |
refers_to Transports::Model::UserOnLandscapeCollection by 'user_on', |
45 |
label is 'Landscape', |
46 |
since '0.0.13'; |
47 |
|
48 |
package Transports::Model::User; |
49 |
use base qw/Transports::Record/; |
50 |
|
51 |
# Your model-specific methods go here. |
52 |
|
53 |
=head2 password_is STRING |
54 |
|
55 |
Returns true if and only if the current user's password matches STRING |
56 |
|
57 |
=cut |
58 |
|
59 |
|
60 |
sub password_is { |
61 |
my $self = shift; |
62 |
my $string = shift || return; |
63 |
warn "password_is ", $self->_value('password'), " == $string\n"; |
64 |
return 1 if ($self->_value('password') eq $string); |
65 |
return 0; |
66 |
} |
67 |
|
68 |
=head2 password |
69 |
|
70 |
Never display a password |
71 |
|
72 |
=cut |
73 |
|
74 |
sub password { |
75 |
return '*****'; |
76 |
} |
77 |
|
78 |
=head2 current_user_can |
79 |
|
80 |
Allows the current user to see all their own attributes and |
81 |
everyone else to see their username. |
82 |
|
83 |
Allows the current user to update any of their own attributes |
84 |
except whether or not their email has been confirmed. |
85 |
|
86 |
Passes everything else off to the superclass. |
87 |
|
88 |
=cut |
89 |
|
90 |
|
91 |
sub current_user_can { |
92 |
my $self = shift; |
93 |
my $right = shift; |
94 |
my %args = (@_); |
95 |
|
96 |
return $self->SUPER::current_user_can( $right, %args ) unless ($right && $self->id && $self->current_user); |
97 |
|
98 |
#Carp::confess if ($right eq 'read' and not $args{'column'}); |
99 |
|
100 |
if ( $self->id == $self->current_user->id or $self->current_user->admin or $self->current_user->can_import ) { |
101 |
return 1; |
102 |
# } elsif ( $right eq 'read' and $args{'column'} eq 'name' ) { |
103 |
# return 1; |
104 |
} |
105 |
|
106 |
return $self->SUPER::current_user_can( $right, %args ); |
107 |
} |
108 |
|
109 |
1; |
110 |
|