/**
  * Authenticates a user by username/password credentials. Uses the 'users' DB table.
  * @uses User_Model
  * @access public
  * @param string $username
  * @param string $password
  * @return bool
  */
 function auth_user($username, $password)
 {
     $this->load->helper('secure_hash');
     $params = array('username' => $username, 'status' => 'Active');
     if ($user = $this->user_model->get($params, true)) {
         if (validate_password($password, $user->password)) {
             log_message('info', 'User ' . $this->user_model->get_name($user->id) . ' has just logged in!');
             reload_session_caps($user->id);
             return true;
         } else {
             add_message('Incorrect username or password, please verify your details and try again.', 'danger');
             return false;
         }
     } else {
         add_message('Incorrect username or password, please verify your details and try again.', 'danger');
         return false;
     }
 }
Esempio n. 2
0
 public function guest($registerkey)
 {
     if ($user = $this->user_model->get(array('registerkey' => $registerkey, 'status' => 'Suspended'), true)) {
         add_message('Sorry, this URL has already been used once, please apply for a new URL by completing the form below.', 'warning');
         redirect(base_url());
     }
     if (!($user = $this->user_model->get(array('registerkey' => $registerkey, 'status' => 'Active'), true))) {
         add_message('Sorry, this URL was not recognised, please make sure you copied it correctly from the email we sent you.', 'warning');
         redirect(base_url());
     }
     reload_session_caps($user->id);
     $this->user_login_model->add(array('user_id' => $user->id, 'session_id' => session_id(), 'last_page_load' => time()));
     if ($user->type == 'demo') {
         $this->user_model->edit($user->id, array('status' => 'Suspended'));
     }
     add_message('Welcome to the demo of ' . $this->setting_model->get_value('Site Name') . '! Please follow the guided tours to learn your way around.');
     redirect(base_url() . 'home');
 }