- public function login($username = NULL, $password = NULL)
- {
- if($username === NULL)
- {
- $username = $this->input->post('username');
- $password = $this->input->post('password');
- }
- if(empty($username) || empty($password))
- return FALSE;
- $user = $this->get_by(array(
- 'username' => $username,
- 'password' => $this->hash($password),
- ), TRUE);
- // Additional check to login with email
- if(sw_count($user) == 0)
- {
- $user = $this->get_by(array(
- 'mail' => $username,
- 'password' => $this->hash($password),
- ), TRUE);
- }
- if(sw_count($user))
- {
- if($user->activated == FALSE && ($user->type == 'USER' || $user->type == 'AGENT'))
- {
- // User and not activated
- }
- else
- {
- // Update last login data
- $this->db->where('id', $user->id);
- $this->db->update($this->_table_name, array('last_login' => date('Y-m-d H:i:s')));
- $profile_image = '';
- if(!empty($user->repository_id))
- {
- $this->_table_name = 'file';
- $this->_order_by = 'id';
- // Get profile image from repository
- $image = $this->get_by(array(
- 'repository_id' => $user->repository_id
- ), TRUE);
- $this->_table_name = 'user';
- $this->_order_by = 'name_surname ';
- if(sw_count($image))
- {
- $profile_image = 'files/thumbnail/'.$image->filename;
- }
- }
- // Log in user
- $data = array(
- 'name_surname'=>$user->name_surname,
- 'username'=>$user->username,
- 'remember'=>(bool)$this->input->post('remember'),
- 'id'=>$user->id,
- 'lang'=>$user->language,
- 'user_namesurname'=>$user->username,
- 'idcode'=>$user->user_idcode,
- 'last_login'=>$user->last_login,
- 'loggedin'=>TRUE,
- 'type'=>$user->type,
- 'profile_image'=>$profile_image,
- 'last_activity'=>time()
- );
- $this->session->set_userdata($data);
- $this->user_session_data = $data;
- return TRUE;
- }
- }
- return FALSE;
- }
Untitled
From Ivory Rhinoceros, 8 Months ago, written in Plain Text, viewed 1 times.
This paste will go to its last resting place in 1 Second.
URL https://paste.ovh/view/a198e0c4
Embed
Download Paste or View Raw
— Expand Paste to full width of browser