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