Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion User.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function getPassword() {
*/
public function setPassword($password) {
if (empty($password))
throw new Exception("Ein leeres Passwort ist nicht erlaubt.");
throw new Exception("No password supplied.");

$this->_password = crypt($password, base64_encode($password));
}
Expand Down
27 changes: 17 additions & 10 deletions UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@

class UserController {

private $templates = "/templatesEN";

public function index() {
global $userManager, $firewall;

if ($firewall->hasUserAccess())
include_once __DIR__ . "/templates/user/index.phtml";
include_once __DIR__ . $this->templates . "/user/index.phtml";
else {
header("HTTP/1.1 403 Forbidden");
include_once __DIR__ . "/templates/403.phtml";
include_once __DIR__ . $this->templates . "/403.phtml";
}
}

public function editPassword() {
global $userManager, $firewall;
include_once __DIR__."/templates/user/edit.phtml";
include_once __DIR__.$this->templates . "/user/edit.phtml";
}

public function updatePassword() {
Expand All @@ -25,19 +27,24 @@ public function updatePassword() {

$message = '';
$success = false;
try {
$user = $userManager->getCurrentUser();
$user->setPassword($_POST['password']);
$success = $userManager->updateUser($user);
} catch(Exception $e) {
$message = $e->getMessage();

if ($_POST['password'] !== $_POST['pwretype']) {
$message = 'Sorry, passwords do not match.';
} else {
try {
$user = $userManager->getCurrentUser();
$user->setPassword($_POST['password']);
$success = $userManager->updateUser($user);
} catch(Exception $e) {
$message = $e->getMessage();
}
}

header("HTTP/1.1 303 See Other");
header("Location: {$_SERVER["SCRIPT_NAME"]}?action=changePassword&success=".(int)$success."&message=".urlencode($message));
} else {
header("HTTP/1.1 403 Forbidden");
include_once __DIR__ . "/templates/403.phtml";
include_once __DIR__ . $this->templates . "/403.phtml";
}
}
}
4 changes: 2 additions & 2 deletions UserManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function deleteUser(User $user) {
*/
public function addUser(User $user) {
if ($this->userExists($user->getUsername()))
throw new Exception("Der Benutzer existiert bereits.");
throw new Exception("User exists already.");

$this->users[$user->getUsername()] = $user;
$this->changed = true;
Expand All @@ -110,7 +110,7 @@ public function addUser(User $user) {
*/
public function updateUser(User $user) {
if (!$this->userExists($user->getUsername()))
throw new Exception("Der Benutzer existiert nicht.");
throw new Exception("User does not exist.");

$this->users[$user->getUsername()] = $user;
$this->changed = true;
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions templates/user/edit.phtml → templatesDE/user/edit.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@
<form action="<?php echo $_SERVER["SCRIPT_NAME"] ?>?action=updatePassword" method="post">
<fieldset>
<label for="user_password">neues Passwort:</label>
<br>
<input type="password" name="password" id="user_password" />
<br>
<label for="user_password_retype">wiederhole neues Passwort:</label>
<br>
<input type="password" name="pwretype" id="user_password_retype" />
</fieldset>

<input type="submit" value="Absenden" />
Expand Down
File renamed without changes.
36 changes: 36 additions & 0 deletions templatesEN/403.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Administration</title>

<link type="text/css" href="css/screen.css" rel="stylesheet" media="all" />
</head>
<body>
<div class="header">
<ul>
<li><a href="<?php echo $_SERVER["SCRIPT_NAME"] ?>?action=changePassword">Change Password</a></li>
<?php if($firewall->hasUserAccess()) : ?>
<li><a href="<?php echo $_SERVER["SCRIPT_NAME"] ?>?action=listUsers">List Users</a></li>
<?php endif; ?>
</ul>
</div>

<h1>Error 403</h1>

<?php if (isset($_GET['success'])) : ?>
<div class="flash">
<?php if (empty($_GET['message'])) : ?>
<div class="success">Password changed successfully.</div>
<?php else : ?>
<div class="error"><?php echo $_GET['message'] ?></div>
<?php endif; ?>
</div>
<?php endif; ?>

<div id="main_content">
<h2 style="text-align: center; margin-top: 7em;">403</h2>
<h3 style="text-align: center; margin-top: 1em;">Access denied</h3>
</div>
</body>
</html>
47 changes: 47 additions & 0 deletions templatesEN/user/edit.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Administration</title>

<link type="text/css" href="css/screen.css" rel="stylesheet" media="all" />
</head>
<body>
<div class="header">
<ul>
<li class="current"><a href="<?php echo $_SERVER["SCRIPT_NAME"] ?>?action=changePassword">Change Password</a></li>
<?php if($firewall->hasUserAccess()) : ?>
<li><a href="<?php echo $_SERVER["SCRIPT_NAME"] ?>?action=listUsers">List Users</a></li>
<?php endif; ?>
</ul>
</div>

<h1>Change your password</h1>

<?php if (isset($_GET['success'])) : ?>
<div class="flash">
<?php if (empty($_GET['message'])) : ?>
<div class="success">Password changed successfully.</div>
<?php else : ?>
<div class="error"><?php echo $_GET['message'] ?></div>
<?php endif; ?>
</div>
<?php endif; ?>

<div id="main_content">
<form action="<?php echo $_SERVER["SCRIPT_NAME"] ?>?action=updatePassword" method="post">
<fieldset>
<label for="user_password">Enter new password:</label>
<br>
<input type="password" name="password" id="user_password" />
<br>
<label for="user_password_retype">Retype new password:</label>
<br>
<input type="password" name="pwretype" id="user_password_retype" />
</fieldset>

<input type="submit" value="Submit" />
</form>
</div>
</body>
</html>
44 changes: 44 additions & 0 deletions templatesEN/user/index.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Administration</title>

<link type="text/css" href="css/screen.css" rel="stylesheet" media="all" />
</head>
<body>
<div class="header">
<ul>
<li><a href="<?php echo $_SERVER["SCRIPT_NAME"] ?>?action=changePassword">Change Password</a></li>
<?php if($firewall->hasUserAccess()) : ?>
<li class="current"><a href="<?php echo $_SERVER["SCRIPT_NAME"] ?>?action=listUsers">List Users</a></li>
<?php endif; ?>
</ul>
</div>

<h1>List of known users</h1>

<?php if (isset($_GET['success'])) : ?>
<div class="flash">
<?php if (empty($_GET['message'])) : ?>
<div class="success">Password changed successfully.</div>
<?php else : ?>
<div class="error"><?php echo $_GET['message'] ?></div>
<?php endif; ?>
</div>
<?php endif; ?>

<div id="main_content">
<table>
<tr>
<th>Username</th>
</tr>
<?php foreach($userManager->getUsers() as $user) : ?>
<tr>
<td><?php echo $user->getUsername() ?></td>
</tr>
<?php endforeach; ?>
</table>
</div>
</body>
</html>