-
Notifications
You must be signed in to change notification settings - Fork 3
/
User.pm
134 lines (92 loc) · 2.71 KB
/
User.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package PresentingPerl::Schema::Result::User;
# Created by DBIx::Class::Schema::Loader
# DO NOT MODIFY THE FIRST PART OF THIS FILE
use strict;
use warnings;
use Moose;
use MooseX::NonMoose;
use namespace::autoclean;
extends 'DBIx::Class::Core';
__PACKAGE__->load_components("InflateColumn::DateTime", "TimeStamp");
__PACKAGE__->load_components(qw(InflateColumn::Authen::Passphrase));
=head1 NAME
PresentingPerl::Schema::Result::User
=cut
__PACKAGE__->table("users");
=head1 ACCESSORS
=head2 id
data_type: 'integer'
is_auto_increment: 1
is_nullable: 0
=head2 username
data_type: 'text'
is_nullable: 1
=head2 password
data_type: 'text'
is_nullable: 1
=head2 email_address
data_type: 'text'
is_nullable: 1
=head2 first_name
data_type: 'text'
is_nullable: 1
=head2 last_name
data_type: 'text'
is_nullable: 1
=head2 active
data_type: 'integer'
is_nullable: 1
=cut
__PACKAGE__->add_columns(
"id",
{ data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
"username",
{ data_type => "text", is_nullable => 1 },
"password",
{ data_type => "varchar", size => 255, is_nullable => 1, inflate_passphrase => 'rfc2307' },
"email_address",
{ data_type => "text", is_nullable => 1 },
"first_name",
{ data_type => "text", is_nullable => 1 },
"last_name",
{ data_type => "text", is_nullable => 1 },
"active",
{ data_type => "integer", is_nullable => 1 },
);
__PACKAGE__->set_primary_key("id");
=head1 RELATIONS
=head2 user_roles
Type: has_many
Related object: L<PresentingPerl::Schema::Result::UserRole>
=cut
__PACKAGE__->has_many(
"user_roles",
"PresentingPerl::Schema::Result::UserRole",
{ "foreign.user_id" => "self.id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-12-03 14:51:10
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:LdcXqKuNwSPcZp4qrNP8mw
# many_to_many():
# args:
# 1) Name of relationship, DBIC will create accessor with this name
# 2) Name of has_many() relationship this many_to_many() is shortcut for
# 3) Name of belongs_to() relationship in model class of has_many() above
# You must already have the has_many() defined to use a many_to_many().
__PACKAGE__->many_to_many(roles => 'user_roles', 'role');
sub check_password {
my ($self, $passp) = @_;
return $self->password->match($passp);
}
=head2 has_role
Check if a user has the specified role
=cut
use Perl6::Junction qw/any/;
sub has_role {
my ($self, $role) = @_;
# Does this user posses the required role?
return any(map { $_->role } $self->roles) eq $role;
}
# You can replace this text with custom code or comments, and it will be preserved on regeneration
__PACKAGE__->meta->make_immutable;
1;