How to filter list view with the current user ?

A place for users and developers of the Xataface to discuss and receive support.

How to filter list view with the current user ?

Postby pyroboynroses » Thu Feb 04, 2010 2:53 am

Hi,

Before I start I'm french so please be kind with my english :D

I'm triyng to use xataface into a joomla website (with a wrapper to display xataface in my webpage).
For this, no problems, xataface is displaying fine in Joomla.

I use the joomla user identification (with the jos_users mysql table) to let the users log in the web site.

I want users to be able to add record in xataface and I want them just to be able to see there own records in the list view. Is it possible ?

My table users can record in gets a "join" with the id field in the jos_users table. So how could I add the user's id in my record in my table when a user add a new record ?

I think it could be defined in the delegate classes of my table.
The function init(&$table) may be configured to display only records linked to the right user but how ? with a sql select query ?

The function afterInsert(&$record) could be defined to add the id of the current user.
I try this code (in my delegate classes for my table) :

Code: Select all
function afterInsert(&$record) {
$sql="update t_pilule set id=90 where num_pill=2";
mysql_query($sql);
}


In this example my table is named t_pilule, id is the joined field with the jos_users table and num_pill is the mrimary key of t_pilule table.
This example works fine but I would like to set the id with the id of the current user and not update the record with numpill=2 but the new added record.

I hope I was clear but I recap my questions :

- How to add the user's id in a new record ?

- How to display only records created by a user with his joined id ?

Thank you for your answers :)
pyroboynroses
 
Posts: 24
Joined: Thu Feb 04, 2010 2:26 am

Re: How to filter list view with the current user ?

Postby pyroboynroses » Thu Feb 04, 2010 4:53 am

Ok, so I found how to insert a value in the new record.

I used the beforeInsert function with the SetValue class for a record.

Here is the code :

Code: Select all
function beforeInsert(&$record) {
   $record->setValue('id','55');
}


With this code, I set the value "55" in the field "id" of the new record, before saving it in the DB.

This works fine but I haven't find yet how to replace the "55" with the user's id...
pyroboynroses
 
Posts: 24
Joined: Thu Feb 04, 2010 2:26 am

Re: How to filter list view with the current user ?

Postby pyroboynroses » Thu Feb 04, 2010 6:22 am

Ok I continue my investigations and I've found how to insert user's id in the record.

I've made the authentication in xataface on the joomla user table (in the conf.ini file) but the user needs to authenticate twice !!!

here is the code :

Code: Select all
function beforeInsert(&$record) {
$auth =& Dataface_AuthenticationTool::getInstance();
$user =& $auth->getLoggedInUser();

$id = $user->val('id');

$record->setValue('id'),$id);
}


So with this my first problem is nearly resolved. Just I would like to use a "transparent" login procedure in xataface because I don't want the users to login twice (once in joomla, once in xataface)...

I have an other problem. Passwords in joomla are crypted in the DB so users who wants to log in xataface get a wrong password because xataface wants the crypted password...
How to resolve that ?

Thanks for your answers.
pyroboynroses
 
Posts: 24
Joined: Thu Feb 04, 2010 2:26 am

Re: How to filter list view with the current user ?

Postby shannah » Thu Feb 04, 2010 12:33 pm

I'm not sure whether you were able to get login working or not from your description. You said that you got it working, but you also said that you're having problems with the encrypted password.

Generally there are 3 strategies for shared login.

1. Authenticate against the same users table (looks like this is the way you are doing it).
2. Tap into the Joomla session (this can be tricky and I wouldn't be able to show you how to do this really in the forums... will take poking around and trial and error).
3. Set up a central authentication server then use the CAS modules for Joomla and Xataface respectively to both authenticate against this.

Obviously the easiest option is the first one - but then you have to login twice.

-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: How to filter list view with the current user ?

Postby pyroboynroses » Thu Feb 04, 2010 11:47 pm

Ok thank you for the answer.

I was thinking it could be possible to have a link to the AuthenticationTool.php file when you log in Joomla. You just have to find the password control page in joomla and add the xataface page into.
With that, as joomla and xataface use $_REQUEST to get the username and the password, you could make the double login in one operation, invisible for the user, isn't it ?

So with the encrypted password, I tested the log with joomla table by adding a user directly with phpmyadmin with a non encrypted password. It works fine but not on encrypted password because you have to enter in the xataface login form the whole encrypted password (ex : ao42zethOJ123HZRF45ODa644:jfD5e4s4563S1aD).

So, in the joomla encrypted password (MD5), there is to datas, the first (ao42zethOJ123HZRF45ODa644) and the second (jfD5e4s4563S1aD) separated by ":".

The second one is a random key generated when the password is encrypted and the first is the result of the password concatened with the key encrypted in MD5.

So, joomla does this to encrypt password :

Code: Select all
$encryptedpassword = MD5($clearpassword.$key):$key


So I was thinking to resolve this problem in the AuthenticationTool.php in the function getCredentials().

- With a SQL query you can select the password of the user who wants to log.
- Then you cut the string to have only the key (after ":").
- Then you encrypt the password given by the user with the selected key.
- After you concate the encrypted password with the key separated by ":".
- And this string should be the same as the joomla encrypted password to grant access.

Do you think it's the right way to test the password ?

I'll try this this afternoon. Will be in touch with you.

So ffor filtering records by a user's id, anyone got an idea ?

Thank you ! :D
pyroboynroses
 
Posts: 24
Joined: Thu Feb 04, 2010 2:26 am

Re: How to filter list view with the current user ?

Postby pyroboynroses » Fri Feb 05, 2010 5:22 am

Ok, I've found how to filter records with the user id.

thank's to this post and the wiki (permissions) :

http://xataface.com/forum/viewtopic.php?t=4062#20407
pyroboynroses
 
Posts: 24
Joined: Thu Feb 04, 2010 2:26 am

Re: How to filter list view with the current user ?

Postby shannah » Fri Feb 05, 2010 10:04 am

You might find this thread helpful: viewtopic.php?t=4459#22046
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: How to filter list view with the current user ?

Postby pyroboynroses » Fri Feb 05, 2010 10:21 am

yes, i've found this topic but i don't know where did fantomasdm pasted his code...

can you help me (the filename where this code is pasted) please ? :roll:
pyroboynroses
 
Posts: 24
Joined: Thu Feb 04, 2010 2:26 am

Re: How to filter list view with the current user ?

Postby pyroboynroses » Sun Feb 07, 2010 6:31 am

I've contated fantomasdm and he pasted this code in the jos_users.php file (in tables directory).

I've tested that and it worked fine !!

I think this code should be implemented in the wiki for joomla users :wink:
pyroboynroses
 
Posts: 24
Joined: Thu Feb 04, 2010 2:26 am

Re: How to filter list view with the current user ?

Postby shannah » Mon Feb 08, 2010 12:51 pm

Perhaps you could add it to the wiki. I have added a link for this page at
http://xataface.com/wiki/authentication
You should notice a link partway down the page that says "Authenticating Against the Joomla! Users Table?"
If you log in and click the '?', it will allow you to create a new page for this.

I just added a page in the wiki to describe a similar process to integrate Xataface with PHBB. You can use this as a reference if you like:
http://xataface.com/wiki/Authenticating ... sers_table

-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: How to filter list view with the current user ?

Postby pyroboynroses » Mon Feb 08, 2010 11:52 pm

Yes of course !

I will do that this evening. :D
pyroboynroses
 
Posts: 24
Joined: Thu Feb 04, 2010 2:26 am


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 16 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved