settable email field
This commit is contained in:
		
							parent
							
								
									ea03506471
								
							
						
					
					
						commit
						b13ccccd69
					
				@ -118,5 +118,11 @@ class User {
 | 
				
			|||||||
		$database->Execute("UPDATE users SET pass=? WHERE id=?", array($hash, $this->id));
 | 
							$database->Execute("UPDATE users SET pass=? WHERE id=?", array($hash, $this->id));
 | 
				
			||||||
		log_info("core-user", "Set password for {$this->name}");
 | 
							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,18 @@ class UserPage extends SimpleExtension {
 | 
				
			|||||||
			else if($event->get_arg(0) == "change_pass") {
 | 
								else if($event->get_arg(0) == "change_pass") {
 | 
				
			||||||
				$this->change_password_wrapper($page);
 | 
									$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)) {
 | 
				
			||||||
 | 
										$this->theme->display_error($page, "Error", "There's no user with that name");
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									if(is_null($user->email)) {
 | 
				
			||||||
 | 
										//
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
			else if($event->get_arg(0) == "create") {
 | 
								else if($event->get_arg(0) == "create") {
 | 
				
			||||||
				if(!$config->get_bool("login_signup_enabled")) {
 | 
									if(!$config->get_bool("login_signup_enabled")) {
 | 
				
			||||||
					$this->theme->display_signups_disabled($page);
 | 
										$this->theme->display_signups_disabled($page);
 | 
				
			||||||
@ -253,15 +265,10 @@ class UserPage extends SimpleExtension {
 | 
				
			|||||||
		global $config;
 | 
							global $config;
 | 
				
			||||||
		global $database;
 | 
							global $database;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$page->set_title("Error");
 | 
					 | 
				
			||||||
		$page->set_heading("Error");
 | 
					 | 
				
			||||||
		$page->add_block(new NavBlock());
 | 
					 | 
				
			||||||
		if($user->is_anonymous()) {
 | 
							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']) &&
 | 
							else if(isset($_POST['id']) && isset($_POST['pass1']) && isset($_POST['pass2'])) {
 | 
				
			||||||
				isset($_POST['pass1']) && isset($_POST['pass2'])) {
 | 
					 | 
				
			||||||
			$name = $_POST['name'];
 | 
					 | 
				
			||||||
			$id = $_POST['id'];
 | 
								$id = $_POST['id'];
 | 
				
			||||||
			$pass1 = $_POST['pass1'];
 | 
								$pass1 = $_POST['pass1'];
 | 
				
			||||||
			$pass2 = $_POST['pass2'];
 | 
								$pass2 = $_POST['pass2'];
 | 
				
			||||||
@ -269,15 +276,13 @@ class UserPage extends SimpleExtension {
 | 
				
			|||||||
			$duser = User::by_id($id);
 | 
								$duser = User::by_id($id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if((!$user->is_admin()) && ($duser->name != $user->name)) {
 | 
								if((!$user->is_admin()) && ($duser->name != $user->name)) {
 | 
				
			||||||
				$page->add_block(new Block("Error",
 | 
									$this->theme->display_error($page, "Error",
 | 
				
			||||||
						"You need to be an admin to change other people's passwords"));
 | 
											"You need to be an admin to change other people's passwords");
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			else if($pass1 != $pass2) {
 | 
								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 {
 | 
								else {
 | 
				
			||||||
				global $config;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				// FIXME: send_event()
 | 
									// FIXME: send_event()
 | 
				
			||||||
				$duser->set_password($pass1);
 | 
									$duser->set_password($pass1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -288,7 +293,40 @@ class UserPage extends SimpleExtension {
 | 
				
			|||||||
				}
 | 
									}
 | 
				
			||||||
				else {
 | 
									else {
 | 
				
			||||||
					$page->set_mode("redirect");
 | 
										$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()) {
 | 
								if($user->id == $duser->id || $user->is_admin()) {
 | 
				
			||||||
				$page->add_block(new Block("Options", $this->build_options($duser), "main", 20));
 | 
									$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) {
 | 
						protected function build_options(User $duser) {
 | 
				
			||||||
		global $database;
 | 
							global $config, $database, $user;
 | 
				
			||||||
		global $config;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$html = "";
 | 
							$html = "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$html .= "
 | 
							$html .= "
 | 
				
			||||||
		<form action='".make_link("user_admin/change_pass")."' method='POST'>
 | 
							<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}'>
 | 
								<input type='hidden' name='id' value='{$duser->id}'>
 | 
				
			||||||
			<table style='width: 300px;'>
 | 
								<table style='width: 300px;'>
 | 
				
			||||||
				<tr><th colspan='2'>Change Password</th></tr>
 | 
									<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>
 | 
									<tr><td colspan='2'><input type='Submit' value='Change Password'></td></tr>
 | 
				
			||||||
			</table>
 | 
								</table>
 | 
				
			||||||
		</form>
 | 
							</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) {
 | 
							if($user->is_admin()) {
 | 
				
			||||||
		global $database;
 | 
								$i_user_id = int_escape($duser->id);
 | 
				
			||||||
		global $config;
 | 
								$h_is_admin = $duser->is_admin() ? " checked" : "";
 | 
				
			||||||
 | 
								$html .= "
 | 
				
			||||||
		$i_user_id = int_escape($duser->id);
 | 
									<p><form action='".make_link("user_admin/set_more")."' method='POST'>
 | 
				
			||||||
		$h_is_admin = $duser->is_admin() ? " checked" : "";
 | 
									<input type='hidden' name='id' value='$i_user_id'>
 | 
				
			||||||
 | 
									Admin: <input name='admin' type='checkbox'$h_is_admin>
 | 
				
			||||||
		$html = "
 | 
									<input type='submit' value='Set'>
 | 
				
			||||||
			<form action='".make_link("user_admin/set_more")."' method='POST'>
 | 
									</form>
 | 
				
			||||||
			<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>
 | 
					 | 
				
			||||||
			";
 | 
								";
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		return $html;
 | 
							return $html;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
// }}}
 | 
					// }}}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user