Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
–1 vote
17.6k views
in Q2A Core by

I'm not a technical person and am trying to set up this website using question2answer template.

The site is up and I can post questions and answer them, and I've also made changes necessary to qa-external-users.php as specified.

But I'm unable to log in as the log in, register and logout URLs that need to be specified in the file are being done incorrectly. From that particular section I've commented out the default sections and un-commented "Example 1". Yet I'm unable to get the log in page to show up.

Please guide me in how to get the log in and register pages to show up.

I'm not even able to get to the admin panel without these settings!

The code after my modifications for the get-links sections is as below:

 

function qa_get_login_links($relative_url_prefix, $redirect_back_to_url)
/*
===========================================================================
YOU MUST MODIFY THIS FUNCTION, BUT CAN DO SO AFTER Q2A CREATES ITS DATABASE
===========================================================================
 
You should return an array containing URLs for the login, register and logout pages on
your site. These URLs will be used as appropriate within the Q2A site.
 
You may return absolute or relative URLs for each page. If you do not want one of the links
to show, omit it from the array, or use null or an empty string.
 
If you use absolute URLs, then return an array with the URLs in full (see example 1 below).
 
If you use relative URLs, the URLs should start with $relative_url_prefix, followed by the
relative path from the root of the Q2A site to your login page. Like in example 2 below, if
the Q2A site is in a subdirectory, $relative_url_prefix.'../' refers to your site root.
 
Now, about $redirect_back_to_url. Let's say a user is viewing a page on the Q2A site, and
clicks a link to the login URL that you returned from this function. After they log in using
the form on your main site, they want to automatically go back to the page on the Q2A site
where they came from. This can be done with an HTTP redirect, but how does your login page
know where to redirect the user to? The solution is $redirect_back_to_url, which is the URL
of the page on the Q2A site where you should send the user once they've successfully logged
in. To implement this, you can add $redirect_back_to_url as a parameter to the login URL
that you return from this function. Your login page can then read it in from this parameter,
and redirect the user back to the page after they've logged in. The same applies for your
register and logout pages. Note that the URL you are given in $redirect_back_to_url is
relative to the root of the Q2A site, so you may need to add something.
*/
{
/*
// Until you edit this function, don't show login, register or logout links
 
return array(
'login' => null,
'register' => null,
'logout' => null
);
 
 
Example 1 - using absolute URLs, suitable if:
 
* Your Q2A site:       http://qa.mysite.com/
* Your login page:     http://www.mysite.com/login
* Your register page:  http://www.mysite.com/register
* Your logout page:    http://www.mysite.com/logout
*/
return array(
);
 
 
 
/*
Example 2 - using relative URLs, suitable if:
 
* Your Q2A site:       http://www.mysite.com/qa/
* Your login page:     http://www.mysite.com/login.php
* Your register page:  http://www.mysite.com/register.php
* Your logout page:    http://www.mysite.com/logout.php
 
return array(
'login' => $relative_url_prefix.'../login.php',
'register' => $relative_url_prefix.'../register.php',
'logout' => $relative_url_prefix.'../logout.php',
);
*/
 
/*
Example 3 - using relative URLs, and implementing $redirect_back_to_url
 
In this example, your pages login.php, register.php and logout.php should read in the
parameter $_GET['redirect'], and redirect the user to the page specified by that
parameter once they have successfully logged in, registered or logged out.
 
return array(
'login' => $relative_url_prefix.'../login.php?redirect='.urlencode('qa/'.$redirect_back_to_url),
'register' => $relative_url_prefix.'../register.php?redirect='.urlencode('qa/'.$redirect_back_to_url),
'logout' => $relative_url_prefix.'../logout.php?redirect='.urlencode('qa/'.$redirect_back_to_url),
);
*/
 
}
 
Q2A version: latest version

1 Answer

0 votes
by
Hi there sushant

Firstly I am responding here because I am pretty sure you won't get a respose from a php expert. The out-of-the-box install is easy - works perfectly but: While trying to get sso working I've scoured the net for help and concluded that you need a level understanding/skill with php. I'm putting in the time cause I need that anyway. Anyway, my non-expert advice is  either pay someone to help or be prepared.

FYI I was struggling with the logic. Out of frustration I decided to get rid of it. I needed to see it working so I simply hard coded the result arrays with actual values for a real user of my main site. It worked! (Q2A SSO for one user). That gave me confidence to go back and modify the code using cookie and session variables etc methods from my site login code and mysql tables. It's looking a lot less mysterious now.

cheers and good luck
by
Thanks for the reply.

Wow! all this went over my non-techie head... I guess I'll have to get help!
I asked around and it seems the older versions had an easier install.
by
sushant I may have misunderstood your question. are you trying to get single sign (SSO) on working (the only reason to edit qa-external-users) or just a straight forward install with login handled by Q2A?
by
A straightforward install with login handled by Q2A ...

So basically I installed Q2A but was not able to even access the admin panel because it wants me to login and the only way I could figure out was by editing qa-external-users.

Maybe I should try and re-install without any changes except the config.php file??
by
edited by
Yes exactly! You don't want qa-external users, and make sure in qa-config.php this line is like this: ('QA_EXTERNAL_USERS', False);
Make sure you have a database with no qa_ tables in it and the connection you set it in qa-config.php works. If install fails go back over your edits to qa-config.php
I also deleted the qa tables whenever I needed to reinstall.
To install just point the browser to the Q2A folder and you should get the install dialog. The database will be set up for you (using the credentials you supplied to qa-config) and you will be prompted to log in as admin.
When in Q2A look for the extra admin menu item at right.
If this fails at any stage go back and check your edits. Keep fresh copies of the original files before editing and be prepared to start again if necessary. If comments say you can do this later then don't edit until you have success as above. Nothing will work without that db connection. You will need to know phpmyadmin basics at least. Easy. Cheers

and I must add that it's all well worth it - my thanks to gidgreen for a brilliant application
...