/[A3C]/lib/A3C/Model/User.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /lib/A3C/Model/User.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 45 - (hide annotations)
Sun Mar 30 22:29:42 2008 UTC (16 years ago) by dpavlin
File size: 8070 byte(s)
- added all fields from ldap to models
- models now have informative name accessor
1 dpavlin 2 use strict;
2     use warnings;
3    
4 dpavlin 11 package A3C::Model::User;
5 dpavlin 2 use Jifty::DBI::Schema;
6    
7 dpavlin 14 use utf8;
8    
9 dpavlin 11 use A3C::Record schema {
10 dpavlin 2
11 dpavlin 16 column uid =>
12     label is ('uid'),
13     is indexed,
14     is mandatory,
15     is distinct;
16    
17     column hrEduPersonUniqueID =>
18     label is ('hrEduPersonUniqueID'),
19     is indexed,
20 dpavlin 18 is distinct,
21 dpavlin 4 is mandatory;
22    
23     column cn =>
24 dpavlin 21 label is _('Ime i prezime'),
25 dpavlin 29 is mandatory;
26 dpavlin 4
27     column sn =>
28     label is _('Prezime'),
29     is mandatory;
30    
31     column givenName =>
32     label is _('Ime'),
33     is mandatory;
34    
35 dpavlin 16 column mail =>
36 dpavlin 4 type is 'text',
37     is mandatory,
38 dpavlin 18 label is _('Email address'), default is '',
39     is immutable,
40     is distinct;
41 dpavlin 4
42     column password =>
43     is unreadable,
44     label is _('Password'),
45     type is 'varchar',
46     hints is _('Your password should be at least six characters'),
47     render_as 'password',
48     # filters are 'Jifty::DBI::Filter::SaltHash',
49     is mandatory;
50    
51     column telephoneNumber =>
52     type is 'text',
53     label is _('Telefonski broj'),
54     hint is '+385 xx yyyyyy';
55    
56     column hrEduPersonExtensionNumber =>
57     label is _('Lokalni telefonski broj');
58    
59     column mobile =>
60     label is _('Broj mobilnog telefona');
61    
62     column facsimileTelephoneNumber =>
63     label is _('Fax broj');
64    
65     column hrEduPersonUniqueNumber =>
66 dpavlin 10 # is mandatory,
67 dpavlin 35 label is _('Unique number');
68 dpavlin 4
69     column hrEduPersonDateOfBirth =>
70     type is 'date',
71 dpavlin 15 render as 'date',
72 dpavlin 16 label is _('Datum rođenja'),
73     filters are 'Jifty::DBI::Filter::Date';
74 dpavlin 4
75     column hrEduPersonGender =>
76     label is _('Spol');
77    
78     column jpegPhoto =>
79     label is _('Slika');
80    
81     column userCertificate =>
82     label is _('Ceritifikat');
83    
84     column labeledURI =>
85     label is _('URI adresa');
86    
87     column wtAdminType =>
88     label is _('Tip administratora'),
89 dpavlin 15 valid are [ '', 'AS', 'AI', 'AR', 'AHU' ];
90 dpavlin 4
91 dpavlin 42 column hrEduPersonHomeOrg =>
92     label is _('Oznaka matične ustanove'),
93     hint is 'CARNet',
94     is mandatory;
95    
96 dpavlin 4 column hrEduPersonProfessionalStatus =>
97     label is _('Stručni status'),
98 dpavlin 15 valid are [
99     '',
100     'NKV',
101     'PKV',
102     'KV',
103     'VKV',
104     'SSS',
105     'VS',
106     'VSS',
107     'VŠS',
108     'MR',
109     'DR',
110     ],
111     default is '';
112 dpavlin 4
113     column hrEduPersonAcademicStatus =>
114     label is _('Zvanje'),
115 dpavlin 15 valid are [
116     '',
117 dpavlin 4 'knjižničar',
118 dpavlin 15 'viši knjižničar',
119 dpavlin 4 'korepetitor',
120 dpavlin 15 'viši korepetitor',
121 dpavlin 4 'lektor',
122 dpavlin 15 'viši lektor',
123     'stručni suradnik',
124     'asistent visoke škole',
125     'profesor visoke škole',
126 dpavlin 4 'mlađi asistent',
127 dpavlin 15 'znanstveni novak',
128     'znanstveni asistent',
129     'znanstveni suradnik',
130 dpavlin 4 'predavač',
131 dpavlin 15 'viši predavač',
132     'asistent',
133     'asistent - predavač',
134     'viši asistent',
135     'docent',
136     'izvanredni profesor',
137 dpavlin 4 'redoviti profesor',
138 dpavlin 15 'znanstveni savjetnik',
139 dpavlin 4 'viši znanstveni suradnik',
140 dpavlin 15 ],
141     default is '';
142 dpavlin 4
143     column hrEduPersonScienceArea =>
144     label is _('Područje znanosti'),
145 dpavlin 15 valid are [
146     '',
147 dpavlin 4 'Tehničke znanosti',
148     'Prirodne znanosti',
149     'Humanističke znanosti',
150     'Društvene znanosti',
151     'Biotehničke znanosti',
152     'Biomedicina i zdravstvo',
153 dpavlin 15 ],
154     default is '';
155 dpavlin 4
156 dpavlin 45 column 'o';
157     column 'l';
158     column 'postalAddress';
159    
160 dpavlin 42 # column organization =>
161     # refers_to A3C::Model::Organization by 'id',
162     # is mandatory;
163 dpavlin 32
164 dpavlin 4 column hrEduPersonAffiliation =>
165     label is _('Povezanost s ustanovom'),
166     is mandatory,
167 dpavlin 15 valid are [
168     'učenik',
169     'student',
170 dpavlin 4 'djelatnik',
171 dpavlin 15 'vanjski suradnik',
172     'korisnik usluge',
173 dpavlin 4 'gost',
174 dpavlin 15 ],
175     default is 'korisnik usluge';
176 dpavlin 4
177     column hrEduPersonPrimaryAffiliation =>
178     label is _('Temeljna povezanost s ustanovom');
179     is mandatory,
180 dpavlin 15 valid are [
181     'učenik',
182     'student',
183 dpavlin 4 'djelatnik',
184 dpavlin 15 'vanjski suradnik',
185     'korisnik usluge',
186 dpavlin 4 'gost',
187 dpavlin 15 ],
188     default is 'korisnik usluge';
189 dpavlin 4
190     column hrEduPersonStudentCategory =>
191     label is 'Vrsta studenta',
192 dpavlin 15 valid are [
193     '',
194     'osnovnoškolac',
195     'srednjoškolac',
196     'student stručnog studija',
197     'preddiplomac',
198     'postdiplomac',
199 dpavlin 4 'dodiplomac',
200     'pauzira godinu',
201     'prekid studija',
202 dpavlin 15 ],
203     default is '';
204 dpavlin 4
205     column hrEduPersonExpireDate =>
206     label is _('Datum isteka temeljne povezanosti'),
207     type is 'date',
208 dpavlin 15 render as 'date',
209 dpavlin 4 is mandatory,
210 dpavlin 16 filters are 'Jifty::DBI::Filter::Date';
211 dpavlin 4
212     column hrEduPersonTitle =>
213     label is 'Položaj u ustanovi',
214 dpavlin 15 valid are [ # FIXME reorder
215     '',
216 dpavlin 4 'dekan',
217     'direktor',
218     'pomoćnik ravnatelja',
219     'predstojnik zavoda',
220     'pročelnik katedre',
221     'pročelnik odsjeka',
222     'pročelnik sveučilišnog odjela',
223     'prodekan',
224     'prorektor',
225     'ravnatelj',
226     'rektor',
227     'voditelj laboratorija',
228     'voditelj odjela',
229     'voditelj organizacijske jedini',
230     'voditelj projekta',
231     'zamjenik pročelnika sveučilišn',
232     'zamjenik ravnatelja',
233 dpavlin 15 ],
234     default is '';
235 dpavlin 4
236     column hrEduPersonRole =>
237     label is 'Uloga u ustanovi',
238 dpavlin 15 valid are [
239     '',
240 dpavlin 4 'administrator imenika',
241     'CARNet koordinator',
242     'CARNet sistem inženjer',
243     'ICT koordinator',
244     'ISVU koordinator',
245     'kontakt za sigurnosna pitanja',
246     'MS koordinator',
247     'MATICA operater',
248     'MATICA urednik',
249 dpavlin 15 ],
250     default is '';
251 dpavlin 4
252     column hrEduPersonStaffCategory =>
253     label is 'Vrsta posla u ustanovi',
254 dpavlin 15 valid are [
255 dpavlin 4 'administrativno osoblje',
256     'ICT podrška',
257     'istraživači',
258     'nastavno osoblje',
259     'osoblje knjižnice',
260     'tehničko osoblje',
261     ];
262    
263     column hrEduPersonGroupMember =>
264     label is 'Pripadnost grupi',
265     hint is 'skolskagodina::razred';
266    
267     column ou =>
268     label is _('Organizacijska jedinica');
269    
270     column roomNumber =>
271     label is _('Broj sobe');
272    
273     column homePostalAddress =>
274 dpavlin 12 label is _('Kućna poštanska adresa'),
275     render as 'textarea';
276 dpavlin 4
277     column homePhone =>
278     label is _('Kućni telefonski broj');
279    
280     column hrEduPersonCommURI =>
281     label is _('Desktop uređaj');
282    
283     column hrEduPersonPrivacy =>
284     label is _('Oznaka privatnosti');
285    
286 dpavlin 23 column loginShell =>
287 dpavlin 45 label is _('login shell');
288 dpavlin 23
289     column uidNumber =>
290 dpavlin 45 label is _('uid number'),
291 dpavlin 23 type is 'int';
292    
293     column gidNumber =>
294 dpavlin 45 label is _('gid number');
295 dpavlin 23 type is 'int';
296    
297     column homeDirectory =>
298 dpavlin 45 label is _('home directory');
299 dpavlin 23
300 dpavlin 2 };
301    
302 dpavlin 18 # we don't use following mixing because it wants to send notificaitons on e-mail address change
303     #use Jifty::Plugin::User::Mixin::Model::User;
304 dpavlin 4 use Jifty::Plugin::Authentication::Password::Mixin::Model::User;
305     #use Jifty::Plugin::OpenID::Mixin::Model::User;
306     use Jifty::Plugin::ActorMetadata::Mixin::Model::ActorMetadata; # created_by, created_on, updated_on
307    
308 dpavlin 2 # Your model-specific methods go here.
309    
310 dpavlin 18 =head2 before_create
311 dpavlin 16
312 dpavlin 18 Implement virtual columns, for now put mail from ldap into email row
313 dpavlin 16
314     =cut
315    
316 dpavlin 18 =for later
317    
318     sub before_create {
319     my ($self, $attr) = @_;
320     if ( ! $attr->{'email'} ) {
321     warn "push mail to email";
322     $attr->{'email'} = $attr->{'mail'};
323     }
324 dpavlin 16 }
325    
326 dpavlin 18 =cut
327    
328     =head2 email
329    
330     Accessor for compatibility with Jifty mixins
331    
332     =cut
333    
334     sub email {
335     my $self = shift;
336     return $self->__value('mail');
337     }
338    
339     sub email_confirmed { 1 };
340    
341 dpavlin 45 =head2 name
342    
343     =cut
344    
345     sub name {
346     my $self = shift;
347     return $self->__value('cn');
348     }
349    
350 dpavlin 4 =head2 validate_telephoneNumber
351    
352     =cut
353    
354     sub validate_telephoneNumber {
355     my ( $self, $value ) = @_;
356    
357     return ( 0, _('Telephone number invalid') ) if $value !~ m/^(\+?385)?[\d\s-]+$/;
358    
359     return ( 1, 'OK' );
360     }
361    
362 dpavlin 38 =head2 hrEduPersonUniqueNumber
363 dpavlin 35
364     Check if JMBG is valid
365    
366     =cut
367    
368     sub validate_hrEduPersonUniqueNumber {
369     my ( $self, $value ) = @_;
370    
371     if ( $value =~ m/^JMBG:\s+(\d+)$/ ) {
372    
373     my $jmbg = $1;
374    
375     return ( 0, _('JMBG must have 13 digits') ) unless length($jmbg) == 13;
376    
377     sub digit_at {
378     my ($jmbg,$pos) = @_;
379     return ord(substr($jmbg,$pos,1)) - ord('0');
380     }
381    
382     my $sum;
383     my $fact = 7;
384    
385     foreach my $i ( 0 .. 11 ) {
386     my $c = digit_at( $jmbg, $i );
387     $sum += $c * $fact;
388     # warn "## $c * $fact => $sum\n";
389     $fact--;
390     $fact = 7 if $fact == 1;
391     }
392    
393     my $ost = $sum % 11;
394     $ost = 11 - $ost if $ost > 1;
395    
396     return ( 0, _("JMBG is invalid") ) if $ost != digit_at( $jmbg, 12 );
397     }
398    
399     return ( 1, 'OK' );
400     }
401    
402 dpavlin 16 =head2 canonicalize_hrEduPersonExpireDate
403    
404     Support NONE as 2042-12-30
405    
406     =cut
407    
408     sub canonicalize_hrEduPersonExpireDate {
409     my ( $self, $value ) = @_;
410    
411 dpavlin 33 if ( lc($value) eq 'none' ) {
412 dpavlin 16 $self->log->warn("fixed hrEduPersonExpireDate");
413     $value = '2042-12-30';
414     }
415    
416     return $value;
417     }
418    
419     =head2 current_user_can
420    
421     =cut
422    
423 dpavlin 7 sub current_user_can {
424     # FIXME no security for now :-)
425     return 1;
426     }
427    
428 dpavlin 45
429 dpavlin 2 1;
430    

  ViewVC Help
Powered by ViewVC 1.1.26