// setup the admin account
public function check_activation_required()
{
$query = $this->db->query('SELECT * FROM users');
// check for no accounts
if(empty($query->result())){
return TRUE;
}
else {
$this->session->set_flashdata('message', 'An admin account has already been activated. Please login.');
return FALSE;
}
}
public function setup_admin_account()
{
$login = $this->input->post('login');
$password = $this->input->post('password');
// create an admin group
$create_group = $this->ion_auth->create_group('admin', 'The administration group');
if(!$create_group) {
$this->session->set_flashdata('message', $this->ion_auth->errors());
}
$admin_group = NULL;
$group_query = $this->ion_auth->groups()->result();
foreach($group_query as $struct) {
if ($struct->name == 'admin') {
$admin_group = $struct->id;
break;
}
}
if(is_null($admin_group)){
$this->session->set_flashdata('message', 'Could not create group or find admin group id.');
return;
}
/*
Register (create) a new user.
Parameters:
1. 'Identity' - string REQUIRED. This must be the value that uniquely identifies the user when he is registered. If you chose "email" as $config['identity'] in the configuration file, you must put the email of the new user.
2. 'Password' - string REQUIRED.
3. 'Email' - string REQUIRED.
4. 'Additional Data' - multidimensional array OPTIONAL.
5. 'Group' - array OPTIONAL. If not passed the default group name set in the config will be used.
*/
if ($this->ion_auth->register($login, $password, $login, NULL, array($admin_group) )) {
$this->session->set_flashdata('message', $this->ion_auth->messages());
}
else {
$this->session->set_flashdata('message', $this->ion_auth->errors());
}
}