| Server IP : 103.234.187.230 / Your IP : 216.73.216.216 Web Server : Apache System : Linux lserver42043-ind.megavelocity.net 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64 User : apache ( 48) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/html/adeetie_hellogtx/application/modules/auth/controllers/ |
Upload File : |
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Auth extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->database();
$this->load->library(array('ion_auth','form_validation'));
$this->load->helper(array('url','language'));
$this->form_validation->set_error_delimiters($this->config->item('error_start_delimiter', 'ion_auth'), $this->config->item('error_end_delimiter', 'ion_auth'));
$this->lang->load('auth');
$this->load->model('home/home_model');
$this->data['menu']=$this->db->query('SELECT A.menu_name,A.id,A.menu_type,A.menu_external_link,A.menu_order,group_concat(B.page_slug ) as page_slug, group_concat(B.page_name ORDER BY FIND_IN_SET(B.id,A.menu_related_pages)) as page_name FROM '.TBL_MENU.' A left join '.TBL_PAGES.' B on FIND_IN_SET(B.id,A.menu_related_pages) WHERE A.status=1 AND (( A.menu_type=3 ) OR ( A.menu_type!=3 AND B.status=1 ) ) group by A.menu_name ORDER BY A.menu_order ASC ' )->result();
$query = $this->db->select('label, value')->get(TBL_GLOBAL)->result_array();
foreach ($query as $row)
{
$details[$row['label']] = $row['value'];
}
$this->data['social_urls'] = $details;
// Counters
$this->data['counters'] = $details;
// footer news
$this->data['footer_news']=$this->home_model->footer_news();
// get footer gallery
$this->data['footer_gallery']=$this->home_model->footer_gallery();
}
// redirect if needed, otherwise display the user list
// function emailtest() {
// $success= emailCheck('Mail of Geostat', '<html>Kya Bakwaas Hai</html>', 'apandey0127@gmail.com', 'pallavi@geostat.in');
// }
public function index()
{
if (!$this->ion_auth->logged_in())
{
// redirect them to the login page
redirect('auth/login', 'refresh');
}
elseif (!$this->ion_auth->is_admin()) // remove this elseif if you want to enable this for non-admins
{
// redirect them to the home page because they must be an administrator to view this
return show_error('You must be an administrator to view this page.');
}
else
{
// set the flash data error message if there is one
$this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');
//list the users
$this->data['users'] = $this->ion_auth->users()->result();
foreach ($this->data['users'] as $k => $user)
{
$this->data['users'][$k]->groups = $this->ion_auth->get_users_groups($user->id)->result();
}
$this->data['bread_crumb'] = render_bread_crumb(array('dashboard'=>'Dashboard','users'=>'All Users'));
$this->data['page']='index';
$this->_render_page(get_template(), $this->data);
}
}
// log the user in
public function login() {
$this->data['title'] = $this->lang->line('login_heading');
//validate form input
$this->form_validation->set_rules('identity', str_replace(':', '', $this->lang->line('login_identity_label')), 'required');
$this->form_validation->set_rules('password', str_replace(':', '', $this->lang->line('login_password_label')), 'required');
$this->form_validation->set_rules('usertypes', str_replace(':', '', $this->lang->line('login_usertypes_label')), 'required');
if ($this->form_validation->run() == true) {
$captcha = $this->input->post('g-recaptcha-response');
$remoteaddr = verify_captcha($captcha, $_SERVER['REMOTE_ADDR']);
// if(empty(json_decode($remoteaddr)) || json_decode($remoteaddr)->success !=1) {
// redirect('auth/login', 'refresh');
// return;
// }
$remember = (bool) $this->input->post('remember');
if ($this->ion_auth->login($this->input->post('identity'), $this->input->post('password'), $remember)) {
$this->session->set_flashdata('message', $this->ion_auth->messages());
redirect('dashboard', 'refresh');
return;
} else {
$this->session->set_flashdata('message', $this->ion_auth->errors());
redirect('auth/login', 'refresh'); // use redirects instead of loading views for compatibility with MY_Controller libraries
return;
}
} else {
$this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');
$this->data['identity'] = array('name' => 'identity',
'id' => 'identity',
'type' => 'text',
'value' => $this->form_validation->set_value('identity'),
'class' =>'form-control',
'placeholder'=>'Username',
);
$this->data['password'] = array('name' => 'password',
'id' => 'password',
'type' => 'password',
'class' =>'form-control',
'placeholder'=>'Password',
);
$groups=$this->ion_auth->groups()->result_array();
$this->data['groups'] = $groups;
$this->_render_page('auth/login', $this->data);
}
}
// log the user out
public function logout()
{
$this->data['title'] = "Logout";
$logout = $this->ion_auth->logout();
$this->session->sess_destroy();
$this->session->set_flashdata('message', $this->ion_auth->messages());
redirect('auth/login', 'refresh');
}
// change password
public function change_password()
{
$this->form_validation->set_rules('old', $this->lang->line('change_password_validation_old_password_label'), 'required');
$this->form_validation->set_rules('new', $this->lang->line('change_password_validation_new_password_label'), 'required|min_length[' . $this->config->item('min_password_length', 'ion_auth') . ']|max_length[' . $this->config->item('max_password_length', 'ion_auth') . ']|matches[new_confirm]');
$this->form_validation->set_rules('new_confirm', $this->lang->line('change_password_validation_new_password_confirm_label'), 'required');
if (!$this->ion_auth->logged_in())
{
redirect('auth/login', 'refresh');
}
$user = $this->ion_auth->user()->row();
if ($this->form_validation->run() == false)
{
// display the form
// set the flash data error message if there is one
$this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');
$this->data['min_password_length'] = $this->config->item('min_password_length', 'ion_auth');
$this->data['old_password'] = array(
'name' => 'old',
'id' => 'old',
'type' => 'password',
'class'=> 'form-control',
);
$this->data['new_password'] = array(
'name' => 'new',
'id' => 'new',
'type' => 'password',
'pattern' => '^.{'.$this->data['min_password_length'].'}.*$',
'class'=> 'form-control',
);
$this->data['new_password_confirm'] = array(
'name' => 'new_confirm',
'id' => 'new_confirm',
'type' => 'password',
'class'=> 'form-control',
'pattern' => '^.{'.$this->data['min_password_length'].'}.*$',
);
$this->data['user_id'] = array(
'name' => 'user_id',
'id' => 'user_id',
'type' => 'hidden',
'value' => $user->id,
);
$this->data['page']='change_password';
// render
$this->_render_page(get_template(), $this->data);
}
else
{
$identity = $this->session->userdata('identity');
$change = $this->ion_auth->change_password($identity, $this->input->post('old'), $this->input->post('new'));
if ($change)
{
//if the password was successfully changed
$this->session->set_flashdata('message', $this->ion_auth->messages());
$this->logout();
}
else
{
$this->session->set_flashdata('message', $this->ion_auth->errors());
redirect('auth/change_password', 'refresh');
}
}
}
// forgot password
public function forgot_password() {
// setting validation rules by checking whether identity is username or email
if($this->config->item('identity', 'ion_auth') != 'email' ) {
$this->form_validation->set_rules('identity', $this->lang->line('forgot_password_identity_label'), 'required');
} else {
$this->form_validation->set_rules('identity', $this->lang->line('forgot_password_validation_email_label'), 'required|valid_email');
}
if ($this->form_validation->run() == false) {
$this->data['type'] = $this->config->item('identity','ion_auth');
// setup the input
$this->data['identity'] = array('name' => 'identity',
'id' => 'identity',
'type' => 'text',
'value' => $this->form_validation->set_value('identity'),
'class' =>'form-control',
'placeholder'=>'Email id',
);
if ( $this->config->item('identity', 'ion_auth') != 'email' ){
$this->data['identity_label'] = $this->lang->line('forgot_password_identity_label');
} else {
$this->data['identity_label'] = $this->lang->line('forgot_password_email_identity_label');
}
// set any errors and display the form
$this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');
$this->_render_page('auth/forgot_password', $this->data);
} else {
$identity_column = $this->config->item('identity','ion_auth');
$identity = $this->ion_auth->where($identity_column, $this->input->post('identity'))->users()->row();
if(empty($identity)) {
if($this->config->item('identity', 'ion_auth') != 'email') {
$this->ion_auth->set_error('forgot_password_identity_not_found');
} else {
$this->ion_auth->set_error('forgot_password_email_not_found');
}
$this->session->set_flashdata('message', $this->ion_auth->errors());
redirect("auth/forgot_password", 'refresh');
}
// run the forgotten password method to email an activation code to the user
$forgotten = $this->ion_auth->forgotten_password($identity->{$this->config->item('identity', 'ion_auth')});
if ($forgotten) {
// if there were no errors
$this->session->set_flashdata('message', $this->ion_auth->messages());
redirect("auth/login", 'refresh'); //we should display a confirmation page here instead of the login page
} else {
$this->session->set_flashdata('message', $this->ion_auth->errors());
redirect("auth/forgot_password", 'refresh');
}
}
}
// reset password - final step for forgotten password
public function reset_password($code = NULL)
{
if (!$code)
{
show_404();
}
$user = $this->ion_auth->forgotten_password_check($code);
if ($user)
{
// if the code is valid then display the password reset form
$this->form_validation->set_rules('new', $this->lang->line('reset_password_validation_new_password_label'), 'required|min_length[' . $this->config->item('min_password_length', 'ion_auth') . ']|max_length[' . $this->config->item('max_password_length', 'ion_auth') . ']|matches[new_confirm]');
$this->form_validation->set_rules('new_confirm', $this->lang->line('reset_password_validation_new_password_confirm_label'), 'required');
if ($this->form_validation->run() == false)
{
// display the form
// set the flash data error message if there is one
$this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');
$this->data['min_password_length'] = $this->config->item('min_password_length', 'ion_auth');
$this->data['new_password'] = array(
'name' => 'new',
'id' => 'new',
'type' => 'password',
'pattern' => '^.{'.$this->data['min_password_length'].'}.*$',
);
$this->data['new_password_confirm'] = array(
'name' => 'new_confirm',
'id' => 'new_confirm',
'type' => 'password',
'pattern' => '^.{'.$this->data['min_password_length'].'}.*$',
);
$this->data['user_id'] = array(
'name' => 'user_id',
'id' => 'user_id',
'type' => 'hidden',
'value' => $user->id,
);
$this->data['csrf'] = $this->_get_csrf_nonce();
$this->data['code'] = $code;
// render
$this->_render_page('auth/reset_password', $this->data);
}
else
{
// do we have a valid request?
if ($this->_valid_csrf_nonce() === FALSE || $user->id != $this->input->post('user_id'))
{
// something fishy might be up
$this->ion_auth->clear_forgotten_password_code($code);
show_error($this->lang->line('error_csrf'));
}
else
{
// finally change the password
$identity = $user->{$this->config->item('identity', 'ion_auth')};
$change = $this->ion_auth->reset_password($identity, $this->input->post('new'));
if ($change)
{
// if the password was successfully changed
$this->session->set_flashdata('message', $this->ion_auth->messages());
redirect("auth/login", 'refresh');
}
else
{
$this->session->set_flashdata('message', $this->ion_auth->errors());
redirect('auth/reset_password/' . $code, 'refresh');
}
}
}
}
else
{
// if the code is invalid then send them back to the forgot password page
$this->session->set_flashdata('message', $this->ion_auth->errors());
redirect("auth/forgot_password", 'refresh');
}
}
// activate the user
public function activate($id, $code=false)
{
if ($code !== false)
{
$activation = $this->ion_auth->activate($id, $code);
}
else if ($this->ion_auth->is_admin())
{
$activation = $this->ion_auth->activate($id);
}
if ($activation)
{
// redirect them to the auth page
$this->session->set_flashdata('message', $this->ion_auth->messages());
redirect("auth/login", 'refresh');
}
else
{
// redirect them to the forgot password page
$this->session->set_flashdata('message', $this->ion_auth->errors());
redirect("auth/forgot_password", 'refresh');
}
}
// deactivate the user
public function deactivate($id = NULL)
{
if (!$this->ion_auth->logged_in() || !$this->ion_auth->is_admin())
{
// redirect them to the home page because they must be an administrator to view this
return show_error('You must be an administrator to view this page.');
}
$id = (int) $id;
$this->load->library('form_validation');
$this->form_validation->set_rules('confirm', $this->lang->line('deactivate_validation_confirm_label'), 'required');
$this->form_validation->set_rules('id', $this->lang->line('deactivate_validation_user_id_label'), 'required|alpha_numeric');
if ($this->form_validation->run() == FALSE)
{
// insert csrf check
$this->data['csrf'] = $this->_get_csrf_nonce();
$this->data['user'] = $this->ion_auth->user($id)->row();
$this->data['bread_crumb'] = render_bread_crumb(array('dashboard'=>'Dashboard','deactivate_user'=>'Deactivate User'));
$this->data['page']='deactivate_user';
$this->_render_page(get_template(), $this->data);
}
else
{
// do we really want to deactivate?
if ($this->input->post('confirm') == 'yes')
{
// do we have a valid request?
if ($this->_valid_csrf_nonce() === FALSE || $id != $this->input->post('id'))
{
show_error($this->lang->line('error_csrf'));
}
// do we have the right userlevel?
if ($this->ion_auth->logged_in() && $this->ion_auth->is_admin())
{
$this->ion_auth->deactivate($id);
}
}
// redirect them back to the auth page
redirect('auth', 'refresh');
}
}
// create a new user
public function create_user()
{
$this->data['title'] = $this->lang->line('create_user_heading');
if (!$this->ion_auth->logged_in() || !$this->ion_auth->is_admin())
{
//redirect('auth', 'refresh');
}
$tables = $this->config->item('tables','ion_auth');
$identity_column = $this->config->item('identity','ion_auth');
$this->data['identity_column'] = $identity_column;
// validate form input
$this->form_validation->set_rules('first_name', $this->lang->line('create_user_validation_fname_label'), 'required');
$this->form_validation->set_rules('last_name', $this->lang->line('create_user_validation_lname_label'), 'required');
if($identity_column!=='email')
{
$this->form_validation->set_rules('identity',$this->lang->line('create_user_validation_identity_label'),'required|is_unique['.$tables['users'].'.'.$identity_column.']');
$this->form_validation->set_rules('email', $this->lang->line('create_user_validation_email_label'), 'required|valid_email');
}
else
{
$this->form_validation->set_rules('email', $this->lang->line('create_user_validation_email_label'), 'required|valid_email|is_unique[' . $tables['users'] . '.email]');
}
//$this->form_validation->set_rules('phone', $this->lang->line('create_user_validation_phone_label'), 'trim');
$this->form_validation->set_rules('company', $this->lang->line('create_user_validation_company_label'), 'trim');
$this->form_validation->set_rules('password', $this->lang->line('create_user_validation_password_label'), 'required|min_length[' . $this->config->item('min_password_length', 'ion_auth') . ']|max_length[' . $this->config->item('max_password_length', 'ion_auth') . ']|matches[password_confirm]');
$this->form_validation->set_rules('password_confirm', $this->lang->line('create_user_validation_password_confirm_label'), 'required');
if ($this->form_validation->run() == true)
{
$email = strtolower($this->input->post('email'));
$identity = ($identity_column==='email') ? $email : $this->input->post('identity');
$password = $this->input->post('password');
$additional_data = array(
'first_name' => $this->input->post('first_name'),
'last_name' => $this->input->post('last_name'),
'company' => $this->input->post('company'),
'company_phone' => $this->input->post('phone'),
);
}
if ($this->form_validation->run() == true && $this->ion_auth->register($identity, $password, $email, $additional_data))
{
// check to see if we are creating the user
// redirect them back to the admin page
$this->session->set_flashdata('message', $this->ion_auth->messages());
redirect("auth", 'refresh');
}
else
{
// display the create user form
// set the flash data error message if there is one
$this->data['message'] = (validation_errors() ? validation_errors() : ($this->ion_auth->errors() ? $this->ion_auth->errors() : $this->session->flashdata('message')));
$this->data['first_name'] = array(
'name' => 'first_name',
'id' => 'first_name',
'type' => 'text',
'value' => $this->form_validation->set_value('first_name'),
'class' =>'form-control',
'placeholder'=>'First Name',
);
$this->data['last_name'] = array(
'name' => 'last_name',
'id' => 'last_name',
'type' => 'text',
'value' => $this->form_validation->set_value('last_name'),
'class' =>'form-control',
'placeholder'=>'Last Name',
);
$this->data['identity'] = array(
'name' => 'identity',
'id' => 'identity',
'type' => 'text',
'value' => $this->form_validation->set_value('identity'),
'class' =>'form-control',
);
$this->data['email'] = array(
'name' => 'email',
'id' => 'email',
'type' => 'text',
'value' => $this->form_validation->set_value('email'),
'class' =>'form-control',
'placeholder'=>'Email',
);
$this->data['company'] = array(
'name' => 'company',
'id' => 'company',
'type' => 'text',
'value' => $this->form_validation->set_value('company'),
'class' =>'form-control',
'placeholder'=>'Company Name',
);
/* $this->data['phone'] = array(
'name' => 'phone',
'id' => 'phone',
'type' => 'text',
'value' => $this->form_validation->set_value('phone'),
'class' =>'form-control',
'placeholder'=>'Phone Number',
); */
$this->data['password'] = array(
'name' => 'password',
'id' => 'password',
'type' => 'password',
'value' => $this->form_validation->set_value('password'),
'class' =>'form-control',
'placeholder'=>'Password',
);
$this->data['password_confirm'] = array(
'name' => 'password_confirm',
'id' => 'password_confirm',
'type' => 'password',
'value' => $this->form_validation->set_value('password_confirm'),
'class' =>'form-control',
'placeholder'=>'Confirm Password',
);
$this->data['bread_crumb'] = render_bread_crumb(array('dashboard'=>'Dashboard','create_user'=>'Create User'));
$this->data['page']='create_user';
$this->_render_page(get_template(), $this->data);
}
}
// edit a user
public function edit_user($id)
{
$this->data['title'] = $this->lang->line('edit_user_heading');
if (!$this->ion_auth->logged_in() || (!$this->ion_auth->is_admin() && !($this->ion_auth->user()->row()->id == $id)))
{
redirect('auth', 'refresh');
}
$user = $this->ion_auth->user($id)->row();
$groups=$this->ion_auth->groups()->result_array();
$currentGroups = $this->ion_auth->get_users_groups($id)->result();
// validate form input
$this->form_validation->set_rules('first_name', $this->lang->line('edit_user_validation_fname_label'), 'required');
$this->form_validation->set_rules('last_name', $this->lang->line('edit_user_validation_lname_label'), 'required');
//$this->form_validation->set_rules('phone', $this->lang->line('edit_user_validation_phone_label'), 'required');
$this->form_validation->set_rules('company', $this->lang->line('edit_user_validation_company_label'), 'required');
if (isset($_POST) && !empty($_POST))
{
// do we have a valid request?
if ($this->_valid_csrf_nonce() === FALSE || $id != $this->input->post('id'))
{
show_error($this->lang->line('error_csrf'));
}
// update the password if it was posted
if ($this->input->post('password'))
{
$this->form_validation->set_rules('password', $this->lang->line('edit_user_validation_password_label'), 'required|min_length[' . $this->config->item('min_password_length', 'ion_auth') . ']|max_length[' . $this->config->item('max_password_length', 'ion_auth') . ']|matches[password_confirm]');
$this->form_validation->set_rules('password_confirm', $this->lang->line('edit_user_validation_password_confirm_label'), 'required');
}
if ($this->form_validation->run() === TRUE)
{
$data = array(
'first_name' => $this->input->post('first_name'),
'last_name' => $this->input->post('last_name'),
'company' => $this->input->post('company'),
'phone' => $this->input->post('phone'),
);
// update the password if it was posted
if ($this->input->post('password'))
{
$data['password'] = $this->input->post('password');
}
// Only allow updating groups if user is admin
if ($this->ion_auth->is_admin())
{
//Update the groups user belongs to
$groupData = $this->input->post('u_role');
if (isset($groupData) && !empty($groupData)) {
$this->ion_auth->remove_from_group('', $id);
$this->ion_auth->add_to_group($groupData, $id);
// foreach ($groupData as $grp) {
// $this->ion_auth->add_to_group($grp, $id);
// }
}
}
// check to see if we are updating the user
if($this->ion_auth->update($user->id, $data))
{
// redirect them back to the admin page if admin, or to the base url if non admin
$this->session->set_flashdata('message', $this->ion_auth->messages() );
if ($this->ion_auth->is_admin())
{
redirect('auth', 'refresh');
}
else
{
redirect('/', 'refresh');
}
}
else
{
// redirect them back to the admin page if admin, or to the base url if non admin
$this->session->set_flashdata('message', $this->ion_auth->errors() );
if ($this->ion_auth->is_admin())
{
redirect('auth', 'refresh');
}
else
{
redirect('/', 'refresh');
}
}
}
}
// display the edit user form
$this->data['csrf'] = $this->_get_csrf_nonce();
// set the flash data error message if there is one
$this->data['message'] = (validation_errors() ? validation_errors() : ($this->ion_auth->errors() ? $this->ion_auth->errors() : $this->session->flashdata('message')));
// pass the user to the view
$this->data['user'] = $user;
$this->data['groups'] = $groups;
$this->data['currentGroups'] = $currentGroups;
$this->data['first_name'] = array(
'name' => 'first_name',
'id' => 'first_name',
'type' => 'text',
'value' => $this->form_validation->set_value('first_name', $user->first_name),
'class'=>'form-control',
);
$this->data['last_name'] = array(
'name' => 'last_name',
'id' => 'last_name',
'type' => 'text',
'value' => $this->form_validation->set_value('last_name', $user->last_name),
'class'=>'form-control',
);
$this->data['company'] = array(
'name' => 'company',
'id' => 'company',
'type' => 'text',
'value' => $this->form_validation->set_value('company', $user->company),
'class'=>'form-control',
);
$this->data['phone'] = array(
'name' => 'phone',
'id' => 'phone',
'type' => 'text',
'value' => $this->form_validation->set_value('phone', $user->phone),
'class'=>'form-control',
);
$this->data['password'] = array(
'name' => 'password',
'id' => 'password',
'type' => 'password',
'class'=>'form-control',
);
$this->data['password_confirm'] = array(
'name' => 'password_confirm',
'id' => 'password_confirm',
'type' => 'password',
'class'=>'form-control',
);
$this->data['bread_crumb'] = render_bread_crumb(array('dashboard'=>'Dashboard','edit-user'=>'Edit User'));
$this->data['page']='edit_user';
$this->_render_page(get_template(), $this->data);
}
// create a new group
public function create_group()
{
$this->data['title'] = $this->lang->line('create_group_title');
if (!$this->ion_auth->logged_in() || !$this->ion_auth->is_admin())
{
redirect('auth', 'refresh');
}
// validate form input
$this->form_validation->set_rules('group_name', $this->lang->line('create_group_validation_name_label'), 'required|alpha_dash');
if ($this->form_validation->run() == TRUE)
{
$new_group_id = $this->ion_auth->create_group($this->input->post('group_name'), $this->input->post('description'));
if($new_group_id)
{
// check to see if we are creating the group
// redirect them back to the admin page
$this->session->set_flashdata('message', $this->ion_auth->messages());
redirect("auth", 'refresh');
}
}
else
{
// display the create group form
// set the flash data error message if there is one
$this->data['message'] = (validation_errors() ? validation_errors() : ($this->ion_auth->errors() ? $this->ion_auth->errors() : $this->session->flashdata('message')));
$this->data['group_name'] = array(
'name' => 'group_name',
'id' => 'group_name',
'type' => 'text',
'value' => $this->form_validation->set_value('group_name'),
'class' =>'form-control',
);
$this->data['description'] = array(
'name' => 'description',
'id' => 'description',
'type' => 'text',
'value' => $this->form_validation->set_value('description'),
'class' =>'form-control',
);
$this->data['bread_crumb'] = render_bread_crumb(array('dashboard'=>'Dashboard','create-group'=>'Create Group'));
$this->data['page']='create_group';
$this->_render_page(get_template(), $this->data);
}
}
// edit a group
public function edit_group($id)
{
// bail if no group id given
if(!$id || empty($id))
{
redirect('auth', 'refresh');
}
$this->data['title'] = $this->lang->line('edit_group_title');
if (!$this->ion_auth->logged_in() || !$this->ion_auth->is_admin())
{
redirect('auth', 'refresh');
}
$group = $this->ion_auth->group($id)->row();
// validate form input
$this->form_validation->set_rules('group_name', $this->lang->line('edit_group_validation_name_label'), 'required|alpha_dash');
if (isset($_POST) && !empty($_POST))
{
if ($this->form_validation->run() === TRUE)
{
$group_update = $this->ion_auth->update_group($id, $_POST['group_name'], $_POST['group_description']);
if($group_update)
{
$this->session->set_flashdata('message', $this->lang->line('edit_group_saved'));
}
else
{
$this->session->set_flashdata('message', $this->ion_auth->errors());
}
redirect("auth", 'refresh');
}
}
// set the flash data error message if there is one
$this->data['message'] = (validation_errors() ? validation_errors() : ($this->ion_auth->errors() ? $this->ion_auth->errors() : $this->session->flashdata('message')));
// pass the user to the view
$this->data['group'] = $group;
$readonly = $this->config->item('admin_group', 'ion_auth') === $group->name ? 'readonly' : '';
$this->data['group_name'] = array(
'name' => 'group_name',
'id' => 'group_name',
'type' => 'text',
'value' => $this->form_validation->set_value('group_name', $group->name),
$readonly => $readonly,
'class'=>'form-control',
);
$this->data['group_description'] = array(
'name' => 'group_description',
'id' => 'group_description',
'type' => 'text',
'value' => $this->form_validation->set_value('group_description', $group->description),
'class' =>'form-control',
);
$this->data['bread_crumb'] = render_bread_crumb(array('dashboard'=>'Dashboard','edit-group'=>'Edit Group'));
$this->data['page']='edit_group';
$this->_render_page(get_template(), $this->data);
}
public function _get_csrf_nonce()
{
$this->load->helper('string');
$key = random_string('alnum', 8);
$value = random_string('alnum', 20);
$this->session->set_flashdata('csrfkey', $key);
$this->session->set_flashdata('csrfvalue', $value);
return array($key => $value);
}
public function _valid_csrf_nonce()
{
$csrfkey = $this->input->post($this->session->flashdata('csrfkey'));
if ($csrfkey && $csrfkey == $this->session->flashdata('csrfvalue'))
{
return TRUE;
}
else
{
return FALSE;
}
}
public function _render_page($view, $data=null, $returnhtml=false)//I think this makes more sense
{
$this->viewdata = (empty($data)) ? $this->data: $data;
$view_html = $this->load->view($view, $this->viewdata, $returnhtml);
if ($returnhtml) return $view_html;//This will return html on 3rd argument being true
}
public function nodalregister(){
if (!$this->ion_auth->logged_in() )
{
redirect('auth', 'refresh');
}
$user = $this->ion_auth->user($this->ion_auth->user()->row()->id)->row();
$this->form_validation->set_rules('nodal_email', $this->lang->line('create_user_validation_email_label'), 'required|valid_email');
$this->form_validation->set_rules('nodal_phone', $this->lang->line('create_user_validation_phone_label'), 'required');
$this->form_validation->set_rules('nodal_name', $this->lang->line('create_user_validation_company_label'), 'required');
$this->form_validation->set_rules('nodal_designation', $this->lang->line('create_user_validation_company_label'), 'required');
if ($this->form_validation->run() == true)
{
$data = array(
'nodal_officer_phone' => $this->input->post('nodal_phone'), // Nodal officer Mobile Number
'nodal_officer_email' => $this->input->post('nodal_email'), // Email ID of Authorized Representative
'nodal_officer_name' => $this->input->post('nodal_name'),
'nodal_officer_designation' => $this->input->post('nodal_designation'),
);
if($this->ion_auth->update($user->id, $data))
{
$this->session->set_flashdata('message', $this->ion_auth->messages() );
if ($this->ion_auth->is_admin())
{
redirect('auth', 'refresh');
}
else
{
redirect('/willingness-form-part-b', 'refresh');
}
}
else
{
$this->session->set_flashdata('message', $this->ion_auth->errors() );
if ($this->ion_auth->is_admin())
{
redirect('auth', 'refresh');
}
else
{
redirect('/', 'refresh');
}
}
}else{
$this->data['message'] = (validation_errors() ? validation_errors() : ($this->ion_auth->errors() ? $this->ion_auth->errors() : $this->session->flashdata('message')));
redirect('/willingness-form-part-a', 'refresh');
}
}
public function register() {
$this->data['title'] = $this->lang->line('create_user_heading');
$this->data['sector'] = $this->home_model->sector();
$this->data['nature_project'] = $this->home_model->natureofproject();
$this->data['states'] = $this->home_model->getStates();
$this->data['districts'] = $this->home_model->getDistricts();
//$this->data['nature_project'] = $this->home_model->getDistricts();
//$this->session->set_flashdata('message', $this->ion_auth->messages());
if (!$this->ion_auth->logged_in() || !$this->ion_auth->is_admin())
{
//redirect('auth', 'refresh');
}
$tables = $this->config->item('tables','ion_auth');
$identity_column = $this->config->item('identity','ion_auth');
$this->data['identity_column'] = $identity_column;
$this->form_validation->set_rules('mec', 'Minimum Eligibility Criteria', 'required');
if($identity_column!=='email'){
$this->form_validation->set_rules('email', $this->lang->line('create_user_validation_email_label'), 'required|valid_email|is_unique[' . $tables['users'] . '.email]');
//$this->form_validation->set_rules('email', $this->lang->line('create_user_validation_email_label'), 'required|valid_email');
}
else
{
$this->form_validation->set_rules('email', $this->lang->line('create_user_validation_email_label'), 'required|valid_email|is_unique[' . $tables['users'] . '.email]');
}
//$this->form_validation->set_rules('phone', $this->lang->line('create_user_validation_phone_label'), 'trim');
$this->form_validation->set_rules('company', $this->lang->line('create_user_validation_company_label'), 'trim');
// $this->form_validation->set_rules('password', $this->lang->line('create_user_validation_password_label'), 'required|min_length[' . $this->config->item('min_password_length', 'ion_auth') . ']|max_length[' . $this->config->item('max_password_length', 'ion_auth') . ']|matches[password_confirm]');
// $this->form_validation->set_rules('password_confirm', $this->lang->line('create_user_validation_password_confirm_label'), 'required');
if ($this->form_validation->run() == true){
$captcha = $this->input->post('g-recaptcha-response');
$remoteaddr = verify_captcha($captcha, $_SERVER['REMOTE_ADDR']);
// if(empty(json_decode($remoteaddr)) || json_decode($remoteaddr)->success !=1) {
// $this->session->set_flashdata('message', 'Invalid Captcha');
// redirect('auth/register', 'refresh');
// return;
// }
// exit();
$email = strtolower($this->input->post('email'));
$identity = ($identity_column==='email') ? $email : $this->input->post('identity');
$password = password_generate(7);
//$identity = "BEE".substr($this->input->post('name'),0,2).substr($this->input->post('company'),0,2);
//echo $username."<br>";
//$uniqueUser = $this->db->select('username')->from('users')->where('username= ', $username)->get()->result();
$additional_data = array(
'first_name' => $this->input->post('name'), // Name of Authorized Representative
'last_name' => $this->input->post('last_name'),
'company' => $this->input->post('company'), // Name of the company
'company_phone' => $this->input->post('company_phone'), // Mobile Number of Authorized Representative
'username' => $identity,
'designation' => $this->input->post('designation'), // company designation
'type_industry' => $this->input->post('sectorid'),
'brief_info' => $this->input->post('brief_info'),
'nature_of_project' => $this->input->post('nature_project'),
);
}
//if ($this->form_validation->run() == true && $this->ion_auth->register($identity, $password, $email, $additional_data))
if ($this->form_validation->run() == true ){
$this->ion_auth->register($identity, $password, $email, $additional_data);
$this->load->model('home/home_model');
$id=$activation='';
$useremail=$this->input->post('email');
$query = $this->db->select('id,username,email,activation_code')->from('users')->where('email= ', $useremail)->get()->result();
foreach ($query as $row)
{
$id = $row->id;
$activation = $row->activation_code;
}
// check to see if we are creating the user
// redirect them back to the admin page
$this->session->set_flashdata('message', $this->ion_auth->messages());
$subject="Registration Details";
$viewdata = $additional_data;
$viewdata['identity'] = $identity;
$viewdata['password'] = $password;
$viewdata['email'] = $email;
$viewdata['company_state_name'] = $this->input->post('company_state_name');
$viewdata['sector_name'] = $this->input->post('sector_name');
$viewdata['nature_project_name'] = $this->input->post('nature_project_name');
$viewdata['company_state_name'] = $this->input->post('company_state_name');
$viewdata['company_dist_name'] = $this->input->post('company_dist_name');
$viewdata['user_activate'] = anchor('auth/activate/'. $id .'/'. $activation, 'Activate','style="text-decoration: none; text-transform: capitalize; display:inline-block;cursor: pointer; line-height: 1.1em; letter-spacing: 0; padding: 12px; background: #33a95b; color: #FFFFFF; border-radius: 5px; text-align: center; font-size: 16px; font-weight: bold; box-sizing: border-box;"');
$message = $this->load->view("email/user_activate", $viewdata, true);
$this->session->set_flashdata('message', 'Your details submit successfully !');
$to=$this->input->post('email');
$cc = $this->input->post('nodal_officer_email') ?? '';
$success= emailCheck($subject, $message, $to, $cc);
$message2 = $this->load->view("email/user_register_detail_fc", $viewdata, true);
$success= emailCheck($subject, $message2, FC_EMAIL_LIST, '');
$this->session->set_flashdata('message', 'Your details submit successfully! <br>Login credentials have been sent to your email.');
//redirect("auth", 'refresh');
//echo $id."this is id of the user";
//exit;
redirect(base_url().'auth/register');
}
else
{
//echo "elese";exit;
// display the create user form
// set the flash data error message if there is one
$this->data['message'] = (validation_errors() ? validation_errors() : ($this->ion_auth->errors() ? $this->ion_auth->errors() : $this->session->flashdata('message')));
$this->data['name'] = array(
'name' => 'name',
'id' => 'name',
'type' => 'text',
'value' => $this->form_validation->set_value('name'),
'class' =>'form-control',
'placeholder'=>'Authorized Name',
);
$this->data['first_name'] = array(
'name' => 'first_name',
'id' => 'first_name',
'type' => 'text',
'value' => $this->form_validation->set_value('first_name'),
'class' =>'form-control',
'placeholder'=>'First Name',
);
$this->data['last_name'] = array(
'name' => 'last_name',
'id' => 'last_name',
'type' => 'text',
'value' => $this->form_validation->set_value('last_name'),
'class' =>'form-control',
'placeholder'=>'Last Name',
);
$this->data['identity'] = array(
'name' => 'identity',
'id' => 'identity',
'type' => 'text',
'value' => $this->form_validation->set_value('identity'),
'class' =>'form-control',
);
$this->data['email'] = array(
'name' => 'email',
'id' => 'email',
'type' => 'text',
'value' => $this->form_validation->set_value('email'),
'class' =>'form-control',
'placeholder'=>'Email',
);
$this->data['company'] = array(
'name' => 'company',
'id' => 'company',
'type' => 'text',
'value' => $this->form_validation->set_value('company'),
'class' =>'form-control',
'placeholder'=>'Company Name',
);
$this->data['type_industry'] = array(
'name' => 'type_industry',
'id' => 'type_industry',
'type' => 'text',
'value' => $this->form_validation->set_value('type_industry'),
'class' =>'form-control',
'placeholder'=>'Type of Industry',
);
$this->data['company_phone'] = array(
'name' => 'company_phone',
'id' => 'company_phone',
'type' => 'text',
'value' => $this->form_validation->set_value('company_phone'),
'class' =>'form-control',
'placeholder'=>'Mobile Number',
);
$this->data['designation'] = array(
'name' => 'designation',
'id' => 'designation',
'type' => 'text',
'value' => $this->form_validation->set_value('designation'),
'class' =>'form-control',
'placeholder'=>'User Designation',
);
/* $this->data['phone'] = array(
'name' => 'phone',
'id' => 'phone',
'type' => 'text',
'value' => $this->form_validation->set_value('phone'),
'class' =>'form-control',
'placeholder'=>'Phone Number',
); */
$this->data['company_address'] = array(
'name' => 'company_address',
'id' => 'company_address',
'type' => 'textarea',
'value' => $this->form_validation->set_value('company_address'),
'class' =>'form-control',
'placeholder'=>'',
);
$this->data['brief_info'] = array(
'name' => 'brief_info',
'id' => 'brief_info',
'type' => 'textarea',
'value' => $this->form_validation->set_value('brief_info'),
'class' =>'form-control',
'placeholder'=>'',
);
$this->data['password'] = array(
'name' => 'password',
'id' => 'password',
'type' => 'password',
'value' => $this->form_validation->set_value('password'),
'class' =>'form-control',
'placeholder'=>'Password',
);
$this->data['password_confirm'] = array(
'name' => 'password_confirm',
'id' => 'password_confirm',
'type' => 'password',
'value' => $this->form_validation->set_value('password_confirm'),
'class' =>'form-control',
'placeholder'=>'Confirm Password',
);
$this->data['input_data'] = array(
'name' => $this->input->post('name'),
'company' => $this->input->post('company'),
//'phone' => $this->input->post('phone'),
'company_phone' => $this->input->post('company_phone'),
'designation' => $this->input->post('designation'),
'type_industry' => $this->input->post('type_industry'),
'company_address' => $this->input->post('company_address'),
'brief_info' => $this->input->post('brief_info'),
'sectorid' => $this->input ->post('sectorid'),
'company_state' => $this->input ->post('company_state'),
'company_city' => $this->input ->post('company_city'),
'company_dist' => $this->input ->post('company_dist'),
'company_pincode' => $this->input ->post('company_pincode'),
);
$this->data['bread_crumb'] = render_bread_crumb(array('dashboard'=>'Dashboard','create_user'=>'Create User'));
$this->data['page']='register';
$this->_render_page(get_template(), $this->data);
}
}
}