aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2012-01-05 21:00:13 +0100
committerKevin Chabowski <kevin@kch42.de>2012-01-05 21:00:13 +0100
commit0025f908f7a4fc195fdccf0879140850f9085033 (patch)
treed2a3bf073f3a1715f16569ff603833d0b2a596ca
parent5a87705b5142f70e3e13af93a52a9e7f612cf951 (diff)
downloadr7r-repo-0025f908f7a4fc195fdccf0879140850f9085033.tar.gz
r7r-repo-0025f908f7a4fc195fdccf0879140850f9085033.tar.bz2
r7r-repo-0025f908f7a4fc195fdccf0879140850f9085033.zip
register implemented.
-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>