summaryrefslogtreecommitdiffstats
path: root/application/controllers
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2012-04-09 11:26:22 +0200
committerFlorian Pritz <bluewind@xinu.at>2012-04-09 20:48:16 +0200
commitc0f1755842211996a7a21ffb8773b260bb2be281 (patch)
tree609107150d2ee82cdbb3ed9157ceccf0cf98f8a7 /application/controllers
parentcb8b733a6c2333ff90d3af0fc37e8c21c73d9e7a (diff)
Implement simple referral system
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'application/controllers')
-rw-r--r--application/controllers/user.php49
1 files changed, 49 insertions, 0 deletions
diff --git a/application/controllers/user.php b/application/controllers/user.php
index 722996d93..4fffbef9b 100644
--- a/application/controllers/user.php
+++ b/application/controllers/user.php
@@ -57,6 +57,55 @@ class User extends CI_Controller {
$this->load->view($this->var->view_dir.'footer', $this->data);
}
}
+
+ function create_invitation_key()
+ {
+ $this->muser->require_access();
+
+ $userid = $this->muser->get_userid();
+
+ // TODO: count both, invited users and key
+ $query = $this->db->query("
+ SELECT count(*) as count
+ FROM invitations
+ WHERE user = ?
+ ", array($userid))->row_array();
+
+ if ($query["count"] + 1 > 3) {
+ // TODO: better message
+ echo "You've reached your invitation limit.";
+ return;
+ }
+
+ $key = random_id(12, 16);
+
+ $this->db->query("
+ INSERT INTO invitations
+ (`key`, `user`, `date`)
+ VALUES (?, ?, ?)
+ ", array($key, $userid, time()));
+
+ redirect("user/invite");
+ }
+
+ function invite()
+ {
+ $this->muser->require_access();
+
+ $userid = $this->muser->get_userid();
+
+ $query = $this->db->query("
+ SELECT *
+ FROM invitations
+ WHERE user = ?
+ ", array($userid))->result_array();
+
+ $this->data["query"] = $query;
+
+ $this->load->view($this->var->view_dir.'header', $this->data);
+ $this->load->view($this->var->view_dir.'invite', $this->data);
+ $this->load->view($this->var->view_dir.'footer', $this->data);
+ }
function logout()
{