Part of the EllisLab Network
   
10 of 25
10
FreakAuth light 1.0.4 released
Posted: 23 May 2007 03:45 PM   [ Ignore ]   [ # 91 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  512
Joined  12-05-2006

I just posted a new tutorial:

=> I don’t like that “auth.php” controller!

wink

 Signature 

FreakAuth_light: pluggable & extendable authentication library that works on CI 1.5.X

CI SWIFT MAILER: 44% less memory than PHPMailer at double speed

Using Zend Framework components in Code Igniter

Profile
 
 
Posted: 23 May 2007 05:01 PM   [ Ignore ]   [ # 92 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  492
Joined  02-21-2007
thierryREY - 23 May 2007 02:20 PM

[quote author=“grahack”]
well, I had a big idea that doesn’t seem to be possible with ci:
a controller in a sub-sub-folder (maybe useless)
/controllers/folder_level_1/folder_level_2/ctrler.php

I confirm ,I have made many test and work on CI URI and Router class to fix a CI bug into the route with controller in subfolder.
Bug when using route with subfolder in it ????

I read this one, but I’m not speaking about config in routes.php, but only about a sub-sub-folder controller
urls like index.php/folder_level_1/folder_level_2/ctrler/fction/params
didn’t work with a controller in a folder that would be in a subfolder of controllers/

anyway, your hack is great, we just have to wait your code review !!!

Profile
 
 
Posted: 23 May 2007 06:49 PM   [ Ignore ]   [ # 93 ]  
Grad Student
Rank
Total Posts:  51
Joined  09-12-2006

Ok
I give you my last notes and sugestions about auth, FAL_front and Freakauth_light files

I will work on admin files next days….

Resume of my previous notes and fix….

File: FAL_front.php : post
delete line 234 & 235

//if activated in config, sets the select country box
if ($this->CI->config->item('FAL_use_country'))

====================================================================================

File: FAL_front.php , FAL_validation.php & Freakauth_light.php : post
Change the fal_validation->login_check() to speed Up the code by acceded the database only one time.

Change the condition in FAL_front->login() function line 150 to:

//Modification
//if ($validation_response==TRUE && $this->CI->fal_validation->login_check($username_login, $password_login))
if ($validation_response==TRUE && $this->CI->fal_validation->login_check())

//......

And replace the fal_validation->login_check() by:

//Modifictaion
//function login_check($username_login, $password_login)
function login_check()
{
        
if ($this->CI->freakauth_light->login())
        
{
            
return true;
        
}
        
else
        
{
           
//let's set the message
           
$this->login_error_message = this->_error_prefix.$this->CI->lang->line('FAL_invalid_username_password_message').$this->_error_suffix;
           return
false;
        
}        
}

//......

====================================================================================

File: register.php the form template view : post

the Cancel button have no effect when ‘FAL_terms_of_service_message’ == ’’ (see my propositions)
and at line 98 replace base_url() by site_url()

====================================================================================

File: FAL_front.php : post

support for auth controller into subfolder in activation() function (only one level, CI doesn’t support more)
replace line 325 by this two lines:

$id_ind=(str_replace("/","",$this->CI->uri->router->fetch_directory()) != "")? 4:3;            
if (
$this->CI->freakauth_light->activation($this->CI->uri->segment($id_ind, 0), $this->CI->uri->segment($id_ind+1, '')))

//......

====================================================================================


NEW notes and fix….


File: FAL_front.php :

Similar than the previous for activation function.
support for auth controller into subfolder in forgotten_password_reset() function (only one level, CI doesn’t support more)
replace line 430 by this two lines:

$id_ind=(str_replace("/","",$this->CI->uri->router->fetch_directory()) != "")? 4:3;            
if (
$this->CI->freakauth_light->forgotten_password_reset($this->CI->uri->segment($id_ind, 0), $this->CI->uri->segment($id_ind+1, '')))

//......

=========================================================================

File: Freakauth_light.php :(the librarie)

In many place you make wrong call to the CI->load->view() function. In fact it is in all the sending email functions…...

You do:

$message = $this->CI->load->view($this->CI->config->item('view').$this->CI->config->item('FAL_forgotten_password_reset_email').EXT, $data, true);

//......

You have to do:

$message = $this->CI->load->view($this->CI->config->item('FAL_forgotten_password_reset_email'), $data, true);

//......

you have to delete: $this->CI->config->item(‘view’). and .EXT because CI->load->view() doesn’t need it to work.
In fact your code work because $this->CI->config->item(‘view’) doesn’t exist so it is always empty but if an user define this config for other purpose this will crash this call.

so delete this two peace of text :$this->CI->config->item(‘view’). and .EXT
at lines 1087,1111,1139 and 1162.

=================================================================

Files: activation_email.php, change_password_email.php, forgotten_password_email.php and forgotten_password_reset_email.php the email template files…

It is a little thing but as I have said for register.php (see before)
It will be better to use site_url() instead of base_url() for the site link into the emails…..

=================================================================

File: register.php the template form view.
In this view you use a global div container,<div id=“register”> </div>, around the form, but in all other view you don’t use it.

The css is also confuse with this particularity. It should be clearer if all the form view use the same scheme.
So we could delete it and modify the css for the same result into register form.

==================================================================

That’s all

Profile
 
 
Posted: 23 May 2007 07:10 PM   [ Ignore ]   [ # 94 ]  
Grad Student
Rank
Total Posts:  51
Joined  09-12-2006

@danfreak

I have look at your new tut for re routed auth method, and it seems that you have a problem with the routes.
you write:

1.
      $route[
'auth'] = "login";
   
2.
      $route[
'auth/login'] = "login";
   
3.
      $route[
'auth/logout'] = "logout";
   
4.
      $route[
'auth/register'] = "register";
   
5.
      $route[
'auth/activation/:any'] = "activate";
   
6.
      $route[
'auth/forgotten_password'] = "forgpass";
   
7.
      $route[
'auth/forgotten_password_reset/:any'] = "resetpass";
   
8.
      $route[
'auth/changepassword'] = "changepass";

it should be


2.
      $route[
'login'] = "auth/login";
   
3.
      $route[
'logout'] = "auth/logout";
   
4.
      $route[
'register'] = "auth/register";
   
5.
      $route[
'activate/:any'] = "auth/activation";//this doen't work,We have to use reg exprssion
   
5''.
      
$route['activate/(\d+)/([a-z]+)'] = "auth/activation/$1/$2";
   
6.
      $route[
'forgpass'] = "auth/forgotten_password";
   
7.
      $route[
'resetpass/:any'] = "auth/forgotten_password_reset";//this doen't work,We have to use reg exprssion
   
7''.
      
$route['resetpass/(\d+)/([a-z]+)'] = "auth/forgotten_password_reset/$1/$2";   
   
8.
      $route[
'changepass'] = "auth/changepassword";

the route with reg expression that I give work only if the activation code and reset code are only made lowercase letter…..

Profile
 
 
Posted: 24 May 2007 02:39 AM   [ Ignore ]   [ # 95 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  512
Joined  12-05-2006

@thierryREY

Thanks for everything.

I corrected the tutorial and retested the code

I did a further mistake with regard to the 1st method described

here is the code for re-routing (I also updated it in the tutorial)

in application/config/freakauth_light.php

$config['FAL_login_uri'] = 'login';                           
$config['FAL_logout_uri'] = 'logout';                         
$config['FAL_register_uri'] = 'register';                     
$config['FAL_activation_uri'] = 'activate/index';             
$config['FAL_changePassword_uri'] = 'changepass';             
$config['FAL_forgottenPassword_uri'] = 'forgpass';            
$config['FAL_forgottenPasswordReset_uri'] = 'resetpass/index';

in application/config/routes.php

$route['login'] = "auth";
$route['login'] = "auth/login";
$route['logout'] = "auth/logout";
$route['register'] = "auth/register";
$route['activate/:any'] = "auth/activation";
$route['changepass'] = "auth/changepassword";
$route['forgpass'] = "auth/forgotten_password";
$route['resetpass/:any'] = "auth/forgotten_password_reset";

This works!

 Signature 

FreakAuth_light: pluggable & extendable authentication library that works on CI 1.5.X

CI SWIFT MAILER: 44% less memory than PHPMailer at double speed

Using Zend Framework components in Code Igniter

Profile
 
 
Posted: 24 May 2007 10:10 AM   [ Ignore ]   [ # 96 ]  
Lab Assistant
RankRank
Total Posts:  192
Joined  04-03-2007

I have two questions:

1) how you load your views
2) how you do autoload / get config

Question 1:

//You do
$this->load->vars($data); //loads data to $this->_ci_cached_vars

//Before
$this->load->view('path/file');

//------
//Instead of just doing:
$this->load->view('path/file',$data); //loads data to $this->_ci_cached_vars

Both ways look to do the same thing, just curious if you found an advantage to doing this in two lines instead of the more compact one line approach?


Question 2:
In the download, you autoload the FAL library and it’s config file.  Only after reviewing the code did I discover that you’re actually autoloading from within the FAL libray the following:

$this->CI->load->library('db_session');
        
$this->CI->load->helper('form');
        
$this->CI->load->helper('url');
        
$this->CI->load->helper('freakauth_light');

It is nice that this setup simplifies the “setup” for using FAL, however, I didn’t realize this (maybe just add comments to the instructions) that all these helpers and library were being “autoloaded” by FAL.  I was already autloading these, so I think this means I was loading these things twice?!
  Edit: it looks like CI may check if a library is loaded already before loading again, but I don’t see a check for ancillary items (plugins, helpers, etc.) which would be loaded again.

Side comment:
When you autoload the configuration, CI loads the config into the CI object, making that config available globally.
When you load the library, it also loads the config, but the config is only available when an instance of the class is created.
I was trying to compare the performance of removing the autoload of the config versus the library loading the config by default, but I didn’t know how to get past the last step shown here:

function Freakauth_light($config) //need parameter here to accept the $config
    
{
        $this
->CI=& get_instance();

        
$global_array = (array)$this->CI->config; //type cast the global object into an array
        
$merged_array['config'] = array_merge($global_array['config'], $config); //merge the 'config' key
        
$this->CI->config['config'] = $merged_array['config']; //assign to CI Object
        // above doesn't work since "$this->CI->config" is an object, not an array

Maybe you guys already know the performance difference is negligible?  I was just thinking loading something twice would be inefficient.

Actually, when you autoload, CI creates an array called “is_loaded” (Line 105 in system/libraries/config.php).  Seems like CI should check if a config file “is_loaded” before loading it again with the library?

system/libraries/loader.php

function _ci_init_class($class, $prefix = '', $config = FALSE)
    
{    
        
// Is there an associated config file for this class?
        
if ($config === NULL)
        
{
            $config
= NULL;
            if (
file_exists(APPPATH.'config/'.$class.EXT))
//***Line above.  Should it also check "is_loaded", if it is already
//loaded, why do it again?
            
{
                
include(APPPATH.'config/'.$class.EXT);
            
}

Profile
 
 
Posted: 24 May 2007 10:25 AM   [ Ignore ]   [ # 97 ]  
Summer Student
Total Posts:  4
Joined  05-24-2007

Hi guys,

I’m a newbie on CI & FreakAuth and certainly very impressed by both of them and now planning to spice up some old apps by porting them to CI/FAL.

I installed FreakAuth and it seems to work fine, except for a small bug with the session expiration: whenever I log in as the superadmin I can perform two pageloads after which the session expires for some reason.. I’ve tried to play around with the config.php and change the expiration time, but so far no success. Any thoughts on this?

EDIT: Ok, figured it out, the autoload loaded “session” -library, which caused some unwanted effects.. :D

Profile
 
 
Posted: 24 May 2007 02:47 PM   [ Ignore ]   [ # 98 ]  
Grad Student
Rank
Total Posts:  39
Joined  04-21-2007

@danfreak

I am reading the tutorials on custom user profiles. One solution t the question of multiple profiles is adding a flag to the profile data showing whether it is extended or not. For many sites it could be sufficient to have two types of users, the regular users and the special user with the additional fields (such as Musician). To generalize this, I think it is preferable to make this field an integer to support an unlimited number of types, since some sites offer multiple user types (Director, Musician, Comedian, etc.). A mechanism is required to specify what fields belong to each type of user. Perhaps an array naming the fields.

While you are thinking about it, consider storing extended fields in their own table for each type, but that may be a bit much for now.

Anyway, will keep exploring FA.

Steve

Profile
 
 
Posted: 24 May 2007 03:32 PM   [ Ignore ]   [ # 99 ]  
Grad Student
Rank
Total Posts:  39
Joined  04-21-2007

Just wanted to let you know I encountered a problem testing FAL 1.0.4 not sure if anyone noticed this, but my existing user from the previous version was in the database. I could bring this up fine in the admin and display the form to edit the profile. On the right, the new custom profile fields defined in the FAL configuration appeared, naturally with nothing in them. I checked the database and the fields were created properly along with the profile table.

In the details (view user) to the right it says “no data in DB: please add them” but when I go to the edit profile form, enter my name and surname, it refused to populate the fields. It says “0 user edited successfully!”

I looked in the database and found there were no rows in the fa_user_profile table. Could the reason be that I did not go through the installer step, being an upgrade? Or is there some reason why it will not create the row if one is not already there (the automagic?) I suppose it could be the user entry was created under the previous system and therefore no user profile row exists.

I hope I followed the upgrade instructions correctly. They were a little confusing.

Okay, I added a row for user 1 using phpMyAdmin (the superadmin was the only one in the database left from the previous time) and it works fine. I assume this would happen for pending users as well. It could really be a problem if you had a dozens of users and had to create these rows manually for each. Perhaps this could addressed in the next release for those upgrading.

Profile
 
 
Posted: 24 May 2007 03:39 PM   [ Ignore ]   [ # 100 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  492
Joined  02-21-2007

@mule
I had a similar problem at my FAL beginnings, please see this post and tell me if the ‘dirty’ hack works for you. I installed FAL on an existing CI app, and I had this problem. This problem vanished after a fresh reinstall (new CI install, new FAL install).

-sek - 24 May 2007 02:47 PM

@danfreak
I am reading the tutorials on custom user profiles. One solution t the question of multiple profiles is adding a flag to the profile data showing whether it is extended or not.

well I think that every profile type should be an ‘extended’ one. I don’t see the point of having ‘regular profiles’, webmasters could just have an ‘extended profile’ called ‘regular’

For many sites it could be sufficient to have two types of users, the regular users and the special user with the additional fields (such as Musician). To generalize this, I think it is preferable to make this field an integer to support an unlimited number of types, since some sites offer multiple user types (Director, Musician, Comedian, etc.). A mechanism is required to specify what fields belong to each type of user. Perhaps an array naming the fields.

While you are thinking about it, consider storing extended fields in their own table for each type, but that may be a bit much for now.

Good idea, I love generalisation. But I love factorisation too: what if we want similar fields in different profiles? I don’t want to have duplicate code here.
So I would just add (maybe you thought about this too) something like (in the config file)

<?php
//...

// this is like our good old FAL_user_profile_fields_names (may need better i18n support)
// and FAL_user_profile_fields_validation_rules
$config['FAL_extended_profiles_field_names']['movie'] = 'prefered movie';
$config['FAL_extended_profiles_field_names']['actor'] = 'prefered actor';
$config['FAL_extended_profiles_field_names']['instr'] = 'prefered instrument';

$config['FAL_extended_profiles_field_names']['movie'] = 'trim|required|max_length[50]';
$config['FAL_extended_profiles_field_names']['actor'] = 'trim|required|whatever';
$config['FAL_extended_profiles_field_names']['instr'] = 'trim|required';

// fields associations to extended profiles
$config['FAL_extended_profiles_assoc']['director'] = array('movie', 'actor');
$config['FAL_extended_profiles_assoc']['musician'] = array('movie', 'instr');
$config['FAL_extended_profiles_assoc']['comedian'] = array('movie', 'actor', 'instr');

now the tricky part: the db tables

in the actual FAL, each profile entry corresponds to a user and has a row of fields (id, field1, field2…)

What I suggest:
we could have several rows for a single user, one for each field that he has:
a row links to a field table and the row we need in it (id, user_id, field_name, id_in_this_field_table)
NOTE: id is not corresponding to the user_id as it did before

EDITED:
then we have a table for each field, containing the data: (id, data)

WAS:
then the last table contains the data: (id, data)

I’m not a db guru, tell me what you think

Profile
 
 
   
10 of 25
10
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 719, on June 06, 2008 10:16 AM
Total Registered Members: 64453 Total Logged-in Users: 19
Total Topics: 80957 Total Anonymous Users: 0
Total Replies: 435678 Total Guests: 169
Total Posts: 516635    
Members ( View Memberlist )