settable email field

This commit is contained in:
Shish 2009-08-11 17:07:03 +01:00
parent 2e8eff8f38
commit 76a9090ded
3 changed files with 69 additions and 34 deletions

@ -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}");
}
}
?>

@ -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}"));
}
}
}

@ -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 .= "
<form action='".make_link("user_admin/change_pass")."' method='POST'>
<input type='hidden' name='name' value='{$duser->name}'>
<input type='hidden' name='id' value='{$duser->id}'>
<table style='width: 300px;'>
<tr><th colspan='2'>Change Password</th></tr>
@ -185,24 +181,28 @@ class UserPageTheme extends Themelet {
<tr><td colspan='2'><input type='Submit' value='Change Password'></td></tr>
</table>
</form>
<p><form action='".make_link("user_admin/change_email")."' method='POST'>
<input type='hidden' name='id' value='{$duser->id}'>
<table style='width: 300px;'>
<tr><th colspan='2'>Change Email</th></tr>
<tr><td>Address</td><td><input type='text' name='address' value='".html_escape($duser->email)."'></td></tr>
<tr><td colspan='2'><input type='Submit' value='Set'></td></tr>
</table>
</form>
";
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 = "
<form action='".make_link("user_admin/set_more")."' method='POST'>
<input type='hidden' name='id' value='$i_user_id'>
Admin: <input name='admin' type='checkbox'$h_is_admin>
<p><input type='submit' value='Set'>
</form>
if($user->is_admin()) {
$i_user_id = int_escape($duser->id);
$h_is_admin = $duser->is_admin() ? " checked" : "";
$html .= "
<p><form action='".make_link("user_admin/set_more")."' method='POST'>
<input type='hidden' name='id' value='$i_user_id'>
Admin: <input name='admin' type='checkbox'$h_is_admin>
<input type='submit' value='Set'>
</form>
";
}
return $html;
}
// }}}