diff --git a/core/user.class.php b/core/user.class.php index bb0874be..86e7bf93 100644 --- a/core/user.class.php +++ b/core/user.class.php @@ -118,5 +118,11 @@ class User { $database->Execute("UPDATE users SET pass=? WHERE id=?", array($hash, $this->id)); log_info("core-user", "Set password for {$this->name}"); } + + public function set_email($address) { + global $database; + $database->Execute("UPDATE users SET email=? WHERE id=?", array($address, $this->id)); + log_info("core-user", "Set email for {$this->name}"); + } } ?> diff --git a/ext/user/main.php b/ext/user/main.php index 15136f62..61bac92e 100644 --- a/ext/user/main.php +++ b/ext/user/main.php @@ -72,6 +72,9 @@ class UserPage extends SimpleExtension { else if($event->get_arg(0) == "change_pass") { $this->change_password_wrapper($page); } + else if($event->get_arg(0) == "change_email") { + $this->change_email_wrapper($page); + } else if($event->get_arg(0) == "recover") { $user = User::by_name($_POST['username']); if(is_null($user)) { @@ -262,15 +265,10 @@ class UserPage extends SimpleExtension { global $config; global $database; - $page->set_title("Error"); - $page->set_heading("Error"); - $page->add_block(new NavBlock()); if($user->is_anonymous()) { - $page->add_block(new Block("Error", "You aren't logged in")); + $this->theme->display_error($page, "Error", "You aren't logged in"); } - else if(isset($_POST['id']) && isset($_POST['name']) && - isset($_POST['pass1']) && isset($_POST['pass2'])) { - $name = $_POST['name']; + else if(isset($_POST['id']) && isset($_POST['pass1']) && isset($_POST['pass2'])) { $id = $_POST['id']; $pass1 = $_POST['pass1']; $pass2 = $_POST['pass2']; @@ -278,15 +276,13 @@ class UserPage extends SimpleExtension { $duser = User::by_id($id); if((!$user->is_admin()) && ($duser->name != $user->name)) { - $page->add_block(new Block("Error", - "You need to be an admin to change other people's passwords")); + $this->theme->display_error($page, "Error", + "You need to be an admin to change other people's passwords"); } else if($pass1 != $pass2) { - $page->add_block(new Block("Error", "Passwords don't match")); + $this->theme->display_error($page, "Error", "Passwords don't match"); } else { - global $config; - // FIXME: send_event() $duser->set_password($pass1); @@ -297,7 +293,40 @@ class UserPage extends SimpleExtension { } else { $page->set_mode("redirect"); - $page->set_redirect(make_link("user/{$user->name}")); + $page->set_redirect(make_link("user/{$duser->name}")); + } + } + } + } + + private function change_email_wrapper($page) { + global $user; + global $config; + global $database; + + if($user->is_anonymous()) { + $this->theme->display_error($page, "Error", "You aren't logged in"); + } + else if(isset($_POST['id']) && isset($_POST['address'])) { + $id = $_POST['id']; + $address = $_POST['address']; + + $duser = User::by_id($id); + + if((!$user->is_admin()) && ($duser->name != $user->name)) { + $this->theme->display_error($page, "Error", + "You need to be an admin to change other people's addressess"); + } + else { + $duser->set_email($address); + + if($id == $user->id) { + $page->set_mode("redirect"); + $page->set_redirect(make_link("user")); + } + else { + $page->set_mode("redirect"); + $page->set_redirect(make_link("user/{$duser->name}")); } } } diff --git a/ext/user/theme.php b/ext/user/theme.php index b6a7561a..70a07cfd 100644 --- a/ext/user/theme.php +++ b/ext/user/theme.php @@ -135,9 +135,6 @@ class UserPageTheme extends Themelet { if($user->id == $duser->id || $user->is_admin()) { $page->add_block(new Block("Options", $this->build_options($duser), "main", 20)); } - if($user->is_admin()) { - $page->add_block(new Block("More Options", $this->build_more_options($duser))); - } } } @@ -170,13 +167,12 @@ class UserPageTheme extends Themelet { } protected function build_options(User $duser) { - global $database; - global $config; + global $config, $database, $user; $html = ""; + $html .= "
+ + "; - return $html; - } - protected function build_more_options(User $duser) { - global $database; - global $config; - - $i_user_id = int_escape($duser->id); - $h_is_admin = $duser->is_admin() ? " checked" : ""; - - $html = " - + if($user->is_admin()) { + $i_user_id = int_escape($duser->id); + $h_is_admin = $duser->is_admin() ? " checked" : ""; + $html .= " + "; + } return $html; } // }}}