| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package MojoMojo::Schema::Result::Person; |
|
2
|
|
|
|
|
|
|
|
|
3
|
40
|
|
|
40
|
|
17373
|
use strict; |
|
|
40
|
|
|
|
|
100
|
|
|
|
40
|
|
|
|
|
1189
|
|
|
4
|
40
|
|
|
40
|
|
200
|
use warnings; |
|
|
40
|
|
|
|
|
83
|
|
|
|
40
|
|
|
|
|
880
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
40
|
|
|
40
|
|
16251
|
use Digest::SHA; |
|
|
40
|
|
|
|
|
77353
|
|
|
|
40
|
|
|
|
|
1845
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
40
|
|
|
40
|
|
408
|
use parent qw/MojoMojo::Schema::Base::Result/; |
|
|
40
|
|
|
|
|
93
|
|
|
|
40
|
|
|
|
|
387
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
40
|
|
|
40
|
|
15002
|
use Text::Textile; |
|
|
40
|
|
|
|
|
480262
|
|
|
|
40
|
|
|
|
|
25518
|
|
|
11
|
|
|
|
|
|
|
my $textile = Text::Textile->new( flavor => "xhtml1", charset => 'utf-8' ); |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
__PACKAGE__->load_components( |
|
14
|
|
|
|
|
|
|
qw/DateTime::Epoch TimeStamp EncodedColumn Core/); |
|
15
|
|
|
|
|
|
|
__PACKAGE__->table("person"); |
|
16
|
|
|
|
|
|
|
__PACKAGE__->add_columns( |
|
17
|
|
|
|
|
|
|
"id", |
|
18
|
|
|
|
|
|
|
{ |
|
19
|
|
|
|
|
|
|
data_type => "INTEGER", |
|
20
|
|
|
|
|
|
|
is_nullable => 0, |
|
21
|
|
|
|
|
|
|
size => undef, |
|
22
|
|
|
|
|
|
|
is_auto_increment => 1 |
|
23
|
|
|
|
|
|
|
}, |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
"active", |
|
26
|
|
|
|
|
|
|
# -1 = user registered but hasn't confirmed e-mail address yet; |
|
27
|
|
|
|
|
|
|
# 0 = manually set to inactive from Site Settings -> Users; |
|
28
|
|
|
|
|
|
|
# 1 = active user |
|
29
|
|
|
|
|
|
|
{ |
|
30
|
|
|
|
|
|
|
data_type => "INTEGER", |
|
31
|
|
|
|
|
|
|
is_nullable => 0, |
|
32
|
|
|
|
|
|
|
default_value => -1, |
|
33
|
|
|
|
|
|
|
size => undef |
|
34
|
|
|
|
|
|
|
}, |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
"registered", |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# { data_type => "BIGINT", is_nullable => 0, size => undef, epoch => 'ctime' }, |
|
39
|
|
|
|
|
|
|
{ |
|
40
|
|
|
|
|
|
|
data_type => "BIGINT", |
|
41
|
|
|
|
|
|
|
is_nullable => 0, |
|
42
|
|
|
|
|
|
|
size => undef, |
|
43
|
|
|
|
|
|
|
inflate_datetime => 'epoch', |
|
44
|
|
|
|
|
|
|
set_on_create => 1, |
|
45
|
|
|
|
|
|
|
}, |
|
46
|
|
|
|
|
|
|
"views", |
|
47
|
|
|
|
|
|
|
{ data_type => "INTEGER", is_nullable => 1, size => undef }, |
|
48
|
|
|
|
|
|
|
"photo", |
|
49
|
|
|
|
|
|
|
{ data_type => "INTEGER", is_nullable => 1, size => undef }, |
|
50
|
|
|
|
|
|
|
"login", |
|
51
|
|
|
|
|
|
|
{ data_type => "VARCHAR", is_nullable => 0, size => 100 }, |
|
52
|
|
|
|
|
|
|
"name", |
|
53
|
|
|
|
|
|
|
{ data_type => "VARCHAR", is_nullable => 0, size => 100 }, |
|
54
|
|
|
|
|
|
|
"email", |
|
55
|
|
|
|
|
|
|
{ data_type => "VARCHAR", is_nullable => 0, size => 100 }, |
|
56
|
|
|
|
|
|
|
"pass", |
|
57
|
|
|
|
|
|
|
{ |
|
58
|
|
|
|
|
|
|
data_type => "CHAR", |
|
59
|
|
|
|
|
|
|
is_nullable => 0, |
|
60
|
|
|
|
|
|
|
size => 40, |
|
61
|
|
|
|
|
|
|
encode_column => 1, |
|
62
|
|
|
|
|
|
|
encode_class => 'Digest', |
|
63
|
|
|
|
|
|
|
encode_args => { algorithm => 'SHA-1', format => 'hex' }, |
|
64
|
|
|
|
|
|
|
encode_check_method => 'check_password', |
|
65
|
|
|
|
|
|
|
}, |
|
66
|
|
|
|
|
|
|
"timezone", |
|
67
|
|
|
|
|
|
|
{ data_type => "VARCHAR", is_nullable => 1, size => 100 }, |
|
68
|
|
|
|
|
|
|
"born", |
|
69
|
|
|
|
|
|
|
{ |
|
70
|
|
|
|
|
|
|
data_type => "BIGINT", |
|
71
|
|
|
|
|
|
|
is_nullable => 1, |
|
72
|
|
|
|
|
|
|
size => undef, |
|
73
|
|
|
|
|
|
|
default_value => undef, |
|
74
|
|
|
|
|
|
|
# epoch => 1, |
|
75
|
|
|
|
|
|
|
inflate_datetime => 'epoch', |
|
76
|
|
|
|
|
|
|
datetime_undef_if_invalid => 1, |
|
77
|
|
|
|
|
|
|
}, |
|
78
|
|
|
|
|
|
|
"gender", |
|
79
|
|
|
|
|
|
|
{ data_type => "CHAR", is_nullable => 1, size => 1 }, |
|
80
|
|
|
|
|
|
|
"occupation", |
|
81
|
|
|
|
|
|
|
{ data_type => "VARCHAR", is_nullable => 1, size => 100 }, |
|
82
|
|
|
|
|
|
|
"industry", |
|
83
|
|
|
|
|
|
|
{ data_type => "VARCHAR", is_nullable => 1, size => 100 }, |
|
84
|
|
|
|
|
|
|
"interests", |
|
85
|
|
|
|
|
|
|
{ data_type => "TEXT", is_nullable => 1, size => undef }, |
|
86
|
|
|
|
|
|
|
"movies", |
|
87
|
|
|
|
|
|
|
{ data_type => "TEXT", is_nullable => 1, size => undef }, |
|
88
|
|
|
|
|
|
|
"music", |
|
89
|
|
|
|
|
|
|
{ data_type => "TEXT", is_nullable => 1, size => undef }, |
|
90
|
|
|
|
|
|
|
); |
|
91
|
|
|
|
|
|
|
__PACKAGE__->set_primary_key("id"); |
|
92
|
|
|
|
|
|
|
__PACKAGE__->add_unique_constraint( login => [qw/login/], ); |
|
93
|
|
|
|
|
|
|
__PACKAGE__->add_unique_constraint( email => [qw/email/], ); |
|
94
|
|
|
|
|
|
|
__PACKAGE__->has_many( |
|
95
|
|
|
|
|
|
|
"entries", |
|
96
|
|
|
|
|
|
|
"MojoMojo::Schema::Result::Entry", |
|
97
|
|
|
|
|
|
|
{ "foreign.author" => "self.id" } |
|
98
|
|
|
|
|
|
|
); |
|
99
|
|
|
|
|
|
|
__PACKAGE__->has_many( |
|
100
|
|
|
|
|
|
|
"tags", |
|
101
|
|
|
|
|
|
|
"MojoMojo::Schema::Result::Tag", |
|
102
|
|
|
|
|
|
|
{ "foreign.person" => "self.id" } |
|
103
|
|
|
|
|
|
|
); |
|
104
|
|
|
|
|
|
|
__PACKAGE__->has_many( |
|
105
|
|
|
|
|
|
|
"comments", |
|
106
|
|
|
|
|
|
|
"MojoMojo::Schema::Result::Comment", |
|
107
|
|
|
|
|
|
|
{ "foreign.poster" => "self.id" } |
|
108
|
|
|
|
|
|
|
); |
|
109
|
|
|
|
|
|
|
__PACKAGE__->has_many( |
|
110
|
|
|
|
|
|
|
"role_members", |
|
111
|
|
|
|
|
|
|
"MojoMojo::Schema::Result::RoleMember", |
|
112
|
|
|
|
|
|
|
{ "foreign.person" => "self.id" }, |
|
113
|
|
|
|
|
|
|
); |
|
114
|
|
|
|
|
|
|
__PACKAGE__->has_many( |
|
115
|
|
|
|
|
|
|
"page_versions", |
|
116
|
|
|
|
|
|
|
"MojoMojo::Schema::Result::PageVersion", |
|
117
|
|
|
|
|
|
|
{ "foreign.creator" => "self.id" }, |
|
118
|
|
|
|
|
|
|
); |
|
119
|
|
|
|
|
|
|
__PACKAGE__->many_to_many( roles => 'role_members', 'role' ); |
|
120
|
|
|
|
|
|
|
__PACKAGE__->has_many( |
|
121
|
|
|
|
|
|
|
"contents", |
|
122
|
|
|
|
|
|
|
"MojoMojo::Schema::Result::Content", |
|
123
|
|
|
|
|
|
|
{ "foreign.creator" => "self.id" } |
|
124
|
|
|
|
|
|
|
); |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 NAME |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
MojoMojo::Schema::Result::Person - store user info |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 METHODS |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head2 is_admin |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Checks if user belongs to list of admins. |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=cut |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub is_admin { |
|
139
|
120
|
|
|
120
|
1
|
4204
|
my $self = shift; |
|
140
|
120
|
|
|
|
|
807
|
my $admins = MojoMojo->pref('admins'); |
|
141
|
120
|
|
|
|
|
9434
|
my $login = $self->login; |
|
142
|
120
|
100
|
66
|
|
|
5462
|
return 1 if $login && $admins =~ m/\b$login\b/; |
|
143
|
15
|
|
|
|
|
122
|
return 0; |
|
144
|
|
|
|
|
|
|
} |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head2 link |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Returns a relative link to the user's home node. |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=cut |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub link { |
|
153
|
90
|
|
|
90
|
1
|
94602
|
my ($self) = @_; |
|
154
|
90
|
|
33
|
|
|
2170
|
return lc "/" . ( $self->login || MojoMojo->pref('anonymous_user') ); |
|
155
|
|
|
|
|
|
|
} |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head2 can_edit <path> |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Checks if a user has rights to edit a given path. |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=cut |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub can_edit { |
|
164
|
0
|
|
|
0
|
1
|
0
|
my ( $self, $page ) = @_; |
|
165
|
0
|
0
|
|
|
|
0
|
return 0 unless $self->active; |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
# allow admins |
|
168
|
0
|
0
|
|
|
|
0
|
return 1 if $self->is_admin; |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
# allow edit unless users are restricted to home page |
|
171
|
0
|
0
|
|
|
|
0
|
return 1 unless MojoMojo->pref('restricted_user'); |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
# allow users editing their pages |
|
174
|
0
|
|
|
|
|
0
|
my $link = $self->link; |
|
175
|
0
|
0
|
|
|
|
0
|
return 1 if $page =~ m|^$link\b|i; |
|
176
|
0
|
|
|
|
|
0
|
return 0; |
|
177
|
|
|
|
|
|
|
} |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head2 pages |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Return the pages created by the user. |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=cut |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
sub pages { |
|
186
|
6
|
|
|
6
|
1
|
19
|
my ($self) = @_; |
|
187
|
6
|
|
|
|
|
51
|
my @pages = |
|
188
|
|
|
|
|
|
|
$self->result_source->related_source('page_versions') |
|
189
|
|
|
|
|
|
|
->related_source('page')->resultset->search( |
|
190
|
|
|
|
|
|
|
{ 'versions.creator' => $self->id, }, |
|
191
|
|
|
|
|
|
|
{ |
|
192
|
|
|
|
|
|
|
join => [qw/versions/], |
|
193
|
|
|
|
|
|
|
order_by => ['me.name'], |
|
194
|
|
|
|
|
|
|
distinct => 1, |
|
195
|
|
|
|
|
|
|
} |
|
196
|
|
|
|
|
|
|
)->all; |
|
197
|
6
|
|
|
|
|
74435
|
return $self->result_source->related_source('page_versions') |
|
198
|
|
|
|
|
|
|
->related_source('page')->resultset->set_paths(@pages); |
|
199
|
|
|
|
|
|
|
} |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head2 pass_matches <pass1> <pass2> |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
Returns true if pass1 eq pass2. |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=cut |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
sub pass_matches { |
|
208
|
0
|
0
|
|
0
|
1
|
0
|
return 1 if ( $_[0] eq $_[1] ); |
|
209
|
0
|
|
|
|
|
0
|
return 0; |
|
210
|
|
|
|
|
|
|
} |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head2 valid_pass <password> |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
Check password against database. |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=cut |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
sub valid_pass { |
|
219
|
0
|
|
|
0
|
1
|
0
|
my ( $self, $pass ) = @_; |
|
220
|
0
|
|
|
|
|
0
|
return $self->check_password($pass); |
|
221
|
|
|
|
|
|
|
} |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=head2 hashed |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
Apply a SHA1 hash to the input string. |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=cut |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
sub hashed { |
|
230
|
1
|
|
|
1
|
1
|
569
|
my ( $self, $secret ) = @_; |
|
231
|
1
|
|
|
|
|
27
|
return Digest::SHA::sha1_hex( $self->id . $secret ); |
|
232
|
|
|
|
|
|
|
} |
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
# FIXME: the formatter is arbitrarily taken to be Textile; it could be MultiMarkdown |
|
235
|
|
|
|
|
|
|
# http://github.com/marcusramberg/mojomojo/issues/#issue/29 |
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=head2 interests_formatted |
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
Format a person's interests. |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=cut |
|
242
|
|
|
|
|
|
|
|
|
243
|
0
|
|
|
0
|
1
|
|
sub interests_formatted { $textile->process( shift->interests ); } |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=head2 music_formatted |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
Format a person's music preferences. |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=cut |
|
250
|
0
|
|
|
0
|
1
|
|
sub music_formatted { $textile->process( shift->music ); } |
|
251
|
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=head2 movies_formatted |
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
Format a person's movie tastes. |
|
255
|
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=cut |
|
257
|
|
|
|
|
|
|
|
|
258
|
0
|
|
|
0
|
1
|
|
sub movies_formatted { $textile->process( shift->movies ); } |
|
259
|
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
=head2 age |
|
261
|
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
Returns age of the user in years. |
|
263
|
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=cut |
|
265
|
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
sub age { |
|
267
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
|
268
|
0
|
0
|
|
|
|
|
if ( my $birthdate = $self->born ) { |
|
269
|
0
|
|
|
|
|
|
my $diff = DateTime->now - $birthdate; |
|
270
|
0
|
|
|
|
|
|
return $diff->years; |
|
271
|
|
|
|
|
|
|
} |
|
272
|
|
|
|
|
|
|
} |
|
273
|
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
=head1 AUTHOR |
|
275
|
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
Marcus Ramberg <mramberg@cpan.org> |
|
277
|
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
=head1 AUTHOR |
|
279
|
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
Marcus Ramberg <mramberg@cpan.org> |
|
281
|
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
=head1 LICENSE |
|
283
|
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
This library is free software. You can redistribute it and/or modify |
|
285
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
|
286
|
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
=cut |
|
288
|
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
1; |