--- lib/A3C/Model/User.pm 2008/03/13 18:07:28 16 +++ lib/A3C/Model/User.pm 2008/03/30 13:32:12 38 @@ -17,39 +17,27 @@ column hrEduPersonUniqueID => label is ('hrEduPersonUniqueID'), is indexed, - is mandatory, - is distinct; - - column name => - type is 'text', - label is _('Ime'), + is distinct, is mandatory; column cn => - label is _('Ime'), - type is 'virtual'; + label is _('Ime i prezime'), + is mandatory; column sn => - type is 'virtual', label is _('Prezime'), is mandatory; column givenName => - type is 'virtual', label is _('Ime'), is mandatory; column mail => - type is 'virtual'; - - column email => type is 'text', is mandatory, - label is _('Email address'), default is '', is immutable, is distinct; - - column email_confirmed => - label is _('Email address confirmed?'), - type is 'boolean'; + label is _('Email address'), default is '', + is immutable, + is distinct; column password => is unreadable, @@ -76,7 +64,7 @@ column hrEduPersonUniqueNumber => # is mandatory, - label is _('JMBG'); + label is _('Unique number'); column hrEduPersonDateOfBirth => type is 'date', @@ -160,6 +148,10 @@ ], default is ''; + column organization => + refers_to A3C::Model::Organization by 'id', + is mandatory; + column hrEduPersonAffiliation => label is _('Povezanost s ustanovom'), is mandatory, @@ -263,38 +255,12 @@ label is 'Pripadnost grupi', hint is 'skolskagodina::razred'; - column o => - label is _('Naziv matične ustanove'), - is mandatory; - - column hrEduPersonHomeOrg => - label is _('Oznaka matične ustanove'), - hint is 'CARNet', - is mandatory; - column ou => label is _('Organizacijska jedinica'); column roomNumber => label is _('Broj sobe'); - column postalAddress => - label is _('Poštanska adresa'), - render as 'textarea', - is mandatory; - - column l => - label is _('Mjesto'), - hist is 'Zagreb', - is mandatory; - - column postalCode => - label is _('Poštanski broj'), - hint is 'HR-10000'; - - column street => - label is _('Ulica i kućni broj'); - column homePostalAddress => label is _('Kućna poštanska adresa'), render as 'textarea'; @@ -308,26 +274,61 @@ column hrEduPersonPrivacy => label is _('Oznaka privatnosti'); + column loginShell => + label is _('shell'); + + column uidNumber => + label is _('uid'), + type is 'int'; + + column gidNumber => + label is _('gid'); + type is 'int'; + + column homeDirectory => + label is _('home'); + }; -use Jifty::Plugin::User::Mixin::Model::User; +# we don't use following mixing because it wants to send notificaitons on e-mail address change +#use Jifty::Plugin::User::Mixin::Model::User; use Jifty::Plugin::Authentication::Password::Mixin::Model::User; #use Jifty::Plugin::OpenID::Mixin::Model::User; use Jifty::Plugin::ActorMetadata::Mixin::Model::ActorMetadata; # created_by, created_on, updated_on # Your model-specific methods go here. -=head2 set_mail +=head2 before_create + +Implement virtual columns, for now put mail from ldap into email row + +=cut + +=for later + +sub before_create { + my ($self, $attr) = @_; + if ( ! $attr->{'email'} ) { + warn "push mail to email"; + $attr->{'email'} = $attr->{'mail'}; + } +} + +=cut -Put mail from ldap into email row +=head2 email + +Accessor for compatibility with Jifty mixins =cut -sub set_mail { - my ($self,$v) = @_; - $self->set_email( $v ); +sub email { + my $self = shift; + return $self->__value('mail'); } +sub email_confirmed { 1 }; + =head2 validate_telephoneNumber =cut @@ -340,6 +341,46 @@ return ( 1, 'OK' ); } +=head2 hrEduPersonUniqueNumber + +Check if JMBG is valid + +=cut + +sub validate_hrEduPersonUniqueNumber { + my ( $self, $value ) = @_; + + if ( $value =~ m/^JMBG:\s+(\d+)$/ ) { + + my $jmbg = $1; + + return ( 0, _('JMBG must have 13 digits') ) unless length($jmbg) == 13; + + sub digit_at { + my ($jmbg,$pos) = @_; + return ord(substr($jmbg,$pos,1)) - ord('0'); + } + + my $sum; + my $fact = 7; + + foreach my $i ( 0 .. 11 ) { + my $c = digit_at( $jmbg, $i ); + $sum += $c * $fact; +# warn "## $c * $fact => $sum\n"; + $fact--; + $fact = 7 if $fact == 1; + } + + my $ost = $sum % 11; + $ost = 11 - $ost if $ost > 1; + + return ( 0, _("JMBG is invalid") ) if $ost != digit_at( $jmbg, 12 ); + } + + return ( 1, 'OK' ); +} + =head2 canonicalize_hrEduPersonExpireDate Support NONE as 2042-12-30 @@ -349,7 +390,7 @@ sub canonicalize_hrEduPersonExpireDate { my ( $self, $value ) = @_; - if ( $value eq 'NONE' ) { + if ( lc($value) eq 'none' ) { $self->log->warn("fixed hrEduPersonExpireDate"); $value = '2042-12-30'; }