⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

[SOLVED] Login function



Raboo
  • profile picture
  • Member

Posted 31 May 2012 - 14:27 PM

Hi,

I'm pretty new to grocery CRUD and CI. In fact I'm not even a php coder.
I just needed to build a database gui and saw this tool and it does a great job.
I've been able to build a gui based on the examples.

But I want to have a login function to the page. Any advice on where I can get such a function?
If it's a library or a tutorial or something.

/Raboo

johnvanham
  • profile picture
  • Member

Posted 31 May 2012 - 17:35 PM

I've used tankauth which can be found here: http://www.konyukhov.com/soft/tank_auth/

Raboo
  • profile picture
  • Member

Posted 01 June 2012 - 07:53 AM

It was simple enough to setup. But with this tool anyone with a valid e-mail can register..
I need something with a mechanism that allows me to authorize accounts or add add accounts manually.

johnvanham
  • profile picture
  • Member

Posted 01 June 2012 - 18:18 PM

Yes that's exactly what I did - I disabled registration, and then I used GroceryCRUD to allow admins to view the users table which TankAuth uses, and to add users to that table as well. I used the callback functionality to both blank the password field, and to hash the password entered when creating/updating a user entry. I added an extra field in the table to flag whether a user is an admin or not and added a method to TankAuth to check for that.

Here's my code for my user table in case you find it useful:



public function users()
{
if (!$this->tank_auth->is_admin()) {
redirect('/main/index');
}

$this->crud->set_subject('User');
$this->crud->set_table($this->db->dbprefix('users'));

$this->crud->columns('username','email','activated','admin','banned','ban_reason','last_ip','last_login');
$this->crud->fields('username','email','password','activated','admin','banned','ban_reason');

$this->crud->callback_edit_field('password',array($this,'set_password_input_to_empty'));
$this->crud->callback_add_field('password',array($this,'set_password_input_to_empty'));

$this->crud->required_fields('username','email','password','activated','admin','banned');

$this->crud->callback_before_update(array($this,'encrypt_password_callback'));
$this->crud->callback_before_insert(array($this,'encrypt_password_callback'));

$this->crud->callback_after_insert(array($this, 'log_activity_insert'));
$this->crud->callback_after_update(array($this, 'log_activity_update'));
$this->crud->callback_before_delete(array($this, 'log_activity_delete_user'));

$output = array_merge($this->data,(array)$this->crud->render());

$this->_users_output($output);
}

function encrypt_password_callback($post_array, $primary_key) {
//Encrypt password only if is not empty. Else don't change the password to an empty field
if(!empty($post_array['password']))
{
// Hash password using phpass
$hasher = new PasswordHash(
$this->tank_auth->ci->config->item('phpass_hash_strength', 'tank_auth'),
$this->tank_auth->ci->config->item('phpass_hash_portable', 'tank_auth'));
$hashed_password = $hasher->HashPassword($post_array['password']);

$post_array['password'] = $hashed_password;
}
else
{
unset($post_array['password']);
}

return $post_array;
}

function _users_output($output = null)
{
$this->load->view('users_template.php',$output);
}

function set_password_input_to_empty() {
return "<input type='password' name='password' value='' />";
}


fieldju
  • profile picture
  • Member

Posted 05 June 2012 - 02:58 AM

ag[quote name='Raboo' timestamp='1338537216' post='2120']
It was simple enough to setup. But with this tool anyone with a valid e-mail can register..
I need something with a mechanism that allows me to authorize accounts or add add accounts manually.
[/quote]


AG_auth is what I use in my projects
http://codeigniter.com/wiki/AG_Auth

you can re-write the register portion of the code
located https://github.com/a..._Controller.php
and put the register function in an admin accessible only controller
you can block off controllers by putting this at the top of your controllers


/* restrict access to all but admin */
$this->ag_auth->restrict('admin');

or what ever group you want to be admins

https://gist.github.com/2872317

[color=#990000]addParentUserAccount()[/color]
[color=#990000]is my function for creating a new account[/color]

Raboo
  • profile picture
  • Member

Posted 05 June 2012 - 08:39 AM

Thanks, that looks like a interesting alternative but I actually managed to get it up and running with ion_auth. It also has groups, registration and all registered users needs to be approved by admin.

vgsangiuliano
  • profile picture
  • Member

Posted 04 January 2015 - 21:02 PM

Hi Raboo,

currently I'm trying to use grocery together with ion_auth.

I'm a newbie in PHP.

My goal would be to have CRUD operations on a table but only after a user is logged in.

If user is not logged in, ion_auth login view should be displayed and after successful login a redirection to grocery view should occur.

How were you able to gain such a behaviour?

Can you please help me or drive me to some reference?

Many thanks.

KR 


portapipe
  • profile picture
  • Member

Posted 22 August 2016 - 08:09 AM

Hi everyone, this is my first post :)

I've search a lot for a basic simple login system. Every script was quite complete and I just want a simple login system so I've created one yesterday and I want to let everyone use it :)

It's really easy, it even create the database and a first admin user for you with just a click.

I've tried to write a complete guide to start using it but it's really simple, no registration form, lost password or anything else, you will manage the users directly with GroceryCrud.

Here the github website: https://portapipe.github.io/Login-GroceryCrud/

Hope this could help you as it helped me :)