19 |
is mandatory, |
is mandatory, |
20 |
is distinct; |
is distinct; |
21 |
|
|
22 |
column password =>, |
column password => |
23 |
type is 'text', |
type is 'text', |
24 |
label is 'Password', |
label is 'Password', |
25 |
|
is mandatory, |
26 |
render_as 'password'; |
render_as 'password'; |
27 |
|
|
28 |
|
column admin => |
29 |
|
type is 'boolean', |
30 |
|
label is 'Administrator', |
31 |
|
is mandatory, |
32 |
|
default is 'false', |
33 |
|
since '0.0.8'; |
34 |
|
|
35 |
package Transports::Model::User; |
package Transports::Model::User; |
36 |
use base qw/Transports::Record/; |
use base qw/Transports::Record/; |
37 |
|
|
38 |
# Your model-specific methods go here. |
# Your model-specific methods go here. |
39 |
|
|
40 |
|
=head2 password_is STRING |
41 |
|
|
42 |
|
Returns true if and only if the current user's password matches STRING |
43 |
|
|
44 |
|
=cut |
45 |
|
|
46 |
|
|
47 |
|
sub password_is { |
48 |
|
my $self = shift; |
49 |
|
my $string = shift || return; |
50 |
|
warn "password_is ", $self->_value('password'), " == $string\n"; |
51 |
|
return 1 if ($self->_value('password') eq $string); |
52 |
|
return 0; |
53 |
|
} |
54 |
|
|
55 |
|
=head2 password |
56 |
|
|
57 |
|
Never display a password |
58 |
|
|
59 |
|
=cut |
60 |
|
|
61 |
|
sub password { |
62 |
|
return '*****'; |
63 |
|
} |
64 |
|
|
65 |
|
=head2 current_user_can |
66 |
|
|
67 |
|
Allows the current user to see all their own attributes and |
68 |
|
everyone else to see their username. |
69 |
|
|
70 |
|
Allows the current user to update any of their own attributes |
71 |
|
except whether or not their email has been confirmed. |
72 |
|
|
73 |
|
Passes everything else off to the superclass. |
74 |
|
|
75 |
|
=cut |
76 |
|
|
77 |
|
|
78 |
|
sub current_user_can { |
79 |
|
my $self = shift; |
80 |
|
my $right = shift; |
81 |
|
|
82 |
|
warn 'no $self->id' unless ($self->id); |
83 |
|
|
84 |
|
my %args = (@_); |
85 |
|
#Carp::confess if ($right eq 'read' and not $args{'column'}); |
86 |
|
if ( $right eq 'read' |
87 |
|
and $self->id == $self->current_user->id ) |
88 |
|
{ |
89 |
|
return 1; |
90 |
|
} elsif ( $right eq 'read' and $args{'column'} eq 'name' ) { |
91 |
|
return (1); |
92 |
|
|
93 |
|
} elsif ( $right eq 'update' |
94 |
|
and $self->id == $self->current_user->id |
95 |
|
and $args{'column'} ne 'email_confirmed' ) |
96 |
|
{ |
97 |
|
return (1); |
98 |
|
} |
99 |
|
|
100 |
|
return $self->SUPER::current_user_can( $right, %args ); |
101 |
|
} |
102 |
|
|
103 |
1; |
1; |
104 |
|
|