From ec1a30e1bc2c33db485140c51591126078425512 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Mon, 9 Apr 2012 13:47:31 +0200 Subject: add register function Signed-off-by: Florian Pritz --- application/controllers/user.php | 73 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) (limited to 'application/controllers/user.php') diff --git a/application/controllers/user.php b/application/controllers/user.php index 5795db158..67c3ccbb7 100644 --- a/application/controllers/user.php +++ b/application/controllers/user.php @@ -106,6 +106,79 @@ class User extends CI_Controller { $this->load->view($this->var->view_dir.'invite', $this->data); $this->load->view($this->var->view_dir.'footer', $this->data); } + + function register() + { + $key = $this->uri->segment(3); + $process = $this->input->post("process"); + $values = array( + "username" => "", + "email" => "" + ); + $error = array(); + + $query = $this->db->query(" + SELECT `user`, `key` + FROM invitations + WHERE `key` = ? + ", array($key))->row_array(); + + if (!isset($query["key"]) || $key != $query["key"]) { + // TODO: better message + echo "Unknown key."; + return; + } + + $referrer = $query["user"]; + + if ($process) { + $username = $this->input->post("username"); + $email = $this->input->post("email"); + $password = $this->input->post("password"); + $password_confirm = $this->input->post("password_confirm"); + + if (!$username) { + $error[]= "Invalid username."; + } + + $this->load->helper("email"); + if (!valid_email($email)) { + $error[]= "Invalid email."; + } + + if (!$password || $password != $password_confirm) { + $error[]= "No password or passwords don't match."; + } + + if (empty($error)) { + $this->db->query(" + INSERT INTO users + (`username`, `password`, `email`, `referrer`) + VALUES(?, ?, ?, ?) + ", array( + $username, + $this->muser->hash_password($password), + $email, + $referrer + )); + $this->db->query(" + DELETE FROM invitations + WHERE `key` = ? + ", array($key)); + } else { + $values["username"] = $username; + $values["email"] = $email; + } + } + + $this->data["key"] = $key; + $this->data["values"] = $values; + $this->data["error"] = $error; + + $this->load->view($this->var->view_dir.'header', $this->data); + $this->load->view($this->var->view_dir.'register', $this->data); + $this->load->view($this->var->view_dir.'footer', $this->data); + } function logout() { -- cgit v1.2.3-24-g4f1b