CodeIgniter-Authit icon indicating copy to clipboard operation
CodeIgniter-Authit copied to clipboard

Add new funcionality (Types of users)

Open rodrigoarreola opened this issue 8 years ago • 1 comments

I'm very new in CI but I want to add the use of two types of users (admin users, regular users).

In Views/Auth/Signup.php line 16 I've added

echo form_radio('user_type', 'User', TRUE);
echo form_label('Usuario', 'user_type');
echo form_radio('user_type', 'Admin user', FALSE);
echo form_label('Super Usuario', 'user_type') .'<br />';

In models/Authit_model.php line 54 I've added

public function create_user($email, $password, $user_type)
{
	$data = array(
		'email' => filter_var($email, FILTER_SANITIZE_EMAIL),
		'password' => $password, // Should be hashed
		'created' => date('Y-m-d H:i:s'),
		'last_login' => date('Y-m-d H:i:s'),
		'type' => $user_type
	);
	$this->db->insert($this->users_table, $data);
	return $this->db->insert_id();
}

and in line 78

$this->load->dbforge();
$this->dbforge->add_field('id');
$this->dbforge->add_field('email VARCHAR(200) NOT NULL');
$this->dbforge->add_field('password VARCHAR(200) NOT NULL');
$this->dbforge->add_field('created DATETIME NOT NULL');
$this->dbforge->add_field('last_login DATE');
$this->dbforge->add_field('user_type  VARCHAR(200) NOT NULL'); 
$this->dbforge->create_table($this->users_table);

But the problem is in controllers/Auth.php because I don't know how to send the type through the form I've this in the signup function this but doesn't work

$this->form_validation->set_rules('email', 'Email', 'required|valid_email|is_unique['. $this->config->item('authit_users_table') .'.email]');
$this->fomr_validation->set_rules('text', 'user_type', required);
$this->form_validation->set_rules('password', 'Password', 'required|min_length['. $this->config->item('authit_password_min_length') .']');
$this->form_validation->set_rules('password_conf', 'Confirm Password', 'required|matches[password]');

if($this->form_validation->run()){
	if($this->authit->signup(set_value('email'), set_value('password'), set_value('type_user'))){
		$this->authit->login(set_value('email'), set_value('password'), set_value('type_user'));

So any help is welcome :)

rodrigoarreola avatar Jan 19 '18 15:01 rodrigoarreola

This is more of an 'application architecture' question, not directly related to the library itself, but I can try and point you in a direction. Usually you don't need to check the user type to login (user-type would be set in the session after authentication), but if you do for some reason - you need to add the variables to the methods in "libraries/Authit.php" file too and your logic.

trafficinc avatar Jan 22 '18 21:01 trafficinc