/** * Authorizes the user. * * @param string $username The users username. * @param string $password The users password. * @return bool */ public static function authorize(string $username, string $password) : bool { // Get the username field name. $field = Auth::usernameField(); // Find user by thier username. $user = static::where($field, '=', $username)->first(); // Was a user found? if (is_object($user)) { // If a user was found, ensure they have a valid password. if ($user->password === Auth::encryptPassword($password, $user->salt)) { // Authorize the user. Auth::authorize($user); // Success. return true; } } // Failure. return false; }
public static function getpass($password, $password_db) { return Auth::encryptPassword($password, substr($password_db, 0, SALT_LENGTH)); }
public function employee_registration() { if (!is_moduleAllowed($this->session->userdata('group_id'), 'employee/employee_registration')) { redirect('home'); } $license_id = $this->session->userdata('license_id'); $data['active_module_parent_id'] = $this->parent_module_id; $data['web_title'] = "Employee Registration"; $params['license_id'] = $license_id; $params['single'] = true; $data['getLicense'] = $this->model_license->getLicense($params); if (count($data['getLicense']) == 0) { redirect('home'); } $data['post'] = array(); if ($this->input->post()) { $post = $this->input->post(); $this->load->library('form_validation'); $this->form_validation->set_rules('name', 'Name', 'trim|required'); $this->form_validation->set_rules('username', 'Username', 'trim|required|callback_username_check|min_length[5]|max_length[30]', array('is_unique' => '%s already exists. Please choose different one.')); $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[5]'); $this->form_validation->set_rules('passwordconf', 'Confirm Password', 'trim|required|min_length[5]|matches[password]'); if ($this->form_validation->run() == FALSE) { $data['message_type'] = 'danger'; $data['message'] = validation_errors('<div>', '</div>'); $data['post'] = $post; } else { $valid = true; if ($_FILES['user_employee_photo']['tmp_name'] != '') { $config['allowed_types'] = 'gif|jpg|png'; $config['overwrite'] = true; $config['file_name'] = $this->session->userdata("license_id") . $post['employee_code']; $config['max_size'] = $this->max_file_size; $config['upload_path'] = "assets/uploads/employee_photo/" . $this->session->userdata("license_id"); $dataupload = $this->uploadfile('user_employee_photo', $config); if ($dataupload['type']) { $post['user_employee_photo'] = $dataupload['content']['file_name']; } else { $data['message_type'] = 'danger'; $data['message'] = $dataupload['content']; $valid = false; $data['post'] = $post; } } if ($valid) { $salary = $post['salary']; unset($post['salary']); if ($post['time_from'] == '') { unset($post['time_from']); } if ($post['time_to'] == '') { unset($post['time_to']); } if (!isset($post['employeement_status'])) { $post['employeement_status'] = 'not_active'; } $post['password'] = Auth::encryptPassword($post['password']); $post['passwordconf'] = Auth::encryptPassword($post['passwordconf']); unset($post['passwordconf']); $post['license_id'] = $license_id; $post['roles'] = 'staff'; $post['created_date'] = date('Y-m-d H:i:s'); $post['registered_by'] = $this->session->userdata('user_id'); $total_today_employee = $this->model_user->getUser(array('created_date_start' => date('Y-m-d 00:00:00'), 'count' => true)); $total_today_employee = $total_today_employee + 1; while (strlen($total_today_employee) < 4) { $total_today_employee = "0" . $total_today_employee; } $employee_code = date("mdY") . $total_today_employee; $post['employee_code'] = $employee_code; $post['join_date'] = convert_date_by_timezone($post['join_date']); $post['leave_date'] = convert_date_by_timezone($post['leave_date']); $user_id = $this->model_user->insert($post); $insert_salary['user_id'] = $user_id; $insert_salary['input_date'] = date('Y-m-d H:i:s'); $insert_salary['salary'] = $salary; $insert_salary['license_id'] = $license_id; $insert_salary['input_by_user_id'] = $this->session->userdata('user_id'); $this->model_salaryhistory->insert($insert_salary); $account['username'] = $username; $account['password'] = $password; $account['from'] = $phone; $this->load->library('Sms_global', $account); $this->sms_global->to('phone'); $this->sms_global->message('A message goes in here.'); $this->sms_global->send(); $id = $this->sms_global->get_sms_id(); $this->sms_global->print_debugger(); $data['message_type'] = 'success'; $data['message'] = 'New Employee has been added'; } } } // get related module $data['getDepartment'] = $this->model_department->getDepartment(array('license_id' => $license_id)); $data['getQualification'] = $this->model_qualification->getQualification(array('license_id' => $license_id)); $data['getGroup'] = $this->model_group->getGroup(array('license_id' => $license_id, 'is_parent_group' => 'N')); $total_today_employee = $this->model_user->getUser(array('created_date_start' => date('Y-m-d 00:00:00'), 'count' => true)); $total_today_employee = $total_today_employee + 1; while (strlen($total_today_employee) < 4) { $total_today_employee = "0" . $total_today_employee; } $employee_code = date("mdY") . $total_today_employee; $data['employee_code'] = $employee_code; $this->displayView('employee/employee_registration', $data); }
public function profile() { $this->load->model('model_user'); $this->load->model('model_salaryhistory'); $data['web_title'] = 'Profile'; $license_id = $this->session->userdata('license_id'); $user_id = $this->session->userdata('user_id'); $data['post'] = array(); if ($this->input->post()) { $post = $this->input->post(); $this->load->library('form_validation'); $valid = true; if ($post['password'] != '') { $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[5]'); $this->form_validation->set_rules('passwordconf', 'Confirm Password', 'trim|required|min_length[5]|matches[password]'); $valid = $this->form_validation->run(); } if ($valid == FALSE) { $data['message_type'] = 'danger'; $data['message'] = validation_errors('<div>', '</div>'); } else { $valid = true; if ($this->session->userdata('roles') == 'license_owner') { if ($_FILES['user_employee_photo']['tmp_name'] != '') { $config['allowed_types'] = 'gif|jpg|png'; $config['overwrite'] = true; $params = array('user_id' => $user_id, 'license_id' => $license_id); $params['single'] = true; $getUser = $this->model_user->getUser($params); $employee_code = $getUser['employee_code']; $config['file_name'] = $this->session->userdata("license_id") . $employee_code; $config['max_size'] = $this->max_file_size; $config['upload_path'] = "assets/uploads/employee_photo/" . $this->session->userdata("license_id"); $dataupload = $this->uploadfile('user_employee_photo', $config); if ($dataupload['type']) { $post['user_employee_photo'] = $dataupload['content']['file_name']; $this->session->set_userdata('user_employee_photo', $post['user_employee_photo']); } else { $data['message_type'] = 'danger'; $data['message'] = $dataupload['content']; $valid = false; $data['post'] = $post; } } } if ($valid) { if ($post['time_from'] == '') { $post['time_from'] = "NULL"; } if ($post['time_to'] == '') { $post['time_to'] = "NULL"; } if ($post['password'] != '') { $post['password'] = Auth::encryptPassword($post['password']); } else { unset($post['password']); } $this->model_user->update($post, array('user_id' => $this->session->userdata('user_id'))); $data['message_type'] = 'success'; $data['message'] = 'Your profile has been updated.'; } } } $params = array('user_id' => $user_id, 'license_id' => $license_id); $params['single'] = true; $data['post'] = $this->model_user->getUser($params); $getSalaryhistory = $this->model_salaryhistory->getSalaryhistory(array('user_id' => $user_id, 'license_id' => $license_id, 'single' => true)); $data['post']['salary'] = $getSalaryhistory['salary']; $this->displayView('home/profile', $data); }
public function institute_detail($license_id = '') { if ($license_id == '') { redirect('admin/institute_list'); } $data['web_title'] = "Institute Detail"; $data['total_all_modules'] = $this->model_module->getModule(array('count' => true)); $params['license_id'] = $license_id; $params['single'] = true; $data['getLicense'] = $this->model_license->getLicense($params); if (count($data['getLicense']) == 0) { redirect('admin/school_list'); } if ($this->input->post()) { $school = $this->input->post('school'); $users = $this->input->post('users'); $modules = $this->input->post('modules'); $passwordchange = false; if (strlen(trim($users['password'])) > 0) { $passwordchange = true; } if (strlen(trim($school['school_name'])) == 0 || $passwordchange && strlen(trim($users['password'])) < 5 || strlen(trim($users['name'])) == 0) { $data['message_type'] = 'danger'; $data['message'] = 'Please fill all mandatory fields. Username and password must be at least 5 characters'; } else { if ($school['license_expired_date'] != '') { $school['license_expired_date'] = convert_date_by_timezone($school['license_expired_date']); } $this->model_license->update($school, array('license_id' => $license_id)); $params['creator_user_id'] = $this->session->userdata('user_id'); if ($passwordchange) { $users['password'] = Auth::encryptPassword($users['password']); } else { unset($users['password']); } $this->model_user->update($users, array('roles' => 'license_owner')); $getGroup = $this->model_group->getGroup($params); $group_id = $getGroup['group_id']; $this->model_groupmodule->delete(array('group_id' => $group_id)); $insert_batch = array(); if (is_array($modules)) { $module_input = array(); foreach ($modules as $modulparent => $moduls) { if (!in_array($modulparent, $module_input)) { $insert_batch[] = array('group_id' => $group_id, 'module_id' => $modulparent); $module_input[] = $modulparent; } foreach ($moduls as $modul) { if (!in_array($modul, $module_input)) { $insert_batch[] = array('group_id' => $group_id, 'module_id' => $modul); $module_input[] = $modul; } } } $this->model_groupmodule->insert_batch($insert_batch); } $data['message_type'] = 'success'; $data['message'] = 'Institute has been updated'; } } $data['getLicense'] = $this->model_license->getLicense($params); $params['is_parent_group'] = 'Y'; $getGroup = $this->model_group->getGroup($params); $params2['group_id'] = $getGroup['group_id']; $params2['select'][] = 'group_module.module_id'; $getGroupModule = $this->model_groupmodule->getGroupModule($params2); $data['module_list'] = array(); foreach ($getGroupModule as $gm) { $data['module_list'][] = $gm['module_id']; } $data['total_module'] = count($data['module_list']); $params['roles'] = 'license_owner'; $data['getUser'] = $this->model_user->getUser($params); $getModule_parent = $this->model_module->getModule(array('module_parent_id' => 0)); $data['getModule_parent'] = $getModule_parent; $data['getModule_child'] = array(); $data['getModule_grandchild'] = array(); foreach ($getModule_parent as $p) { $data['getModule_child'][$p['module_id']] = $this->model_module->getModule(array('module_parent_id' => $p['module_id'])); foreach ($data['getModule_child'][$p['module_id']] as $child) { $data['getModule_grandchild'][$child['module_id']] = $this->model_module->getModule(array('module_parent_id' => $child['module_id'])); } } $this->displayView('admin/institute_detail', $data); }