code-igniter-v3-giggi: update release v1
diff --git a/application/controllers/Invite.php b/application/controllers/Invite.php
new file mode 100644
index 0000000..9c98621
--- /dev/null
+++ b/application/controllers/Invite.php
@@ -0,0 +1,95 @@
+<?php
+
+class Invite extends CI_Controller {
+ private function is_valid_file($rel_path = '/', $file_html = 'home.html')
+ {
+ $abs_path = APPPATH.$rel_path.$file_html;
+ if (file_exists($abs_path))
+ return true;
+
+ return false;
+ }
+
+ private function is_post_invalid()
+ {
+ return !$this->form_validation->run();
+ }
+
+ public function view($file_name = 'invite')
+ {
+ $file_html = $file_name.'.html';
+ if ($this->is_valid_file('views/page/', $file_html))
+ {
+ /* Got to open a connection here as validation may require one */
+ if (!$this->load->database())
+ redirect(base_url('index.html'));
+
+ $this->load->helper(array('form', 'url'));
+ $this->load->library('form_validation');
+
+ $this->form_validation->set_rules('username', 'Username',
+ 'required|min_length[5]|max_length[12]|is_unique[users.username]',
+ array(
+ 'required' => 'You must provide a %s',
+ 'min_length' => '%s must be more than 5 chars',
+ 'max_length' => '%s must be less than 12 chars',
+ 'is_unique' => 'This %s already exists'
+ )
+ );
+
+ $this->form_validation->set_rules('password', 'Password', 'required',
+ array('required' => 'You must provide a %s')
+ );
+
+ $this->form_validation->set_rules('passconf', 'Password Confirmation',
+ 'required|matches[password]',
+ array(
+ 'required' => 'You must provide a %s',
+ 'matches' => 'Passowrd confirmation didn\'t match'
+ )
+ );
+
+ $this->form_validation->set_rules('email', 'Email', 'required',
+ array('required' => 'You must provide a %s')
+ );
+
+ if ($this->is_post_invalid())
+ {
+ /* Validation errors already set */
+ }
+ else
+ {
+ /* Add backticks on ientifiers */
+ $this->db->protect_identifiers('users', TRUE);
+
+ /* Always use query bindings as they are automatically escaped */
+ $stmt = "INSERT INTO users (username, email, password) VALUES (?, ?, ?)";
+ $data = $this->input->post(array('username', 'email'));
+ $password = $this->input->post('password');
+ $hash_password = password_hash($password, PASSWORD_DEFAULT);
+ $data['password'] = $hash_password;
+
+ if (!$this->db->query($stmt, $data))
+ {
+ /* Debug:
+ *
+ * $error = $this->db->error();
+ * var_dump($error);
+ */
+ $this->form_validation->set_message('submit_msg', 'Didn\'t work, :|');
+ }
+ else
+ {
+ $this->form_validation->set_string('Invite succesfully sent');
+ }
+ }
+
+ $this->db->close();
+ $this->load->view('page/'.$file_html);
+ }
+ else
+ {
+ redirect(base_url('index.html'));
+ }
+ }
+}