diff options
Diffstat (limited to 'frontend/index.php')
-rw-r--r-- | frontend/index.php | 229 |
1 files changed, 229 insertions, 0 deletions
diff --git a/frontend/index.php b/frontend/index.php new file mode 100644 index 0000000..373052f --- /dev/null +++ b/frontend/index.php @@ -0,0 +1,229 @@ +<?php +require_once('conf.php'); + +if (isset($_GET['logout'])) { + session_destroy(); + header('Location: /'); +} + +require_once('head.php'); + +if (isset($_POST['create'])) { + $pass = Author::randomPass(); + try { + $author = Author::create( + $_pdo, [$_POST['create_name'], $_POST['create_email'], $pass]); + ?> + Your account has been created. + Your name is <tt><?=$author->name?></tt> and your password is <tt><?=$pass?></tt>. + <b>Store this password in a secure place.</b> + <?php + } catch (Exception $e) { + echo '<p class="error">' . $e->getMessage() . '.</p>'; + } +} + +if (isset($_POST['login'])) { + $authors = Author::search($_pdo, ['`name` like ?'], [$_POST['login_name']]); + if (count($authors) == 0) { + echo '<p class="error">No such user.</p>'; + } else { + $author = $authors[0]; + if ($author->verifyPassword($_POST['login_pass'])) { + $_SESSION['logged_in_id'] = $author->id; + } else { + echo '<p class="error">Invalid password.</p>'; + } + } +} + +if (isset($_SESSION['logged_in_id'])) { + $_author = new Author($_pdo, $_SESSION['logged_in_id']); + echo "You are logged in as {$_author->name}. <a href='?logout'>Logout</a>.<hr/>"; + + if (isset($_POST['create_pkg'])) { + try { + $pkg = Package::create($_pdo, + [ $_author->id + , $_POST['create_pkg_name'] + , $_POST['create_pkg_url'] + , $_POST['create_pkg_git_url'] + , $_POST['create_pkg_desc']]); + echo 'Your package has been created.'; + } catch (Exception $e) { + echo '<p class="error">' . $e->getMessage() . '.</p>'; + } + } +} +?> + +<h2>Packages</h2> +<?php +$pkgs = Package::search($_pdo); + +if (count($pkgs) == 0) : + echo '<p class="error">No packages found.</p>'; +else : +?> + <table> + <tr> + <th>Name</th> + <th>Author</th> + <th>Description</th> + <th>Website</th> + <th>Versions</th> + </tr> + <?php + foreach ($pkgs as $pkg) { + echo + "<tr> + <td>{$pkg->name}</td> + <td>" . $pkg->getAuthor()->name . "</td> + <td>{$pkg->desc}</td>"; + + if ($pkg->url != '') + echo "<td><a href='{$pkg->url}' target='_blank'>Go</a></td>"; + else + echo "<td>&endash;</td>"; + + echo "<td>"; + foreach ($pkg->getVersions() as $v) + echo "{$v->major}.{$v->minor}.{$v->revision} ({$v->time_added})"; + echo "</td>"; + + echo + "<td>{$pkg->name}</td> + </tr>"; + } + ?> + </table> +<?php +endif; +?> + +<hr/> + +<h2>Create an account</h2> +You only need an account to add new packages. +<form method="post"> + <table> + <tr> + <th>Name</th> + <td><input name="create_name"/></td> + <td>Posted publicly.</td> + </tr> + <tr> + <th>Email</th> + <td><input type="email" name="create_email"/></td> + <td>Kept private.</td> + </tr> + <tr> + <th></th> + <td><input type="submit" name="create" value="Create"/></td> + </tr> + </table> +</form> + +<hr/> + +<?php +if (isset($_SESSION['logged_in_id'])) : +?> + <h2>Your packages</h2> + <?php + $pkgs = $_author->getPackages(); + if (count($pkgs) == 0) : + echo '<p class="error">No packages found.</p>'; + else : + ?> + <p>To change details, please contact the CLPM maintainer.</p> + <table> + <tr> + <th>Name</th> + <th>URL</th> + <th>Git URL</th> + <th>Description</th> + </tr> + <?php + foreach ($pkgs as $pkg) { + echo " + <tr> + <td>{$pkg->name}</td>"; + if ($pkg->url != '') + echo "<td><a href='{$pkg->url}'>{$pkg->url}</a></td>"; + else + echo "<td>&endash;</td>"; + echo " + <td><a href='{$pkg->git_url}'>{$pkg->git_url}</a></td> + <td>{$pkg->desc}</td> + </tr>"; + } + ?> + </table> + <?php + endif; + ?> + + <h3>Add new</h3> + <form method="post"> + <table> + <tr> + <th>Name</th> + <td><input name="create_pkg_name"/></td> + <td>Shown publicly.</td> + </tr> + <tr> + <th>URL</th> + <td><input type="url" name="create_pkg_url"/></td> + <td>Shown publicly.</td> + </tr> + <tr> + <th>Git URL</th> + <td><input type="url" name="create_pkg_git_url"/></td> + <td> + <p>Your git repository. It should not require authorisation.</p> + <p>On scheduled intervals, we will clone the repository and + search for tags that look like a version number, e.g. <tt>v1.0.2</tt>. + For those versions that are not yet found in the database, + we will checkout the tag and run <tt>make TARGET.tar.gz</tt> for all targets + (currently <tt>linux32</tt>, <tt>linux64</tt>, <tt>mac</tt>, <tt>win32</tt> and <tt>win64</tt>). + We will then copy tose files to <tt>/repo/PACKAGE/VERSION/PLATFORM.tar.gz</tt>.</p> + </td> + </tr> + <tr> + <th>Description</th> + <td colspan="2"> + <textarea name="create_pkg_desc" cols="60" rows="6"></textarea> + </td> + </tr> + <tr> + <th></th> + <td><input type="submit" name="create_pkg" value="Add"/></td> + </tr> + </table> + </form> +<?php +else : // Not logged in +?> + <h2>Login</h2> + <form method="post"> + <table> + <tr> + <th>Name</th> + <td><input name="login_name"/></td> + </tr> + <tr> + <th>Password</th> + <td><input type="password" name="login_pass"/></td> + </tr> + <tr> + <th></th> + <td><input type="submit" name="login" value="Login"/></td> + </tr> + </table> + <p>If you lost your password, please contact the CLPM maintainer.</p> + </form> +<?php +endif; + +require_once('foot.php'); |