merge NG auth, RT#21563
[freeside.git] / httemplate / edit / process / access_user.html
1 %  if ( $cgi->param('_password') ne $cgi->param('_password2') ) {
2 %    $cgi->param('error', "The passwords do not match");
3 %    print $cgi->redirect(popurl(2) . "access_user.html?" . $cgi->query_string);
4 %  } else {
5 <%   include( 'elements/process.html',
6                  'table'          => 'access_user',
7                  'viewall_dir'    => 'browse',
8                  'copy_on_empty'  => [ '_password', '_password_encoding' ],
9                  'clear_on_error' => [ '_password', '_password2' ],
10                  'process_m2m'    => { 'link_table'   => 'access_usergroup',
11                                        'target_table' => 'access_group',
12                                      },
13                  'precheck_callback'        => \&precheck_callback,
14                  'post_new_object_callback' => \&post_new_object_callback,
15              )
16 %>
17 %   }
18 <%init>
19
20 die "access denied"
21   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
22
23 if ( FS::Conf->new->exists('disable_acl_changes') ) {
24   errorpage('ACL changes disabled in public demo.');
25   die "shouldn't be reached";
26 }
27
28 sub precheck_callback {
29   my $cgi = shift;
30
31   my $o = FS::access_user->new({username => $cgi->param('username')});
32   if( $o->is_system_user and !$cgi->param('usernum') ) {
33     $cgi->param('username','');
34     return "username '".$o->username."' reserved for system account."
35   }
36
37   return '';
38 }
39
40 sub post_new_object_callback {
41   my( $cgi, $access_user ) = @_;
42
43   if ( length($cgi->param('_password')) ) {
44     my $password = scalar($cgi->param('_password'));
45     $access_user->change_password_fields($password);
46   }
47
48 }
49
50 </%init>