File Coverage

blib/lib/RapidApp/CoreSchema/Result/User.pm
Criterion Covered Total %
statement 18 24 75.0
branch 0 2 0.0
condition 0 6 0.0
subroutine 6 7 85.7
pod 0 1 0.0
total 24 40 60.0


line stmt bran cond sub pod time code
1             package RapidApp::CoreSchema::Result::User;
2              
3 1     1   641 use strict;
  1         2  
  1         31  
4 1     1   5 use warnings;
  1         3  
  1         29  
5              
6 1     1   5 use Moose;
  1         2  
  1         8  
7 1     1   5964 use MooseX::NonMoose;
  1         2  
  1         8  
8 1     1   4655 use namespace::autoclean;
  1         2  
  1         10  
9             extends 'DBIx::Class::Core';
10              
11             #use DBIx::Class::PassphraseColumn 0.02;
12 1     1   575 use RapidApp::DBIC::Component::PassphraseColumn; # temp
  1         4  
  1         485  
13              
14             __PACKAGE__->load_components(
15             "InflateColumn::DateTime",
16             #"PassphraseColumn",
17             '+RapidApp::DBIC::Component::PassphraseColumn'
18             );
19              
20             __PACKAGE__->table('user');
21              
22             __PACKAGE__->add_columns(
23             "id",
24             {
25             data_type => "integer",
26             extra => { unsigned => 1 },
27             is_auto_increment => 1,
28             is_nullable => 0,
29             },
30             "username",
31             { data_type => "varchar", is_nullable => 0, size => 32 },
32             #"password",
33             #{ data_type => "varchar", is_nullable => 1, size => 255 },
34            
35             password => {
36             is_serializable => 1,
37             data_type => 'varchar',
38             is_nullable => 1,
39             size => 'max',
40             passphrase => 'rfc2307',
41             passphrase_class => 'BlowfishCrypt',
42             passphrase_args => {
43             cost => 9,
44             salt_random => 1,
45             },
46             passphrase_check_method => 'check_password',
47             },
48            
49             "full_name",
50             { data_type => "varchar", is_nullable => 1, size => 255 },
51             "last_login_ts",
52             {
53             data_type => "datetime",
54             datetime_undef_if_invalid => 1,
55             is_nullable => 1,
56             },
57             "disabled",
58             { data_type => "tinyint", default_value => 0, is_nullable => 0 },
59             "disabled_ts",
60             {
61             data_type => "datetime",
62             datetime_undef_if_invalid => 1,
63             is_nullable => 1,
64             },
65             );
66             __PACKAGE__->set_primary_key("id");
67             __PACKAGE__->add_unique_constraint("username", ["username"]);
68              
69             __PACKAGE__->has_many(
70             "user_to_roles",
71             "RapidApp::CoreSchema::Result::UserToRole",
72             { "foreign.username" => "self.username" },
73             { cascade_copy => 0, cascade_delete => 0 },
74             );
75              
76             __PACKAGE__->has_many(
77             "saved_states",
78             "RapidApp::CoreSchema::Result::SavedState",
79             { "foreign.user_id" => "self.id" },
80             { cascade_copy => 0, cascade_delete => 0 },
81             );
82              
83             __PACKAGE__->has_many(
84             "sessions",
85             "RapidApp::CoreSchema::Result::Session",
86             { "foreign.user_id" => "self.id" },
87             { cascade_copy => 0, cascade_delete => 0 },
88             );
89              
90              
91             __PACKAGE__->load_components('+RapidApp::DBIC::Component::TableSpec');
92             __PACKAGE__->TableSpec_m2m( roles => "user_to_roles", 'role');
93              
94             # ----
95             # TODO/FIXME: This is ugly/global, but works. This virtual column
96             # provides a column-based interface to set the password, optionally
97             # passing it through a custom Authen::Passphrase class. The ugly
98             # part is that the Authen::Passphrase class setting is set on the class...
99             # This is being set by Catalyst::Plugin::RapidApp::AuthCore
100             __PACKAGE__->mk_classdata( 'authen_passphrase_class' );
101             __PACKAGE__->mk_classdata( 'authen_passphrase_params' );
102             __PACKAGE__->add_virtual_columns( set_pw => {
103             data_type => "varchar",
104             is_nullable => 1,
105             sql => "SELECT NULL",
106             set_function => sub {
107             my ($self,$pw) = @_;
108             if($pw && $pw ne '') {
109             if($self->authen_passphrase_class) {
110             my %params = (
111             %{ $self->authen_passphrase_params || {} },
112             passphrase => $pw
113             );
114            
115             $pw = $self->authen_passphrase_class->new(%params);
116            
117             # TODO/FIXME: I thought I could pass an Authen::Passphrase object
118             # to the PassphraseColumn, but it seemed to always only create the
119             # default set in passphrase_class, so I am just doing it manually
120             my $pf = $pw->can('as_rfc2307')
121             ? $pw->as_rfc2307 : join('','{CRYPT}',$pw->as_crypt);
122            
123             $self->store_column( password => $pf );
124             $self->make_column_dirty('password');
125             }
126             else {
127             $self->password($pw);
128             }
129             $self->update;
130             }
131             }
132             });
133             # ----
134              
135             __PACKAGE__->apply_TableSpec;
136              
137              
138             # Always returns undef unless 'linked_user_model' is configured
139             sub linkedRow {
140 0     0 0   my $self = shift;
141 0   0       $self->{_linkedRow} //= do {
142 0           my $Row = undef;
143 0 0         if($self->can('_find_linkedRow')) {
144 0   0       $Row = $self->_find_linkedRow || $self->_create_linkedRow;
145             }
146             $Row
147 0           }
148             }
149              
150              
151             __PACKAGE__->TableSpec_set_conf(
152             title => 'User',
153             title_multi => 'Users',
154             iconCls => 'ra-icon-businessman',
155             multiIconCls => 'ra-icon-businessmen',
156             display_column => 'username',
157             priority_rel_columns => 1,
158             columns => {
159             id => { width => 40, header => 'Id', profiles => ['noedit'] },
160             username => { width => 90, header => 'Username' },
161             password => { width => 120, header => 'Password (hashed)', profiles => ['noedit'] },
162             full_name => { width => 120, header => 'Full Name', hidden => \1 },
163            
164             last_login_ts => {
165             hidden => \1, # temp: hide only so it doesn't show between password and set_pw
166             header => 'Last Login',
167             width => 120, allow_edit => \0, allow_add => \0
168             },
169            
170             disabled => {
171             width => 60, profiles => ['bool'], hidden => \1,
172             # Not implemented yet
173             no_column => \1, no_quick_search => \1, no_multifilter => \1
174             },
175            
176             disabled_ts => {
177             width => 120, hidden => \1,
178             # Not implemented yet
179             no_column => \1, no_quick_search => \1, no_multifilter => \1
180             },
181            
182            
183            
184             roles => { width => 220, header => 'Roles' },
185             sessions => { width => 120, header => 'Sessions' },
186             saved_states => { width => 130, header => 'Saved Views' },
187             user_to_roles => { width => 130, header => 'User to Roles', hidden => \1 },
188            
189             set_pw => {
190             header => 'Set Password*',
191             width => 130,
192             editor => { xtype => 'ra-change-password-field' },
193             renderer => 'Ext.ux.RapidApp.renderSetPwValue'
194             },
195            
196             }
197             );
198              
199              
200             __PACKAGE__->meta->make_immutable;
201             1;