summaryrefslogtreecommitdiff
path: root/httemplate/edit/process/access_user.html
blob: 8e264c1a9ca289d877a5b215f15cf152b9a03362 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
%  if ( $cgi->param('_password') ne $cgi->param('_password2') ) {
%    $cgi->param('error', "The passwords do not match");
%    print $cgi->redirect(popurl(2) . "access_user.html?" . $cgi->query_string);
%  } else {
<%   include( 'elements/process.html',
                 'table'          => 'access_user',
                 'viewall_dir'    => 'browse',
                 'copy_on_empty'  => [ '_password', '_password_encoding', 'totp_secret32' ],
                 'clear_on_error' => [ '_password', '_password2' ],
                 'process_m2m'    => { 'link_table'   => 'access_usergroup',
                                       'target_table' => 'access_group',
                                     },
                 'precheck_callback'        => \&precheck_callback,
                 'post_new_object_callback' => \&post_new_object_callback,
                 'noerror_callback'         => \&noerror_callback,
             )
%>
%   }
<%init>

die "access denied"
  unless $FS::CurrentUser::CurrentUser->access_right('Configuration');

if ( FS::Conf->new->exists('disable_acl_changes') ) {
  errorpage('ACL changes disabled in public demo.');
  die "shouldn't be reached";
}

sub precheck_callback {
  my $cgi = shift;

  my $o = FS::access_user->new({username => scalar($cgi->param('username'))});
  if( $o->is_system_user and !$cgi->param('usernum') ) {
    $cgi->param('username','');
    return "username '".$o->username."' reserved for system account."
  }

  return '';
}

sub post_new_object_callback {
  my( $cgi, $access_user ) = @_;

  return '' unless length($cgi->param('_password'));

  my $password = scalar($cgi->param('_password'));
  my $error = $access_user->is_password_allowed($password);
  return $error if $error;

  $access_user->change_password_fields($password);
  '';
}

sub noerror_callback {
  my( $cgi, $access_user ) = @_;

  #handle installer checkbox
  my @sched_item = $access_user->sched_item;
  my $sched_item = $sched_item[0];
  if ( $cgi->param('sched_item_enabled') ) {

    if ( ! $sched_item ) {
      my $sched_item = new FS::sched_item {
        'usernum' => $access_user->usernum,
      };
      my $error = $sched_item->insert;
      die $error if $error; #wtf?  shouldn't happen
    } elsif ( $sched_item->disabled ) {
      $sched_item->disabled('');
      my $error = $sched_item->replace;
      die $error if $error; #wtf?  shouldn't happen
    }

  } elsif ( ! $cgi->param('sched_item_enabled')
              && $sched_item
              && ! $sched_item->disabled
          )
  {
    $sched_item->disabled('Y');
    my $error = $sched_item->replace;
    die $error if $error; #wtf?  shouldn't happen
  }

}

</%init>