diff options
author | Florian Pritz <bluewind@xinu.at> | 2012-04-09 13:47:31 +0200 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2012-04-09 20:48:18 +0200 |
commit | ec1a30e1bc2c33db485140c51591126078425512 (patch) | |
tree | d79ad1a344b08e1368b7a8b9bee30b8439c1013c | |
parent | 5940316125c1672b72eb08186e6c43f5a91e71ef (diff) |
add register function
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rw-r--r-- | application/controllers/user.php | 73 | ||||
-rw-r--r-- | application/views/user/invite.php | 2 | ||||
-rw-r--r-- | application/views/user/register.php | 26 |
3 files changed, 100 insertions, 1 deletions
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() { diff --git a/application/views/user/invite.php b/application/views/user/invite.php index f97804274..968315ac9 100644 --- a/application/views/user/invite.php +++ b/application/views/user/invite.php @@ -5,6 +5,6 @@ <p>Unused invitation keys:</p> <p> <?php foreach($query as $key => $item): ?> - <?php echo $item["key"]; ?><br /> + <?php echo anchor("user/register/".$item["key"], $item["key"]); ?><br /> <?php endforeach; ?> </p> diff --git a/application/views/user/register.php b/application/views/user/register.php new file mode 100644 index 000000000..78af46e96 --- /dev/null +++ b/application/views/user/register.php @@ -0,0 +1,26 @@ +<?php if (!empty($error)) { + echo "<p>"; + echo implode("<br />\n", $error); + echo "</p>"; +} ?> +<?php echo form_open('user/register/'.$key); ?> + <table> + <tr> + <td>Username</td> + <td> <input type="text" name="username" value="<?=$values["username"]; ?>" /></td> + </tr><tr> + <td>Email</td> + <td> <input type="text" name="email" value="<?=$values["email"]; ?>" /></td> + </tr><tr> + <td>Password</td> + <td> <input type="password" name="password" /></td> + </tr><tr> + <td>Confirm password</td> + <td> <input type="password" name="password_confirm" /></td> + </tr><tr> + <td></td> + <td><input type="submit" value="Register" name="process" /></td> + </tr> + </table> +</form> + |