| … | |
… | |
| 24 | my $r = $self->{r}; |
24 | my $r = $self->{r}; |
| 25 | my $ce = $self->{courseEnvironment}; |
25 | my $ce = $self->{courseEnvironment}; |
| 26 | |
26 | |
| 27 | $self->{cldb} = WeBWorK::DB::Classlist->new($ce); |
27 | $self->{cldb} = WeBWorK::DB::Classlist->new($ce); |
| 28 | $self->{authdb} = WeBWorK::DB::Auth->new($ce); |
28 | $self->{authdb} = WeBWorK::DB::Auth->new($ce); |
| 29 | $self->{user} = $self->{cldb}->getUser($r->param('user')); |
29 | $self->{effectiveUser} = $self->{cldb}->getUser($r->param('effectiveUser')); |
| 30 | } |
30 | } |
| 31 | |
31 | |
| 32 | sub path { |
32 | sub path { |
| 33 | my ($self, $args) = @_; |
33 | my ($self, $args) = @_; |
| 34 | |
34 | |
| … | |
… | |
| 43 | } |
43 | } |
| 44 | |
44 | |
| 45 | sub title { |
45 | sub title { |
| 46 | my $self = shift; |
46 | my $self = shift; |
| 47 | |
47 | |
| 48 | return "User Options for " . $self->{user}->first_name |
48 | return "User Options for " . $self->{effectiveUser}->first_name |
| 49 | . " " . $self->{user}->last_name; |
49 | . " " . $self->{effectiveUser}->last_name; |
| 50 | } |
50 | } |
| 51 | |
51 | |
| 52 | sub body { |
52 | sub body { |
| 53 | my $self = shift; |
53 | my $self = shift; |
| 54 | my $r = $self->{r}; |
54 | my $r = $self->{r}; |
| 55 | my $user = $self->{user}; |
55 | my $effectiveUser = $self->{effectiveUser}; |
| 56 | |
56 | |
| 57 | my $changeOptions = $r->param("changeOptions"); |
57 | my $changeOptions = $r->param("changeOptions"); |
| 58 | my $newP = $r->param("newPassword"); |
58 | my $newP = $r->param("newPassword"); |
| 59 | my $confirmP = $r->param("confirmPassword"); |
59 | my $confirmP = $r->param("confirmPassword"); |
| 60 | my $newA = $r->param("newAddress"); |
60 | my $newA = $r->param("newAddress"); |
| … | |
… | |
| 65 | print CGI::h2("Change Password"); |
65 | print CGI::h2("Change Password"); |
| 66 | if ($changeOptions) { |
66 | if ($changeOptions) { |
| 67 | if ($newP or $confirmP) { |
67 | if ($newP or $confirmP) { |
| 68 | if ($newP eq $confirmP) { |
68 | if ($newP eq $confirmP) { |
| 69 | # possibly do some format checking? |
69 | # possibly do some format checking? |
| 70 | eval { $self->{authdb}->setPassword($user->id, $newP) }; |
70 | eval { $self->{authdb}->setPassword($effectiveUser->id, $newP) }; |
| 71 | if ($@) { |
71 | if ($@) { |
| 72 | print CGI::p("Couldn't change your |
72 | print CGI::p("Couldn't change your |
| 73 | password: $@"); |
73 | password: $@"); |
| 74 | } else { |
74 | } else { |
| 75 | print CGI::p("Your password has been |
75 | print CGI::p("Your password has been |
| … | |
… | |
| 96 | print CGI::h2("Change Email Address"); |
96 | print CGI::h2("Change Email Address"); |
| 97 | if ($changeOptions) { |
97 | if ($changeOptions) { |
| 98 | if ($newA or $confirmA) { |
98 | if ($newA or $confirmA) { |
| 99 | if ($newA eq $confirmA) { |
99 | if ($newA eq $confirmA) { |
| 100 | # possibly do some format checking? |
100 | # possibly do some format checking? |
| 101 | my $oldA = $user->email_address; |
101 | my $oldA = $effectiveUser->email_address; |
| 102 | $user->email_address($newA); |
102 | $effectiveUser->email_address($newA); |
| 103 | eval { $self->{cldb}->setUser($user) }; |
103 | eval { $self->{cldb}->setUser($effectiveUser) }; |
| 104 | if ($@) { |
104 | if ($@) { |
| 105 | $user->email_address($oldA); |
105 | $effectiveUser->email_address($oldA); |
| 106 | print CGI::p("Couldn't change your |
106 | print CGI::p("Couldn't change your |
| 107 | email address: $@"); |
107 | email address: $@"); |
| 108 | } else { |
108 | } else { |
| 109 | print CGI::p("Your email address has |
109 | print CGI::p("Your email address has |
| 110 | been changed."); |
110 | been changed."); |
| … | |
… | |
| 119 | } |
119 | } |
| 120 | } |
120 | } |
| 121 | print CGI::table( |
121 | print CGI::table( |
| 122 | CGI::Tr( |
122 | CGI::Tr( |
| 123 | CGI::td("Current Address"), |
123 | CGI::td("Current Address"), |
| 124 | CGI::td($user->email_address), |
124 | CGI::td($effectiveUser->email_address), |
| 125 | ), |
125 | ), |
| 126 | CGI::Tr( |
126 | CGI::Tr( |
| 127 | CGI::td("New Address"), |
127 | CGI::td("New Address"), |
| 128 | CGI::td(CGI::textfield("newAddress", $newA)), |
128 | CGI::td(CGI::textfield("newAddress", $newA)), |
| 129 | ), |
129 | ), |