From 7c7eaa5feb44ff93d30a97e8a323680419df3672 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Thu, 24 Jan 2013 19:28:17 +0100 Subject: Repurpose invitations table to actions This can be used to track data for all kinds of one-time actions like invitations and password resets. Signed-off-by: Florian Pritz --- application/controllers/user.php | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'application/controllers') diff --git a/application/controllers/user.php b/application/controllers/user.php index 0550b0f6a..39bf1d767 100644 --- a/application/controllers/user.php +++ b/application/controllers/user.php @@ -81,8 +81,9 @@ class User extends CI_Controller { // TODO: count both, invited users and key $query = $this->db->query(" SELECT count(*) as count - FROM invitations - WHERE user = ? + FROM `actions` + WHERE `user` = ? + AND `action` = 'invitation' ", array($userid))->row_array(); if ($query["count"] + 1 > 3) { @@ -92,9 +93,9 @@ class User extends CI_Controller { $key = random_alphanum(12, 16); $this->db->query(" - INSERT INTO invitations - (`key`, `user`, `date`) - VALUES (?, ?, ?) + INSERT INTO `actions` + (`key`, `user`, `date`, `action`) + VALUES (?, ?, ?, 'invitation') ", array($key, $userid, time())); redirect("user/invite"); @@ -108,8 +109,9 @@ class User extends CI_Controller { $query = $this->db->query(" SELECT `key`, `date` - FROM invitations - WHERE user = ? + FROM `actions` + WHERE `user` = ? + AND `action` = 'invitation' ", array($userid))->result_array(); $this->data["query"] = $query; @@ -131,8 +133,9 @@ class User extends CI_Controller { $query = $this->db->query(" SELECT `user`, `key` - FROM invitations + FROM actions WHERE `key` = ? + AND `action` = 'invitation' ", array($key))->row_array(); if (!isset($query["key"]) || $key != $query["key"]) { @@ -176,7 +179,7 @@ class User extends CI_Controller { $referrer )); $this->db->query(" - DELETE FROM invitations + DELETE FROM actions WHERE `key` = ? ", array($key)); $this->load->view('header', $this->data); @@ -229,12 +232,12 @@ class User extends CI_Controller { { if (!$this->input->is_cli_request()) return; - if ($this->config->item('invitations_max_age') == 0) return; + if ($this->config->item('actions_max_age') == 0) return; - $oldest_time = (time() - $this->config->item('invitations_max_age')); + $oldest_time = (time() - $this->config->item('actions_max_age')); $this->db->query(" - DELETE FROM invitations + DELETE FROM actions WHERE date < ? ", array($oldest_time)); } -- cgit v1.2.3-24-g4f1b