/[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 35 - (hide annotations)
Tue Mar 18 19:58:34 2008 UTC (11 years, 5 months ago) by dpavlin
File size: 7792 byte(s)
validate JMBG (REAL JMBGs :-)
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     column hrEduPersonProfessionalStatus =>
92     label is _('Stručni status'),
93 dpavlin 15 valid are [
94     '',
95     'NKV',
96     'PKV',
97     'KV',
98     'VKV',
99     'SSS',
100     'VS',
101     'VSS',
102     'VŠS',
103     'MR',
104     'DR',
105     ],
106     default is '';
107 dpavlin 4
108     column hrEduPersonAcademicStatus =>
109     label is _('Zvanje'),
110 dpavlin 15 valid are [
111     '',
112 dpavlin 4 'knjižničar',
113 dpavlin 15 'viši knjižničar',
114 dpavlin 4 'korepetitor',
115 dpavlin 15 'viši korepetitor',
116 dpavlin 4 'lektor',
117 dpavlin 15 'viši lektor',
118     'stručni suradnik',
119     'asistent visoke škole',
120     'profesor visoke škole',
121 dpavlin 4 'mlađi asistent',
122 dpavlin 15 'znanstveni novak',
123     'znanstveni asistent',
124     'znanstveni suradnik',
125 dpavlin 4 'predavač',
126 dpavlin 15 'viši predavač',
127     'asistent',
128     'asistent - predavač',
129     'viši asistent',
130     'docent',
131     'izvanredni profesor',
132 dpavlin 4 'redoviti profesor',
133 dpavlin 15 'znanstveni savjetnik',
134 dpavlin 4 'viši znanstveni suradnik',
135 dpavlin 15 ],
136     default is '';
137 dpavlin 4
138     column hrEduPersonScienceArea =>
139     label is _('Područje znanosti'),
140 dpavlin 15 valid are [
141     '',
142 dpavlin 4 'Tehničke znanosti',
143     'Prirodne znanosti',
144     'Humanističke znanosti',
145     'Društvene znanosti',
146     'Biotehničke znanosti',
147     'Biomedicina i zdravstvo',
148 dpavlin 15 ],
149     default is '';
150 dpavlin 4
151 dpavlin 32 column organization =>
152     refers_to A3C::Model::Organization by 'id',
153     is mandatory;
154    
155 dpavlin 4 column hrEduPersonAffiliation =>
156     label is _('Povezanost s ustanovom'),
157     is mandatory,
158 dpavlin 15 valid are [
159     'učenik',
160     'student',
161 dpavlin 4 'djelatnik',
162 dpavlin 15 'vanjski suradnik',
163     'korisnik usluge',
164 dpavlin 4 'gost',
165 dpavlin 15 ],
166     default is 'korisnik usluge';
167 dpavlin 4
168     column hrEduPersonPrimaryAffiliation =>
169     label is _('Temeljna povezanost s ustanovom');
170     is mandatory,
171 dpavlin 15 valid are [
172     'učenik',
173     'student',
174 dpavlin 4 'djelatnik',
175 dpavlin 15 'vanjski suradnik',
176     'korisnik usluge',
177 dpavlin 4 'gost',
178 dpavlin 15 ],
179     default is 'korisnik usluge';
180 dpavlin 4
181     column hrEduPersonStudentCategory =>
182     label is 'Vrsta studenta',
183 dpavlin 15 valid are [
184     '',
185     'osnovnoškolac',
186     'srednjoškolac',
187     'student stručnog studija',
188     'preddiplomac',
189     'postdiplomac',
190 dpavlin 4 'dodiplomac',
191     'pauzira godinu',
192     'prekid studija',
193 dpavlin 15 ],
194     default is '';
195 dpavlin 4
196     column hrEduPersonExpireDate =>
197     label is _('Datum isteka temeljne povezanosti'),
198     type is 'date',
199 dpavlin 15 render as 'date',
200 dpavlin 4 is mandatory,
201 dpavlin 16 filters are 'Jifty::DBI::Filter::Date';
202 dpavlin 4
203     column hrEduPersonTitle =>
204     label is 'Položaj u ustanovi',
205 dpavlin 15 valid are [ # FIXME reorder
206     '',
207 dpavlin 4 'dekan',
208     'direktor',
209     'pomoćnik ravnatelja',
210     'predstojnik zavoda',
211     'pročelnik katedre',
212     'pročelnik odsjeka',
213     'pročelnik sveučilišnog odjela',
214     'prodekan',
215     'prorektor',
216     'ravnatelj',
217     'rektor',
218     'voditelj laboratorija',
219     'voditelj odjela',
220     'voditelj organizacijske jedini',
221     'voditelj projekta',
222     'zamjenik pročelnika sveučilišn',
223     'zamjenik ravnatelja',
224 dpavlin 15 ],
225     default is '';
226 dpavlin 4
227     column hrEduPersonRole =>
228     label is 'Uloga u ustanovi',
229 dpavlin 15 valid are [
230     '',
231 dpavlin 4 'administrator imenika',
232     'CARNet koordinator',
233     'CARNet sistem inženjer',
234     'ICT koordinator',
235     'ISVU koordinator',
236     'kontakt za sigurnosna pitanja',
237     'MS koordinator',
238     'MATICA operater',
239     'MATICA urednik',
240 dpavlin 15 ],
241     default is '';
242 dpavlin 4
243     column hrEduPersonStaffCategory =>
244     label is 'Vrsta posla u ustanovi',
245 dpavlin 15 valid are [
246 dpavlin 4 'administrativno osoblje',
247     'ICT podrška',
248     'istraživači',
249     'nastavno osoblje',
250     'osoblje knjižnice',
251     'tehničko osoblje',
252     ];
253    
254     column hrEduPersonGroupMember =>
255     label is 'Pripadnost grupi',
256     hint is 'skolskagodina::razred';
257    
258     column ou =>
259     label is _('Organizacijska jedinica');
260    
261     column roomNumber =>
262     label is _('Broj sobe');
263    
264     column homePostalAddress =>
265 dpavlin 12 label is _('Kućna poštanska adresa'),
266     render as 'textarea';
267 dpavlin 4
268     column homePhone =>
269     label is _('Kućni telefonski broj');
270    
271     column hrEduPersonCommURI =>
272     label is _('Desktop uređaj');
273    
274     column hrEduPersonPrivacy =>
275     label is _('Oznaka privatnosti');
276    
277 dpavlin 23 column loginShell =>
278     label is _('shell');
279    
280     column uidNumber =>
281     label is _('uid'),
282     type is 'int';
283    
284     column gidNumber =>
285     label is _('gid');
286     type is 'int';
287    
288     column homeDirectory =>
289     label is _('home');
290    
291 dpavlin 2 };
292    
293 dpavlin 18 # we don't use following mixing because it wants to send notificaitons on e-mail address change
294     #use Jifty::Plugin::User::Mixin::Model::User;
295 dpavlin 4 use Jifty::Plugin::Authentication::Password::Mixin::Model::User;
296     #use Jifty::Plugin::OpenID::Mixin::Model::User;
297     use Jifty::Plugin::ActorMetadata::Mixin::Model::ActorMetadata; # created_by, created_on, updated_on
298    
299 dpavlin 2 # Your model-specific methods go here.
300    
301 dpavlin 18 =head2 before_create
302 dpavlin 16
303 dpavlin 18 Implement virtual columns, for now put mail from ldap into email row
304 dpavlin 16
305     =cut
306    
307 dpavlin 18 =for later
308    
309     sub before_create {
310     my ($self, $attr) = @_;
311     if ( ! $attr->{'email'} ) {
312     warn "push mail to email";
313     $attr->{'email'} = $attr->{'mail'};
314     }
315 dpavlin 16 }
316    
317 dpavlin 18 =cut
318    
319     =head2 email
320    
321     Accessor for compatibility with Jifty mixins
322    
323     =cut
324    
325     sub email {
326     my $self = shift;
327     return $self->__value('mail');
328     }
329    
330     sub email_confirmed { 1 };
331    
332 dpavlin 4 =head2 validate_telephoneNumber
333    
334     =cut
335    
336     sub validate_telephoneNumber {
337     my ( $self, $value ) = @_;
338    
339     return ( 0, _('Telephone number invalid') ) if $value !~ m/^(\+?385)?[\d\s-]+$/;
340    
341     return ( 1, 'OK' );
342     }
343    
344 dpavlin 35 =head hrEduPersonUniqueNumber
345    
346     Check if JMBG is valid
347    
348     =cut
349    
350     sub validate_hrEduPersonUniqueNumber {
351     my ( $self, $value ) = @_;
352    
353     if ( $value =~ m/^JMBG:\s+(\d+)$/ ) {
354    
355     my $jmbg = $1;
356    
357     return ( 0, _('JMBG must have 13 digits') ) unless length($jmbg) == 13;
358    
359     sub digit_at {
360     my ($jmbg,$pos) = @_;
361     return ord(substr($jmbg,$pos,1)) - ord('0');
362     }
363    
364     my $sum;
365     my $fact = 7;
366    
367     foreach my $i ( 0 .. 11 ) {
368     my $c = digit_at( $jmbg, $i );
369     $sum += $c * $fact;
370     # warn "## $c * $fact => $sum\n";
371     $fact--;
372     $fact = 7 if $fact == 1;
373     }
374    
375     my $ost = $sum % 11;
376     $ost = 11 - $ost if $ost > 1;
377    
378     return ( 0, _("JMBG is invalid") ) if $ost != digit_at( $jmbg, 12 );
379     }
380    
381     return ( 1, 'OK' );
382     }
383    
384 dpavlin 16 =head2 canonicalize_hrEduPersonExpireDate
385    
386     Support NONE as 2042-12-30
387    
388     =cut
389    
390     sub canonicalize_hrEduPersonExpireDate {
391     my ( $self, $value ) = @_;
392    
393 dpavlin 33 if ( lc($value) eq 'none' ) {
394 dpavlin 16 $self->log->warn("fixed hrEduPersonExpireDate");
395     $value = '2042-12-30';
396     }
397    
398     return $value;
399     }
400    
401     =head2 current_user_can
402    
403     =cut
404    
405 dpavlin 7 sub current_user_can {
406     # FIXME no security for now :-)
407     return 1;
408     }
409    
410 dpavlin 2 1;
411    

  ViewVC Help
Powered by ViewVC 1.1.26