1 | package LATMOS::Accounts::Bases::OCHelper::User; |
---|
2 | |
---|
3 | # $Id: User.pm 2932 2010-08-10 17:19:21Z nanardon $ |
---|
4 | |
---|
5 | use strict; |
---|
6 | use warnings; |
---|
7 | use base qw(LATMOS::Accounts::Bases::OCHelper); |
---|
8 | use LATMOS::Accounts::Utils; |
---|
9 | use LATMOS::Accounts::I18N; |
---|
10 | |
---|
11 | =head1 NAME |
---|
12 | |
---|
13 | LATMOS::Accounts::Bases::OCHelper::User - |
---|
14 | Helper to create user in L<LATMOS::Accounts> system |
---|
15 | |
---|
16 | =cut |
---|
17 | |
---|
18 | sub _step { |
---|
19 | my ($self, $info) = @_; |
---|
20 | if ($info->{step} <= 0) { |
---|
21 | $info->{name}{ask} = 1; |
---|
22 | push(@{$info->{ask}}, qw(givenName sn)); |
---|
23 | $info->{step} = 1; |
---|
24 | if (!($info->{name}{content} || |
---|
25 | ($info->{contents}{sn}) && $info->{contents}{givenName})) { |
---|
26 | return 'NEEDINFO'; |
---|
27 | } |
---|
28 | } |
---|
29 | if ($info->{step} == 1) { |
---|
30 | $info->{step} = 2; |
---|
31 | my $login = $info->{name}{content}; |
---|
32 | if (!$login) { |
---|
33 | $info->{name}{ask} = 1; |
---|
34 | # Try to find a login: |
---|
35 | |
---|
36 | if ($info->{contents}{sn}) { |
---|
37 | |
---|
38 | # On regarde si on objet de même nom existe: |
---|
39 | if ($info->{contents}{givenName}) { |
---|
40 | if (my @objs = $self->base->search_objects( |
---|
41 | 'user', |
---|
42 | 'givenName~' . $info->{contents}{givenName}, |
---|
43 | 'sn~' . $info->{contents}{sn}, |
---|
44 | 'oalias=NULL' ) ) { |
---|
45 | $info->{duplicates} = \@objs; |
---|
46 | } |
---|
47 | } |
---|
48 | my $login = buildLogin( |
---|
49 | sub { |
---|
50 | !$self->base->get_object('user', $_[0]); |
---|
51 | }, |
---|
52 | $info->{contents}{sn}, |
---|
53 | $info->{contents}{givenName}, |
---|
54 | ); |
---|
55 | if ($login) { |
---|
56 | $info->{name}{content} = $login; |
---|
57 | } |
---|
58 | } |
---|
59 | } else { |
---|
60 | $self->base->get_object('user', $login) and do { |
---|
61 | $info->{name}{ask} = 1; |
---|
62 | } |
---|
63 | } |
---|
64 | push(@{$info->{ask}}, 'uidNumber'); |
---|
65 | push(@{$info->{ask}}, 'gidNumber'); |
---|
66 | |
---|
67 | my %default = $self->base->compute_default( |
---|
68 | 'user', $login || '', |
---|
69 | %{ $info->{contents} || {} } |
---|
70 | ); |
---|
71 | |
---|
72 | if ($default{mail}) { |
---|
73 | push(@{$info->{ask}}, 'mail'); |
---|
74 | $info->{contents}{mail} ||= $default{mail}; |
---|
75 | } |
---|
76 | if (my $attr = $self->base->attribute('user', 'aliases')) { |
---|
77 | if (!$attr->ro) { |
---|
78 | push(@{$info->{ask}}, 'aliases'); |
---|
79 | $info->{contents}{aliases} ||= $default{aliases}; |
---|
80 | } |
---|
81 | } |
---|
82 | if (my $attr = $self->base->attribute('user', 'revaliases')) { |
---|
83 | if (!$attr->ro) { |
---|
84 | push(@{$info->{ask}}, 'revaliases'); |
---|
85 | $info->{contents}{revaliases} ||= $default{revaliases}; |
---|
86 | } |
---|
87 | } |
---|
88 | return 'NEEDINFO'; |
---|
89 | |
---|
90 | |
---|
91 | } elsif ($info->{step} == 2) { |
---|
92 | if ($self->base->create_c_object($self->otype, |
---|
93 | $info->{name}{content}, |
---|
94 | %{$info->{contents} || {}}, |
---|
95 | )) { |
---|
96 | return 'CREATED'; |
---|
97 | } else { |
---|
98 | return 'ERROR'; |
---|
99 | } |
---|
100 | } else { |
---|
101 | return undef; |
---|
102 | } |
---|
103 | } |
---|
104 | |
---|
105 | 1; |
---|
106 | |
---|
107 | __END__ |
---|
108 | |
---|
109 | =head1 SEE ALSO |
---|
110 | |
---|
111 | L<LATMOS::Accounts::Bases::OCHelper> |
---|
112 | |
---|
113 | =head1 AUTHOR |
---|
114 | |
---|
115 | Thauvin Olivier, E<lt>olivier.thauvin@latmos.ipsl.frE<gt> |
---|
116 | |
---|
117 | =head1 COPYRIGHT AND LICENSE |
---|
118 | |
---|
119 | Copyright (C) 2012 by Thauvin Olivier |
---|
120 | |
---|
121 | This library is free software; you can redistribute it and/or modify |
---|
122 | it under the same terms as Perl itself, either Perl version 5.10.0 or, |
---|
123 | at your option, any later version of Perl 5 you may have available. |
---|
124 | |
---|
125 | =cut |
---|