Add a country column to users
[gruntmaster-data.git] / lib / Gruntmaster / Data / Result / User.pm
1 use utf8;
2 package Gruntmaster::Data::Result::User;
3
4 # Created by DBIx::Class::Schema::Loader
5 # DO NOT MODIFY THE FIRST PART OF THIS FILE
6
7 =head1 NAME
8
9 Gruntmaster::Data::Result::User - List of users
10
11 =cut
12
13 use strict;
14 use warnings;
15
16 use base 'DBIx::Class::Core';
17
18 =head1 TABLE: C<users>
19
20 =cut
21
22 __PACKAGE__->table("users");
23
24 =head1 ACCESSORS
25
26 =head2 id
27
28 data_type: 'text'
29 is_nullable: 0
30
31 =head2 passphrase
32
33 data_type: 'text'
34 is_nullable: 1
35
36 RFC2307-encoded passphrase
37
38 =head2 admin
39
40 data_type: 'boolean'
41 default_value: false
42 is_nullable: 0
43
44 =head2 name
45
46 data_type: 'text'
47 is_nullable: 1
48
49 Full name of user
50
51 =head2 email
52
53 data_type: 'text'
54 is_nullable: 1
55
56 =head2 phone
57
58 data_type: 'text'
59 is_nullable: 1
60
61 =head2 town
62
63 data_type: 'text'
64 is_nullable: 1
65
66 =head2 university
67
68 data_type: 'text'
69 is_nullable: 1
70
71 =head2 level
72
73 data_type: 'text'
74 is_nullable: 1
75
76 Highschool, Undergraduate, Master, Doctorate or Other
77
78 =head2 country
79
80 data_type: 'text'
81 is_nullable: 1
82
83 =head2 lastjob
84
85 data_type: 'bigint'
86 is_nullable: 1
87
88 Unix time when this user last submitted a job
89
90 =cut
91
92 __PACKAGE__->add_columns(
93 "id",
94 { data_type => "text", is_nullable => 0 },
95 "passphrase",
96 { data_type => "text", is_nullable => 1 },
97 "admin",
98 { data_type => "boolean", default_value => \"false", is_nullable => 0 },
99 "name",
100 { data_type => "text", is_nullable => 1 },
101 "email",
102 { data_type => "text", is_nullable => 1 },
103 "phone",
104 { data_type => "text", is_nullable => 1 },
105 "town",
106 { data_type => "text", is_nullable => 1 },
107 "university",
108 { data_type => "text", is_nullable => 1 },
109 "level",
110 { data_type => "text", is_nullable => 1 },
111 "country",
112 { data_type => "text", is_nullable => 1 },
113 "lastjob",
114 { data_type => "bigint", is_nullable => 1 },
115 );
116
117 =head1 PRIMARY KEY
118
119 =over 4
120
121 =item * L</id>
122
123 =back
124
125 =cut
126
127 __PACKAGE__->set_primary_key("id");
128
129 =head1 RELATIONS
130
131 =head2 contest_statuses
132
133 Type: has_many
134
135 Related object: L<Gruntmaster::Data::Result::ContestStatus>
136
137 =cut
138
139 __PACKAGE__->has_many(
140 "contest_statuses",
141 "Gruntmaster::Data::Result::ContestStatus",
142 { "foreign.owner" => "self.id" },
143 { cascade_copy => 0, cascade_delete => 0 },
144 );
145
146 =head2 contests
147
148 Type: has_many
149
150 Related object: L<Gruntmaster::Data::Result::Contest>
151
152 =cut
153
154 __PACKAGE__->has_many(
155 "contests",
156 "Gruntmaster::Data::Result::Contest",
157 { "foreign.owner" => "self.id" },
158 { cascade_copy => 0, cascade_delete => 0 },
159 );
160
161 =head2 jobs
162
163 Type: has_many
164
165 Related object: L<Gruntmaster::Data::Result::Job>
166
167 =cut
168
169 __PACKAGE__->has_many(
170 "jobs",
171 "Gruntmaster::Data::Result::Job",
172 { "foreign.owner" => "self.id" },
173 { cascade_copy => 0, cascade_delete => 0 },
174 );
175
176 =head2 opens
177
178 Type: has_many
179
180 Related object: L<Gruntmaster::Data::Result::Open>
181
182 =cut
183
184 __PACKAGE__->has_many(
185 "opens",
186 "Gruntmaster::Data::Result::Open",
187 { "foreign.owner" => "self.id" },
188 { cascade_copy => 0, cascade_delete => 0 },
189 );
190
191 =head2 problem_statuses
192
193 Type: has_many
194
195 Related object: L<Gruntmaster::Data::Result::ProblemStatus>
196
197 =cut
198
199 __PACKAGE__->has_many(
200 "problem_statuses",
201 "Gruntmaster::Data::Result::ProblemStatus",
202 { "foreign.owner" => "self.id" },
203 { cascade_copy => 0, cascade_delete => 0 },
204 );
205
206 =head2 problems
207
208 Type: has_many
209
210 Related object: L<Gruntmaster::Data::Result::Problem>
211
212 =cut
213
214 __PACKAGE__->has_many(
215 "problems",
216 "Gruntmaster::Data::Result::Problem",
217 { "foreign.owner" => "self.id" },
218 { cascade_copy => 0, cascade_delete => 0 },
219 );
220
221
222 # Created by DBIx::Class::Schema::Loader v0.07042 @ 2015-01-29 18:45:35
223 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:rpx697B3St+ICCSbOn4cbQ
224
225 use Class::Method::Modifiers qw/after/;
226
227 after qw/insert update delete/ => sub {
228 my ($self) = @_;
229 Gruntmaster::Data::purge '/us/';
230 Gruntmaster::Data::purge '/us/' . $self->id;
231 };
232
233 use Authen::Passphrase;
234 use Authen::Passphrase::BlowfishCrypt;
235
236 sub check_passphrase {
237 my ($self, $pw) = @_;
238 Authen::Passphrase->from_rfc2307($self->passphrase)->match($pw)
239 }
240
241 sub set_passphrase {
242 my ($self, $pw) = @_;
243 $self->update({passphrase => Authen::Passphrase::BlowfishCrypt->new(
244 cost => 10,
245 passphrase => $pw,
246 salt_random => 1,
247 )->as_rfc2307});
248 }
249
250 1;
251
252 __END__
253
254 =head1 METHODS
255
256 =head2 check_passphrase(I<$passphrase>)
257
258 Returns true if I<$passphrase> is the correct passphrase, false otherwise.
259
260 =head2 set_passphrase(I<$passphrase>)
261
262 Changes the passphrase to I<$passphrase>.
263
264 =head1 AUTHOR
265
266 Marius Gavrilescu E<lt>marius@ieval.roE<gt>
267
268 =head1 COPYRIGHT AND LICENSE
269
270 Copyright (C) 2014 by Marius Gavrilescu
271
272 This library is free software; you can redistribute it and/or modify
273 it under the same terms as Perl itself, either Perl version 5.18.1 or,
274 at your option, any later version of Perl 5 you may have available.
275
276
277 =cut
This page took 0.029353 seconds and 4 git commands to generate.