summaryrefslogtreecommitdiffstats
path: root/application/controllers/user.php
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2013-01-24 19:28:17 +0100
committerFlorian Pritz <bluewind@xinu.at>2013-01-24 19:29:48 +0100
commit7c7eaa5feb44ff93d30a97e8a323680419df3672 (patch)
tree060dc43f6edc15a252cbfd265f44281059cf4072 /application/controllers/user.php
parent54eec0dfee36ba686cdcc4515bccea79b07c2393 (diff)
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 <bluewind@xinu.at>
Diffstat (limited to 'application/controllers/user.php')
-rw-r--r--application/controllers/user.php27
1 files changed, 15 insertions, 12 deletions
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));
}