Index: /trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases.pm
===================================================================
--- /trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases.pm	(revision 1075)
+++ /trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases.pm	(revision 1076)
@@ -314,9 +314,75 @@
 }
 
+=head2 compute_default($otype, $id, %cdata)
+
+Return a hash containing value to set for new object
+
+=cut
+
+sub compute_default {
+    my ($self, $otype, $id, %cdata) = @_;
+
+    my %default;
+    foreach my $def (keys %{ $self->{defattr} || {}}) {
+        if ($def =~ /^$otype\.(.*)$/) {
+            $default{$1} = $self->{defattr}{$def} if(!$cdata{$1});
+        }
+    }
+
+    # computed default value (not a simple set)
+    if (lc($otype) eq 'user') {
+        if (!$cdata{homeDirectory}) {
+            $default{homeDirectory} = $self->{defattr}{'user.homebase'}
+                ? $self->{defattr}{'user.homebase'} . "/$id" 
+                : '';
+        }
+
+        if (!$cdata{uidNumber}) {
+            $default{uidNumber} ||= $self->find_next_numeric_id('user', 'uidNumber',
+            $self->{defattr}{'user.min_uid'}, $self->{defattr}{'user.max_uid'});
+        }
+
+        my $mailid = $cdata{givenName} && $cdata{sn}
+            ? sprintf('%s.%s',
+                to_ascii(lc($cdata{givenName})),
+                to_ascii(lc($cdata{sn})),)
+            : undef;
+        $mailid =~ s/\s+/-/g if($mailid);
+
+        if ($mailid &&
+            $self->is_supported_object('aliases') &&
+            ! $self->get_object('aliases', $mailid)) {
+            if (my $attr = $self->attribute($otype, 'mail')) {
+                if ((!$attr->ro) && $self->{defattr}{'user.maildomain'}) {
+                    $default{mail} ||= sprintf('%s@%s',
+                    $mailid,
+                    $self->{defattr}{'user.maildomain'});
+                }
+            }
+            if (my $attr = $self->attribute($otype, 'aliases')) {
+                $default{aliases} ||= $mailid unless ($attr->ro);
+            }
+            if (my $attr = $self->attribute($otype, 'revaliases')) {
+                $default{revaliases} ||= $mailid unless ($attr->ro);
+            }
+        }
+    } elsif (lc($otype) eq 'group') {
+        if (!$cdata{gidNumber}) {
+            $default{gidNumber} ||= $self->find_next_numeric_id(
+                'group', 'gidNumber',
+                $self->{defattr}{'group.min_gid'},
+                $self->{defattr}{'group.max_gid'}
+            );
+        }
+    }
+
+    return %default;
+}
+
 sub _create_c_object {
     my ($self, $otype, $id, %cdata) = @_;
 
     $id ||= ''; # Avoid undef
-    
+
     if (my $chk = (
         lc($otype) eq 'user' || lc($otype) eq 'group')
@@ -334,42 +400,11 @@
 
     # populating default value
-    foreach my $def (keys %{ $self->{defattr} || {}}) {
-        if ($def =~ /^$otype\.(.*)$/) {
-            $cdata{$1} = $self->{defattr}{$def} if(!$cdata{$1});
-        }
-    }
-    if (lc($otype) eq 'user') {
-        $cdata{homeDirectory} ||= $self->{defattr}{'user.homebase'} ?
-            $self->{defattr}{'user.homebase'} . "/$id" : '';
-        $cdata{uidNumber} ||= $self->find_next_numeric_id('user', 'uidNumber',
-            $self->{defattr}{'user.min_uid'}, $self->{defattr}{'user.max_uid'});
-        my $mailid = $cdata{givenName} && $cdata{sn}
-            ? sprintf('%s.%s',
-                to_ascii(lc($cdata{givenName})),
-                to_ascii(lc($cdata{sn})),)
-            : undef;
-        $mailid =~ s/\s*//g if($mailid);
-
-        if ($mailid &&
-            $self->is_supported_object('aliases') &&
-            ! $self->get_object('aliases', $mailid)) {
-            if (my $attr = $self->attribute($otype, 'mail')) {
-                if ((!$attr->ro) && $self->{defattr}{'user.maildomain'}) {
-                    $cdata{mail} ||= sprintf('%s@%s',
-                    $mailid,
-                    $self->{defattr}{'user.maildomain'});
-                }
-            }
-            if (my $attr = $self->attribute($otype, 'aliases')) {
-                $cdata{aliases} ||= $mailid unless ($attr->ro);
-            }
-            if (my $attr = $self->attribute($otype, 'revaliases')) {
-                $cdata{revaliases} ||= $mailid unless ($attr->ro);
-            }
-        }
-    } elsif (lc($otype) eq 'group') {
-        $cdata{gidNumber} ||= $self->find_next_numeric_id('group', 'gidNumber',
-            $self->{defattr}{'group.min_gid'}, $self->{defattr}{'group.max_gid'});
-    }
+    {
+        my %default = $self->compute_default($otype, $id, %cdata);
+        foreach my $k (keys %default) {
+            $cdata{$k} = $default{$k};
+        }
+    }
+
     my %data;
     foreach my $cfield (keys %cdata) {
@@ -381,5 +416,4 @@
     $self->create_object($otype, $id, %data);
 }
-
 
 sub _allowed_values {
Index: /trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/OCHelper/User.pm
===================================================================
--- /trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/OCHelper/User.pm	(revision 1075)
+++ /trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/OCHelper/User.pm	(revision 1076)
@@ -59,19 +59,18 @@
         push(@{$info->{ask}}, 'uidNumber');
         push(@{$info->{ask}}, 'gidNumber');
-        my $mailid = $info->{contents}{givenName} && $info->{contents}{sn}
-            ? sprintf('%s.%s',
-                to_ascii(lc($info->{contents}{givenName})),
-                to_ascii(lc($info->{contents}{sn})),)
-            : undef;
-        $mailid =~ s/ /-/g if ($mailid); # replace space by '-' in mail
-        push(@{$info->{ask}}, 'mail');
-        $info->{contents}{mail} = $mailid && $self->base->{defattr}{'user.maildomain'}
-            ? sprintf('%s@%s', $mailid,
-                $self->base->{defattr}{'user.maildomain'})
-            : undef;
+
+       my %default = $self->base->compute_default(
+            'user', $login || '',
+            %{ $info->{contents} || {} }
+        );
+
+        if ($default{mail}) {
+            push(@{$info->{ask}}, 'mail');
+            $info->{contents}{mail} = $default{mail};
+        }
         if (my $attr = $self->base->attribute('user', 'aliases')) {
             if (!$attr->ro) {
                 push(@{$info->{ask}}, 'aliases');
-                $info->{contents}{aliases} = $mailid
+                $info->{contents}{aliases} = $default{aliases};
             }
         }
@@ -79,5 +78,5 @@
             if (!$attr->ro) {
                 push(@{$info->{ask}}, 'revaliases');
-                $info->{contents}{revaliases} = $mailid
+                $info->{contents}{revaliases} = $default{revaliases};
             }
         }
