diff --git a/User.php b/User.php index 7128493..6fa8559 100644 --- a/User.php +++ b/User.php @@ -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)); } diff --git a/UserController.php b/UserController.php index 7ec2083..70b5670 100644 --- a/UserController.php +++ b/UserController.php @@ -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() { @@ -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"; } } } diff --git a/UserManager.php b/UserManager.php index ce3b55f..b41abe2 100644 --- a/UserManager.php +++ b/UserManager.php @@ -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; @@ -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; diff --git a/templates/403.phtml b/templatesDE/403.phtml similarity index 100% rename from templates/403.phtml rename to templatesDE/403.phtml diff --git a/templates/user/edit.phtml b/templatesDE/user/edit.phtml similarity index 87% rename from templates/user/edit.phtml rename to templatesDE/user/edit.phtml index 243ef4d..0d137f2 100644 --- a/templates/user/edit.phtml +++ b/templatesDE/user/edit.phtml @@ -32,7 +32,12 @@
?action=updatePassword" method="post">
+
+
+ +
+
diff --git a/templates/user/index.phtml b/templatesDE/user/index.phtml similarity index 100% rename from templates/user/index.phtml rename to templatesDE/user/index.phtml diff --git a/templatesEN/403.phtml b/templatesEN/403.phtml new file mode 100644 index 0000000..95f04d4 --- /dev/null +++ b/templatesEN/403.phtml @@ -0,0 +1,36 @@ + + + + + Administration + + + + +
+ +
+ +

Error 403

+ + +
+ +
Password changed successfully.
+ +
+ +
+ + +
+

403

+

Access denied

+
+ + diff --git a/templatesEN/user/edit.phtml b/templatesEN/user/edit.phtml new file mode 100644 index 0000000..38287bb --- /dev/null +++ b/templatesEN/user/edit.phtml @@ -0,0 +1,47 @@ + + + + + Administration + + + + +
+ +
+ +

Change your password

+ + +
+ +
Password changed successfully.
+ +
+ +
+ + +
+ ?action=updatePassword" method="post"> +
+ +
+ +
+ +
+ +
+ + + +
+ + \ No newline at end of file diff --git a/templatesEN/user/index.phtml b/templatesEN/user/index.phtml new file mode 100644 index 0000000..420f196 --- /dev/null +++ b/templatesEN/user/index.phtml @@ -0,0 +1,44 @@ + + + + + Administration + + + + +
+ +
+ +

List of known users

+ + +
+ +
Password changed successfully.
+ +
+ +
+ + +
+ + + + + getUsers() as $user) : ?> + + + + +
Username
getUsername() ?>
+
+ +