1 |
dpavlin |
1 |
use strict; |
2 |
|
|
use warnings; |
3 |
|
|
|
4 |
|
|
package Transports::Model::User::Schema; |
5 |
|
|
use Jifty::DBI::Schema; |
6 |
|
|
|
7 |
|
|
# Your column definitions go here. See L<Jifty::DBI::Schema> for |
8 |
|
|
# documentation about how to write column definitions. |
9 |
|
|
|
10 |
|
|
column name => |
11 |
|
|
type is 'text', |
12 |
|
|
label is 'Name', |
13 |
|
|
is mandatory, |
14 |
|
|
is distinct; |
15 |
|
|
|
16 |
|
|
column email => |
17 |
|
|
type is 'text', |
18 |
|
|
label is 'Email address', |
19 |
|
|
is mandatory, |
20 |
|
|
is distinct; |
21 |
|
|
|
22 |
dpavlin |
27 |
column password => |
23 |
dpavlin |
1 |
type is 'text', |
24 |
|
|
label is 'Password', |
25 |
dpavlin |
3 |
is mandatory, |
26 |
dpavlin |
1 |
render_as 'password'; |
27 |
|
|
|
28 |
dpavlin |
27 |
column admin => |
29 |
|
|
type is 'boolean', |
30 |
|
|
label is 'Administrator', |
31 |
|
|
is mandatory, |
32 |
|
|
default is 'false', |
33 |
|
|
since '0.0.8'; |
34 |
|
|
|
35 |
dpavlin |
1 |
package Transports::Model::User; |
36 |
|
|
use base qw/Transports::Record/; |
37 |
|
|
|
38 |
|
|
# Your model-specific methods go here. |
39 |
|
|
|
40 |
dpavlin |
15 |
=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 |
dpavlin |
5 |
} |
54 |
|
|
|
55 |
dpavlin |
15 |
=head2 password |
56 |
|
|
|
57 |
|
|
Never display a password |
58 |
|
|
|
59 |
|
|
=cut |
60 |
|
|
|
61 |
dpavlin |
17 |
sub password { |
62 |
|
|
return '*****'; |
63 |
|
|
} |
64 |
dpavlin |
15 |
|
65 |
dpavlin |
17 |
=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 |
dpavlin |
31 |
my %args = (@_); |
82 |
dpavlin |
27 |
|
83 |
dpavlin |
31 |
return $self->SUPER::current_user_can( $right, %args ) unless ($right && $self->id && $self->current_user); |
84 |
dpavlin |
27 |
|
85 |
dpavlin |
17 |
#Carp::confess if ($right eq 'read' and not $args{'column'}); |
86 |
dpavlin |
31 |
|
87 |
dpavlin |
17 |
if ( $right eq 'read' |
88 |
dpavlin |
31 |
and ( $self->id == $self->current_user->id or $self->current_user->admin ) ) |
89 |
dpavlin |
17 |
{ |
90 |
|
|
return 1; |
91 |
|
|
} elsif ( $right eq 'read' and $args{'column'} eq 'name' ) { |
92 |
|
|
return (1); |
93 |
|
|
|
94 |
|
|
} elsif ( $right eq 'update' |
95 |
|
|
and $self->id == $self->current_user->id |
96 |
|
|
and $args{'column'} ne 'email_confirmed' ) |
97 |
|
|
{ |
98 |
|
|
return (1); |
99 |
|
|
} |
100 |
|
|
|
101 |
|
|
return $self->SUPER::current_user_can( $right, %args ); |
102 |
|
|
} |
103 |
|
|
|
104 |
dpavlin |
1 |
1; |
105 |
|
|
|