[system] / trunk / webwork2 / lib / WeBWorK / ContentGenerator / Options.pm Repository:
ViewVC logotype

Annotation of /trunk/webwork2/lib/WeBWorK/ContentGenerator/Options.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1045 - (view) (download) (as text)

1 : sh002i 644 ################################################################################
2 :     # WeBWorK mod_perl (c) 2000-2002 WeBWorK Project
3 :     # $Id$
4 :     ################################################################################
5 :    
6 :     package WeBWorK::ContentGenerator::Options;
7 : sh002i 818 use base qw(WeBWorK::ContentGenerator);
8 : sh002i 644
9 :     =head1 NAME
10 :    
11 :     WeBWorK::ContentGenerator::Options - Change user options.
12 :    
13 :     =cut
14 :    
15 :     use strict;
16 :     use warnings;
17 :     use CGI qw();
18 :    
19 :     sub initialize {
20 :     my $self = shift;
21 :     my $r = $self->{r};
22 : sh002i 809 my $ce = $self->{ce};
23 : sh002i 818 my $db = $self->{db};
24 : sh002i 644
25 : sh002i 818 $self->{effectiveUser} = $db->getUser($r->param('effectiveUser'));
26 : sh002i 644 }
27 :    
28 :     sub path {
29 :     my ($self, $args) = @_;
30 :    
31 : sh002i 809 my $ce = $self->{ce};
32 : sh002i 644 my $root = $ce->{webworkURLs}->{root};
33 :     my $courseName = $ce->{courseName};
34 :     return $self->pathMacro($args,
35 :     "Home" => "$root",
36 :     $courseName => "$root/$courseName",
37 :     "User Options" => "",
38 :     );
39 :     }
40 :    
41 :     sub title {
42 :     my $self = shift;
43 :    
44 : malsyned 720 return "User Options for " . $self->{effectiveUser}->first_name
45 :     . " " . $self->{effectiveUser}->last_name;
46 : sh002i 644 }
47 :    
48 :     sub body {
49 :     my $self = shift;
50 : sh002i 645 my $r = $self->{r};
51 : sh002i 818 my $db = $self->{db};
52 : malsyned 720 my $effectiveUser = $self->{effectiveUser};
53 : sh002i 644
54 : sh002i 645 my $changeOptions = $r->param("changeOptions");
55 :     my $newP = $r->param("newPassword");
56 :     my $confirmP = $r->param("confirmPassword");
57 :     my $newA = $r->param("newAddress");
58 :    
59 :     print CGI::start_form(-method=>"POST", -action=>$r->uri);
60 :     print $self->hidden_authen_fields;
61 :     print CGI::h2("Change Password");
62 :     if ($changeOptions) {
63 :     if ($newP or $confirmP) {
64 :     if ($newP eq $confirmP) {
65 :     # possibly do some format checking?
66 : sh002i 919 eval { $self->{authdb}->setPassword($effectiveUser->user_id, $newP) };
67 : sh002i 645 if ($@) {
68 :     print CGI::p("Couldn't change your
69 :     password: $@");
70 :     } else {
71 :     print CGI::p("Your password has been
72 :     changed.");
73 :     }
74 :     } else {
75 :     print CGI::p("The passwords you entered in the
76 :     New Password and Confirm Password fields don't
77 :     match. Please retype your new password and try
78 :     again.");
79 :     }
80 :     }
81 :     }
82 :     print CGI::table(
83 :     CGI::Tr(
84 :     CGI::td("New Password"),
85 :     CGI::td(CGI::password_field("newPassword")),
86 :     ),
87 :     CGI::Tr(
88 :     CGI::td("Confirm Password"),
89 :     CGI::td(CGI::password_field("confirmPassword")),
90 :     ),
91 :     );
92 :     print CGI::h2("Change Email Address");
93 :     if ($changeOptions) {
94 : malsyned 1045 if ($newA) {
95 :     # possibly do some format checking?
96 :     my $oldA = $effectiveUser->email_address;
97 :     $effectiveUser->email_address($newA);
98 :     eval { $db->putUser($effectiveUser) };
99 :     if ($@) {
100 :     $effectiveUser->email_address($oldA);
101 :     print CGI::p("Couldn't change your
102 :     email address: $@");
103 : sh002i 645 } else {
104 : malsyned 1045 print CGI::p("Your email address has
105 :     been changed.");
106 :     $newA = "";
107 : sh002i 645 }
108 :     }
109 :     }
110 :     print CGI::table(
111 :     CGI::Tr(
112 :     CGI::td("Current Address"),
113 : malsyned 720 CGI::td($effectiveUser->email_address),
114 : sh002i 645 ),
115 :     CGI::Tr(
116 :     CGI::td("New Address"),
117 :     CGI::td(CGI::textfield("newAddress", $newA)),
118 :     ),
119 :     );
120 :     print CGI::br();
121 :     print CGI::submit("changeOptions", "Change User Options");
122 :     print CGI::end_form();
123 :    
124 : sh002i 644 return "";
125 :     }
126 :    
127 :     1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9