Optimize "Customer has a referring customer" condition, RT#74452
[freeside.git] / httemplate / pref / pref-process.html
1 % if ( $error ) {
2 %   $cgi->param('error', $error);
3     <% $cgi->redirect(popurl(1). "pref.html?". $cgi->query_string ) %>
4 % } else {
5     <% $cgi->redirect( -uri    => popurl(1). "pref.html",
6                    -cookie => CGI::Cookie->new(
7                      -name    => 'freeside_status',
8                      -value   => mt('Preferences updated'),
9                      -expires => '+5m',
10                    ),
11        )
12     %>
13 % }
14 <%init>
15
16 my $access_user = $FS::CurrentUser::CurrentUser;
17
18 if ( FS::Conf->new->exists('disable_acl_changes') ) {
19   errorpage("Preference changes disabled in public demo");
20   die "shouldn't be reached";
21 }
22
23 my $error = '';
24
25 if ( FS::Auth->auth_class->can('change_password')
26        && grep { $cgi->param($_) !~ /^\s*$/ }
27             qw(_password new_password new_password2)
28    ) {
29
30   my $oldpass = $cgi->param('_password');
31   my $newpass = $cgi->param('new_password');
32
33   if ( $newpass ne $cgi->param('new_password2') ) {
34     $error = mt("New passwords don't match");
35
36   } elsif ( ! length($newpass) ) {
37     $error = mt('No new password entered');
38
39   } elsif ( ! FS::Auth->authenticate( $access_user, $oldpass ) ) {
40     $error = mt('Current password incorrect; password not changed');
41
42   } else {
43
44     $error = $access_user->is_password_allowed($newpass)
45           || $access_user->change_password($newpass);
46
47   }
48
49 }
50
51 #well, if you got your password change wrong, you don't get anything else
52 #changed right now.  but it should be sticky on the form
53 unless ( $error ) { # if ($access_user) {
54
55   my %param = $access_user->options;
56
57   #XXX autogen
58   my @paramlist = qw( locale menu_position default_customer_view 
59                       history_order
60                       spreadsheet_format mobile_menu
61                       disable_html_editor disable_enter_submit_onetimecharge
62                       enable_mask_clipboard_hack dashboard_customers
63                       customer_view_emails
64                       printtofit
65                       email_address
66                       snom-ip snom-username snom-password
67                       vonage-fromnumber vonage-username vonage-password
68                       cust_pkg-display_times
69                       show_pkgnum show_confitem_counts export_getsettings
70                       show_db_profile save_db_profile save_tmp_typesetting
71                       height width availHeight availWidth colorDepth
72                     );
73
74   foreach (@paramlist) {
75     scalar($cgi->param($_)) =~ /^[,.\-\@\w]*$/ && next;
76     $error ||= mt("Illegal value for parameter")." $_";
77     last;
78   }
79
80   foreach (@paramlist) {
81     $param{$_} = scalar($cgi->param($_));
82   }
83
84   $error ||= $access_user->replace( \%param );
85
86 }
87
88 if ( !$error and ($FS::TicketSystem::system || '') eq 'RT_Internal' ) {
89   # sync RT user locale on every update
90   my $locale = $access_user->option('locale');
91   FS::TicketSystem->init;
92   my $UserObj = FS::TicketSystem->session('')->{'CurrentUser'}->UserObj;
93   # Bypass RT ModifySelf ACL
94   $UserObj->CurrentUser( $RT::SystemUser );
95   if ( $UserObj->Lang ne $locale ) {
96     my ($val, $msg) = $UserObj->SetLang($locale);
97     $error = $msg if !$val;
98   }
99 }
100 </%init>