[SOLVED] Login function
- Single Page
Posted 31 May 2012 - 14:27 PM
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
Posted 31 May 2012 - 17:35 PM
Posted 01 June 2012 - 07:53 AM
I need something with a mechanism that allows me to authorize accounts or add add accounts manually.
Posted 01 June 2012 - 18:18 PM
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='' />";
}
Posted 05 June 2012 - 02:58 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.
[/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]
Posted 05 June 2012 - 08:39 AM
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
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 :)