From e8d30fa25470f3912c0d4e8629fc7b764aae1c72 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Fri, 25 Jan 2013 23:24:31 +0100 Subject: Refactor querying action table Signed-off-by: Florian Pritz --- application/controllers/user.php | 23 ++--------------------- application/models/muser.php | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/application/controllers/user.php b/application/controllers/user.php index 4a79a6730..1562ae9fd 100644 --- a/application/controllers/user.php +++ b/application/controllers/user.php @@ -131,16 +131,7 @@ class User extends CI_Controller { ); $error = array(); - $query = $this->db->query(" - SELECT `user`, `key` - FROM actions - WHERE `key` = ? - AND `action` = 'invitation' - ", array($key))->row_array(); - - if (!isset($query["key"]) || $key != $query["key"]) { - show_error("Invalid invitation key."); - } + $query = $this->muser->get_action("invitation", $key); $referrer = $query["user"]; @@ -285,17 +276,7 @@ class User extends CI_Controller { $key = $this->uri->segment(3); $error = array(); - // TODO: refactor into common function - $query = $this->db->query(" - SELECT `user`, `key` - FROM actions - WHERE `key` = ? - AND `action` = 'passwordreset' - ", array($key))->row_array(); - - if (!isset($query["key"]) || $key != $query["key"]) { - show_error("Invalid reset key."); - } + $query = $this->muser->get_action("passwordreset", $key); $userid = $query["user"]; diff --git a/application/models/muser.php b/application/models/muser.php index ee086994d..c277118f2 100644 --- a/application/models/muser.php +++ b/application/models/muser.php @@ -144,6 +144,22 @@ class Muser extends CI_Model { } } + function get_action($action, $key) + { + $query = $this->db->query(" + SELECT * + FROM actions + WHERE `key` = ? + AND `action` = ? + ", array($key, $action))->row_array(); + + if (!isset($query["key"]) || $key != $query["key"]) { + show_error("Invalid action key"); + } + + return $query; + } + function hash_password($password) { -- cgit v1.2.3-24-g4f1b