Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Dubauth
- {
- private $error = array();
- function __construct()
- {
- $this->ci =& get_instance();
- $this->ci->load->library('session');
- $this->ci->load->model('user');
- $this->ci->load->helper('string');
- }
- function login($username, $password)
- {
- if(!($user = $this->ci->user->login_username($username)))
- {
- $this->error = 'invalid_user_pass';
- return false;
- }
- elseif($user->password != $password)
- {
- $this->error = 'invalid_user_pass';
- return false;
- }
- elseif($user->active == 0)
- {
- $this->error = 'account_not_verified';
- return false;
- }
- elseif($user->banned == 1)
- {
- $this->error = 'account_banned';
- return false;
- }
- else
- {
- $this->ci->session->set_userdata(array(
- 'user_id' => $user->user_id,
- 'username' => $user->username
- ));
- return true;
- }
- }
- function verify($key)
- {
- if(!($user_id = $this->ci->user->is_key_valid($key)))
- {
- $this->error = 'invalid_key';
- return false;
- }
- else
- {
- $this->ci->user->validate($user_id, $key);
- return true;
- }
- }
- function register($username, $email, $password)
- {
- if($this->ci->user->is_username_registered($username))
- {
- $this->error = 'username_registered';
- return false;
- }
- elseif($this->ci->user->is_email_registered($email))
- {
- $this->error = 'email_registered';
- return false;
- }
- else
- {
- $array = array(
- 'username' => $this->ci->input->post('username'),
- 'email' => $this->ci->input->post('email'),
- 'password' => md5($this->ci->input->post('password'))
- );
- $this->ci->db->insert('users', $array);
- $array = array(
- 'user_id' => $this->ci->db->insert_id(),
- 'key' => random_string('unique')
- );
- $this->ci->db->insert('user_verify_keys', $array);
- return true;
- }
- }
- function logout()
- {
- $this->ci->session->sess_destroy();
- }
- function is_logged_in()
- {
- $user_id = $this->ci->session->userdata('user_id');
- if(!isset($user_id))
- {
- return false;
- }
- else
- {
- $this->ci->db->select('user_id');
- $this->ci->db->where('user_id', $this->ci->session->userdata('user_id'));
- $query = $this->ci->db->get('users');
- if($query->num_rows() == 0)
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- }
- function get_error_message()
- {
- return $this->error;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement