CodeIgniter Forums
flexi auth - A user authentication library for CodeIgniter - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: flexi auth - A user authentication library for CodeIgniter (/showthread.php?tid=54581)

Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34


flexi auth - A user authentication library for CodeIgniter - El Forum - 03-05-2013

[eluser]NotSmilie[/eluser]
Thanks for the suggestions.
I guess I could have the two projects use the same database, with different prefixes on the CI_Session table. This way the sessions are separated (as I'm not going to use your library for the backend), and it can use the default database.
The problems with two databases is becoming a pain anyway, as no libraries seem to support it.


flexi auth - A user authentication library for CodeIgniter - El Forum - 03-05-2013

[eluser]Azarhi[/eluser]
Didn't figure anyone has use Postgres, not very popular for web development. On this I have started working with Flexi Auth, and working through my troubles. Might have a few questions later if I can't figure things out. Right now most have been of my own making.

As for the errors I am getting, yes I have setup a fresh install of 2.1.3 and followed the install instructions. To continue working with flexi auth I have had to turn off ALL error reporting. Which makes development difficult because those three errors report any time I load either library (flexi_auth or flexi_auth_lite).

What version of PHP do you recommend/require to have no errors? I am using 5.1.6 as we are using standard install Redhat 5 machines. This is a requirement and not something that can be changed. Upgrading php might be an option.

Thanks for you help.


flexi auth - A user authentication library for CodeIgniter - El Forum - 03-05-2013

[eluser]taztwister[/eluser]
I am calling $result = $this->flexi_auth->insert_user($email, $username, $password, false, 1, false); and I am getting an error from the insert.

I also used the provided sql dump to make the tables for the library. I can make the default value null but I don't want to do that if that is not how its supposed to work.

I checked the sql dump file and it does say that the field has to be NOT NULL. so this would make sense if it this value isn't sent as part of the insert query.

A Database Error Occurred

Error Number: 1364

Field 'uacc_forgotten_password_token' doesn't have a default value

Filename: D:\Internet\codeignitercore\system\database\DB_driver.php

Line Number: 330


flexi auth - A user authentication library for CodeIgniter - El Forum - 03-06-2013

[eluser]haseydesign[/eluser]
@Azarhi

For flexi auth to work with no php warnings, its needs to be PHP 5.2.x (I'm not sure of the exact version).
Personally I use PHP 5.3.13 on Apache 2.2 without any issues.

------------------------------------------------------------------------------------------------------------------------

@taztwister

I'm not sure why you would be getting that error if you say you have installed the sql dump file too.
I would recommend you go through the installation guide and get the demo working 100%, then start developing your site.


flexi auth - A user authentication library for CodeIgniter - El Forum - 03-06-2013

[eluser]NotSmilie[/eluser]
Okay, so I solved my problems by migrating the two databases.
My backend uses a different session table than the front-end does. The two logins are in no way affiliated, I just want to edit users via the backend, such as username, password, email, credits (custom field) etc.. I suppose it doesn't need the "real" session data for that?


Regrettable I face this error now:
A PHP Error was encountered
Severity: Warning
Message: Creating default object from empty value
Filename: models/flexi_auth_lite_model.php
Line Number: 47

This is my class:

Code:
<?php

class User extends CI_Controller {

    public function __construct()
    {
        parent::__construct();

        $this->load->library('flexi_auth');
    }

    function index() {
        $this->userlist();
    }

    function userlist() {

        if (!$this->general->isLoggedIn()) {
            header('Refresh: 0; url=' . base_url("login") . '');
            die();
        }

        if (!$this->general->checkAccess("users")) {
            header('Refresh: 0; url=' . base_url("denied") . '');
            die();
        }

        $data['query'] = $this->db
            ->get('user_accounts');

        $data['page'] = 'user';
        $view = $this->load->view('user/userlist', $data, TRUE);
        $this->template->create_page('User', $view);
    }
}

?>

Edit:
Nevermind, forgot this: $this->auth = new stdClass;


flexi auth - A user authentication library for CodeIgniter - El Forum - 03-06-2013

[eluser]NotSmilie[/eluser]
Hi,
So I decided to put it to the test, and it seems to work great Big Grin

My add function creates a new user:
Code:
function add(){
        if(!empty($_POST)){
            $user_data = array(
                'uacc_credits' => '0'
            );
            $group_id = 1;
            $data['res'] = $this->flexi_auth->insert_user($_POST['uacc_email'], $_POST['uacc_username'], $_POST['uacc_password'], $user_data, $group_id, $_POST['uacc_active']);
            $data['message'] = (! isset($data['message'])) ? $this->session->flashdata('message') : $data['message'];
        }

        $data['page'] = 'user';
        $view = $this->load->view('user/create', $data, TRUE);
        $this->template->create_page('User', $view);
    }

My problem is about the messages. The function returns a bool, but as I can read, I can retrieve the exact message and the way I'm currently doing it appears to be wrong.

I want an error message if the creation fails, such as the email already exists, or was invalid, or username exists or is invalid etc..
How is this possible?


flexi auth - A user authentication library for CodeIgniter - El Forum - 03-06-2013

[eluser]taztwister[/eluser]
@haseydesign

I did go through the instillation guide. I am not sure why the forgotten password token field is set to be NOT NULL but in the insert query the library runs it doesn't specify a forgotten password token value. So the insert query will fail.

Code I am executing
Code:
$result = $this->flexi_auth->insert_user($email, $username, $password, false, 1, false);
Query run by library from insert_user command
Code:
INSERT INTO `user_accounts`
(`user_accounts`.`uacc_group_fk`,
`user_accounts`.`uacc_email`,
`user_accounts`.`uacc_username`,
`user_accounts`.`uacc_password`,
`user_accounts`.`uacc_ip_address`,
`user_accounts`.`uacc_date_last_login`,
`user_accounts`.`uacc_date_added`,
`user_accounts`.`uacc_activation_token`,
`user_accounts`.`uacc_active`,
`user_accounts`.`uacc_suspend`,
`user_accounts`.`uacc_salt`)
VALUES (
  1,
'[email protected]',
'testuser',
'$2a$08$AyMGTHv4Vq/rJ84V.KBMJuVTRNETI0Gb4dxbYhyNDpGaQ.RcfXnpa',
'192.168.1.197',
'2013-03-06 13:03:24',
'2013-03-06 13:03:24',
'9d6daf8b40382ba9bc4438e980eaa2f00b9852b9',
  0,
  0,
'YdtZJYNvf5')

SQL Script provided by the library that pertains to this field
Code:
DROP TABLE IF EXISTS `user_accounts`;
CREATE TABLE `user_accounts` (
  `uacc_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `uacc_group_fk` smallint(5) unsigned NOT NULL,
  `uacc_email` varchar(100) NOT NULL,
  `uacc_username` varchar(15) NOT NULL,
  `uacc_password` varchar(60) NOT NULL,
  `uacc_ip_address` varchar(40) NOT NULL,
  `uacc_salt` varchar(40) NOT NULL,
  `uacc_activation_token` varchar(40) NOT NULL,
  `uacc_forgotten_password_token` varchar(40) NOT NULL,
  ....



flexi auth - A user authentication library for CodeIgniter - El Forum - 03-07-2013

[eluser]haseydesign[/eluser]
@NotSmilie

From your example where you define
Code:
$data['message'] = (! isset($data['message'])) ? $this->session->flashdata('message') : $data['message'];

I can't see whether you have set the flexi auth library message to the flash data - so I'm guessing this is what is wrong.
To get a status/error message from the library, you call the 'get_messages()' function.

So with your insert user example, your code would look something like:
Code:
$data['res'] = $this->flexi_auth->insert_user(...);
$data['message'] = $this->flexi_auth->get_messages();

The code you're currently using looks like a copy and paste from the demo, which is saving the message to CI's flash session data (Via the login method in demo_auth_model.php) before it performs a redirect - hence the use of flash data so the message is available once the page is reloaded.

If you don't need/want to use a redirect once the user is inserted, you can just catch the message without using CI's flash data.

If you want to get a bit more complicated than just outputting the message, you could try using the 'get_messages_array()' function.


flexi auth - A user authentication library for CodeIgniter - El Forum - 03-07-2013

[eluser]haseydesign[/eluser]
@taztwister

I'm not convinced the NOT NULL condition set in the MySQL table is the cause of the error you are getting.
I use the same SQL you are using and when I insert a record, MySQL simply enters an empty string (Equivalent to '') rather than NULL and this works fine for me and other users.

The NOT NULL setting is just a personal preference, if you want to allow NULL, then give it a go and see whether it solves your problem as I don't think it should affect the functionality of the library.

Additionally, you could try defining MySQL to enter an empty string for the column.
Code:
ALTER TABLE `user_accounts`
MODIFY COLUMN `uacc_forgotten_password_token`  varchar(40) NOT NULL DEFAULT '' AFTER `uacc_activation_token`;
Note: That sql requires the default database to be setup with no columns moved or renamed.

If one of these methods do work, then maybe its conflict with the MySQL version you are using - do you know what version you're on?


flexi auth - A user authentication library for CodeIgniter - El Forum - 03-08-2013

[eluser]NotSmilie[/eluser]
Thanks for the help Smile
I'm still struggling though, I attempted to update a user, and it didn't work at all, lol.
Here is my function

Code:
function edit(){
        $user_id = mysql_real_escape_string($product_id = $this->uri->segment(3));
        $user = $this->flexi_auth->get_user_by_id_row_array($user_id);
        if($user == false){
            $data['error'] = "User doesn't exists";
            $data['page'] = 'user';
            $data['query'] = $this->db
                ->get('user_accounts');
            $view = $this->load->view('user/userlist', $data, TRUE);
            $this->template->create_page('User', $view);
        }
        $data['user'] = $user;
        $data['page'] = 'user';
        $data['query'] = $this->db
            ->get('user_groups');

        if(!empty($_POST)){
            if($_POST['uacc_password'] != '')
                $user_data = array(
                    'email' => $_POST['uacc_email'],
                    'password' => $_POST['uacc_password'],
                    'username' => $_POST['uacc_username'],
                    'group_fk' => $_POST['uacc_group_fk'],
                    'uacc_credits' => $_POST['uacc_credits']
                );
            else
                $user_data = array(
                    'uacc_email' => $_POST['uacc_email'],
                    'uacc_username' => $_POST['uacc_username'],
                    'uacc_group_fk' => $_POST['uacc_group_fk'],
                    'uacc_credits' => $_POST['uacc_credits']
                );

            $data['res'] = $this->flexi_auth->update_user($user_id, $user_data);
            $data['message'] = $this->flexi_auth->get_messages();
        }

        $view = $this->load->view('user/edit', $data, TRUE);
        $this->template->create_page('User', $view);
    }

I wasn't really sure if the fields were supposed to have uacc_ before them, they don't have that in the online documentation, and in the example, they had upro_ so I tried with both without help though.