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 @@