Clean-up user model

This commit is contained in:
Eike Foken
2011-09-21 02:14:29 +02:00
parent 76f3134756
commit 0442f39664
2 changed files with 30 additions and 34 deletions

View File

@@ -25,6 +25,7 @@
* Simple auth system. * Simple auth system.
* *
* @package ScattPort * @package ScattPort
* @subpackage Libraries
* @author Eike Foken <kontakt@eikefoken.de> * @author Eike Foken <kontakt@eikefoken.de>
*/ */
class Access { class Access {
@@ -90,7 +91,7 @@ class Access {
public function forgottenPassword($email) { public function forgottenPassword($email) {
if ($this->CI->user->forgottenPassword($email)) { if ($this->CI->user->forgottenPassword($email)) {
// get user information // get user information
$user = $this->CI->user->getUserByEmail($email); $user = $this->CI->user->getByEmail($email);
$data = array( $data = array(
'username' => $user['username'], 'username' => $user['username'],
@@ -258,7 +259,7 @@ class Access {
* @return object * @return object
*/ */
public function getCurrentUser() { public function getCurrentUser() {
return $this->CI->user->getUserByID($this->CI->session->userdata('user_id')); return $this->CI->user->getById($this->CI->session->userdata('user_id'));
} }
/** /**

View File

@@ -376,13 +376,24 @@ class User extends CI_Model {
return $this->get()->result_array(); return $this->get()->result_array();
} }
/**
* Gets a specified number of new users.
*
* @param integer $limit
* @return array
*/
public function getNewest($limit = 10) {
$this->db->order_by('users.created_on DESC')->limit($limit);
return $this->get()->result_array();
}
/** /**
* Gets a user by ID. * Gets a user by ID.
* *
* @param string $id * @param string $id
* @return array * @return array
*/ */
public function getUserByID($id = false) { public function getById($id = false) {
if (empty($id)) { if (empty($id)) {
return false; return false;
} }
@@ -392,13 +403,24 @@ class User extends CI_Model {
return $this->get()->row_array(); return $this->get()->row_array();
} }
/**
* Gets a user by ID.
*
* @deprecated 21-09-2011
* @param string $id
* @return array
*/
public function getUserByID($id = false) {
return $this->getById($id);
}
/** /**
* Gets a user by email. * Gets a user by email.
* *
* @param string $email * @param string $email
* @return array * @return array
*/ */
public function getUserByEmail($email) { public function getByEmail($email) {
$this->db->where('users.email', $email)->limit(1); $this->db->where('users.email', $email)->limit(1);
return $this->get()->row_array(); return $this->get()->row_array();
} }
@@ -409,38 +431,11 @@ class User extends CI_Model {
* @param string $username * @param string $username
* @return array * @return array
*/ */
public function getUserByUsername($username) { public function getByUsername($username) {
$this->db->where('users.username', $username)->limit(1); $this->db->where('users.username', $username)->limit(1);
return $this->get()->row_array(); return $this->get()->row_array();
} }
/**
* Gets a specified number of new users.
*
* @param integer $limit
* @return array
*/
public function getNewestUsers($limit = 10) {
$this->db->order_by('users.created_on DESC')->limit($limit);
return $this->get()->result_array();
}
/**
* Gets a users group.
*
* @param string $id
* @return array
*/
public function getUsersGroup($id = false) {
// if no ID was passed use the current users ID
$id || $id = $this->session->userdata('user_id');
$user = $this->db->select('group_id')->where('id', $id)->get('users')->row();
return $this->db->select('name, description')
->where('id', $user->group_id)->get('groups')->row_array();
}
/** /**
* Gets a users settings. * Gets a users settings.
* *
@@ -475,7 +470,7 @@ class User extends CI_Model {
* @return boolean Returns TRUE if the update was successful. * @return boolean Returns TRUE if the update was successful.
*/ */
public function update($id, $data) { public function update($id, $data) {
$user = $this->getUserByID($id); $user = $this->getById($id);
if (array_key_exists('username', $data) && $this->checkUsername($data['username']) && $user['username'] !== $data['username']) { if (array_key_exists('username', $data) && $this->checkUsername($data['username']) && $user['username'] !== $data['username']) {
$this->messages->add(_('The entered username is already in use.'), 'error'); $this->messages->add(_('The entered username is already in use.'), 'error');
@@ -582,7 +577,7 @@ class User extends CI_Model {
return false; return false;
} }
$user = $this->getUserByID($id); $user = $this->getById($id);
$salt = sha1($user['password']); $salt = sha1($user['password']);