Add a very basic login view.
authorGunnar Wrobel <p@rdus.de>
Wed, 29 Apr 2009 05:40:07 +0000 (07:40 +0200)
committerGunnar Wrobel <p@rdus.de>
Wed, 29 Apr 2009 05:43:55 +0000 (07:43 +0200)
koward/lib/Koward/Controller/LoginController.php [new file with mode: 0644]
koward/lib/Koward/View/Login/login.html.php [new file with mode: 0644]

diff --git a/koward/lib/Koward/Controller/LoginController.php b/koward/lib/Koward/Controller/LoginController.php
new file mode 100644 (file)
index 0000000..0fbe30d
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+/**
+ * @package Koward
+ */
+
+/**
+ * @package Koward
+ */
+class LoginController extends Koward_Controller_Application
+{
+    protected $welcome;
+
+    protected $auth_handler = true;
+
+    public function login()
+    {
+        $auth = Auth::getAuth();
+        if (!empty($auth)) {
+            header('Location: ' . $this->urlFor(array('controller' => 'index')));
+            exit;
+        }
+
+        $this->title = _("Login");
+        $this->welcome = _("Welcome.");
+
+        $this->post = $this->urlFor(array('controller' => 'login', 
+                                          'action' => 'login'));
+
+        if (isset($_POST['horde_user']) && isset($_POST['horde_pass'])) {
+            /* Destroy any existing session on login and make sure to use a
+             * new session ID, to avoid session fixation issues. */
+            Horde::getCleanSession();
+            if ($this->koward->auth->authenticate(Util::getPost('horde_user'),
+                                                  array('password' => Util::getPost('horde_pass')))) {
+                $entry = sprintf('Login success for %s [%s] to Horde',
+                                 Auth::getAuth(), $_SERVER['REMOTE_ADDR']);
+                Horde::logMessage($entry, __FILE__, __LINE__, PEAR_LOG_NOTICE);
+
+                header('Location: ' . $this->urlFor(array('controller' => 'index')));
+                exit;
+            } else {
+                $entry = sprintf('FAILED LOGIN for %s [%s] to Horde',
+                                 Util::getFormData('horde_user'), $_SERVER['REMOTE_ADDR']);
+                Horde::logMessage($entry, __FILE__, __LINE__, PEAR_LOG_ERR);
+            }
+        }
+
+        if ($reason = $this->koward->auth->getLogoutReasonString()) {
+            $this->koward->notification->push(str_replace('<br />', ' ', $reason), 'horde.message');
+        }
+
+    }
+}
\ No newline at end of file
diff --git a/koward/lib/Koward/View/Login/login.html.php b/koward/lib/Koward/View/Login/login.html.php
new file mode 100644 (file)
index 0000000..48dc91c
--- /dev/null
@@ -0,0 +1,28 @@
+<?= $this->renderPartial('header'); ?>
+
+<div id="menu">
+ <h1 style="text-align:center"><?= $this->welcome ?></h1>
+</div>
+
+<?php $this->koward->notification->notify(array('listeners' => 'status')) ?>
+
+<form name="koward_login" method="post" action="<?= $this->post ?>"
+<table width="100%"><tr><td align="center"><table width="300" align="center">
+
+<tr>
+    <td class="light rightAlign"><strong><?php echo Horde::label('horde_user', _("Username")) ?></strong>&nbsp;</td>
+    <td class="leftAlign"><input type="text" id="horde_user" name="horde_user" value="<?php echo htmlspecialchars(Util::getFormData('horde_user')) ?>" style="direction:ltr" /></td>
+</tr>
+
+<tr>
+    <td class="light rightAlign"><strong><?php echo Horde::label('horde_pass', _("Password")) ?></strong>&nbsp;</td>
+    <td class="leftAlign"><input type="password" id="horde_pass" name="horde_pass" value="" style="direction:ltr" /></td>
+</tr>
+
+<tr>
+    <td>&nbsp;</td>
+    <td class="light leftAlign"><input name="loginButton" class="button" value="<?php echo _("Log in") ?>" type="submit" onclick="return submit_login();" /></td>
+</tr>
+
+</table></td></tr></table>
+</form>