Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+4 votes
28.4k views
in Q2A Core by
I know is part of the advance section, but can anyone help me or give me an idea how can I add the Q&A login system to my other directorys. I have already search the function or piece of code but I can't find anything.
by
Hi Mèlanie - thanx for your quick reply!
Unfortunately (or luckily...) I just get an user-name from external.
Based on this I would like to automatically log in  q2a based on the q2a user-profiles.  If I understood the "q2a single-sign on module" the right way, than this requires, that all user data (profile, picture etc) are provided by the external source - or I'm I wrong?
So what I'm seeking for is: Use Q2A internal profiles -- but instead of manual user login: Take the system information about the user who gets identified by the NTLM info (NT-user logged in at a domain).
What I have e.g. is a php function which returns a user name from external. Where should I go with this information to automatically log in a user who opens q2a?  
--> if the user is known in the q2a database (same name): just login
--> if the user is unknown: open initial profile page to let the user add profile information...

what I'm playing around with is the mechanism used to read out the cookie and replace something in there -- but this feels like a dirty hack - isn't it?  :(

...sorry - difficult to explain with just few words...
by
+1
I understand what you want to achieve.. I guess it is feasible, but would required some work... As a hint, look at qa-app-users.php, this is the one the either use the external or internal information.
 I think this would worth being a whole new question!
by
I want to login from my application to The Q&a, could you please help me to do that?

1 Answer

+6 votes
by
 
Best answer

Interesting question. Here's how you do it in your PHP code:

define('QA_BASE_DIR', '/PATH/TO/Q2A/');
 
require_once QA_BASE_DIR.'qa-include/qa-base.php';
require_once QA_BASE_DIR.'qa-include/qa-app-users.php';
require_once QA_BASE_DIR.'qa-include/qa-db.php';
 
qa_base_db_connect(null);
 
echo qa_get_logged_in_userid().' '.qa_get_logged_in_handle().' '.qa_get_logged_in_email().' '.qa_get_logged_in_level();
 
Replace /PATH/TO/Q2A/ above with the full path to your Q2A directory (the directory that includes qa-config.php). The last line shows the kind of information you can extract about the logged in user. If no user is logged in, all of these functions (defined in qa-app-users.php) return null.
by
Thank you!!

Works great, and thank you for this great product.
by
edited by
Thanks again for the code.

The code worked great with 1.4, but stop working with the 1.5 beta and today I upgrade to 1.5 and still doesn't work. Any ideas??

UPDATE:

Looks like the "qa_base_db_connect(null);" function was delete from 1.5 what use now?
by
You don't need to replace qa_base_db_connect(...) with anything and can just leave it out.
...