aboutsummaryrefslogtreecommitdiff
path: root/r7r_repo
diff options
context:
space:
mode:
Diffstat (limited to 'r7r_repo')
-rw-r--r--r7r_repo/main.php41
-rw-r--r--r7r_repo/templates/src/register.html12
2 files changed, 53 insertions, 0 deletions
diff --git a/r7r_repo/main.php b/r7r_repo/main.php
index a6e0199..f7a16cf 100644
--- a/r7r_repo/main.php
+++ b/r7r_repo/main.php
@@ -174,6 +174,47 @@ $url_handlers = array(
$ste->vars["success"] = "Logged out successfully.";
$url_next = array("_prelude", "index");
},
+ "register" => function(&$data, $url_now, &$url_next)
+ {
+ global $ste, $user, $settings;
+
+ if($settings["repo_mode"] == "private")
+ throw new NotFoundError();
+
+ if($user !== NULL)
+ {
+ $url_next = array("index");
+ return;
+ }
+
+ $url_next = array();
+ $ste->vars["menu"] = "register";
+ $ste->vars["title"] = "Register";
+
+ if(isset($_POST["register"]))
+ {
+ if(empty($_POST["username"]) or empty($_POST["password"]))
+ $ste->vars["error"] = "Formular not filled out.";
+ else
+ {
+ try
+ {
+ $u = User::by_name($_POST["username"]);
+ $ste->vars["error"] = "Username already exists.";
+ }
+ catch(DoesNotExistError $e)
+ {
+ $u = User::create($_POST["username"]);
+ $u->isadmin = False;
+ $u->pwhash = PasswordHash::create($_POST["password"]);
+ $u->save();
+ $ste->vars["success"] = "Account successfully created. You can now log in.";
+ }
+ }
+ }
+
+ echo $ste->exectemplate("register.html");
+ },
"setup" => function(&$data, $url_now, &$url_next)
{
global $settings, $ste;
diff --git a/r7r_repo/templates/src/register.html b/r7r_repo/templates/src/register.html
new file mode 100644
index 0000000..5d89a71
--- /dev/null
+++ b/r7r_repo/templates/src/register.html
@@ -0,0 +1,12 @@
+<ste:load name="master.html" />
+<ste:block name="content">
+ <ste:default_error />
+ <ste:default_success />
+
+ <form action="$rel_path_to_root/register" method="POST" accept-charset="UTF-8">
+ <h2>Register for a new account</h2>
+ <strong>Username:</strong> <input type="text" name="username" /><br />
+ <strong>Password:</strong> <input type="password" name="password" /><br />
+ <input type="submit" name="register" />
+ </form>
+</ste:block>