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

we are trying to integrate q2a to an existing application where users login with their email and a password.

What is a good approach to tackle the problem of assigning a username/nickname?

We are thinking of customizing q2a so that it prompts the user for a nickname the first time he tries to post a question or an answer.

What do you think? Is there a "clean" way to do this (maybe as a plugin) without too much hacking of the codebase?

cheers

1 Answer

+2 votes
by
 
Best answer

If the existing app assigns user ids, perhaps the following strategy would work?

  • You build your own additional 'join' table, linking the user id of the user in the existing app to a username. You will want to add this in the original app's database, if you're not sharing the database with your Q2A install.
     
  • In the external authentication code for Q2A, in all the relevant queries, you will need to do a SQL join between the existing user table and your new table. Do a left join in qa_get_logged_in_user(). If the username from the join is null, this will also count as not-logged-in.
     
  • Q2A allows you to specify register/login/logout links. So you could write your own intermediate login screen - say it is /myqalogin.php. Its job would be to check to see if you are logged in on the existing app, by checking for the appropriate cookie or whatever. If you are not, it would pass you to the login screen of the application, doing whatever is necessary to get it to come back to /myqalogin.php when you're logged in.
     
  • If you are logged in, it would check to see whether there is a username entry for the existing app's user id in your new join table. If so, then it redirects back to Q2A. If not, prompt them for a username in a form,  check it's unique on submission, and if so, store it, and bounce them back to the Q2A site.

This is a bit of a sketchy outline; hope it helps.

by
thanks! we ended up doing a normal sso based on the template php file for external users. Then we customized the question form to also ask for a username for users that have not set one yet. Not very clean as we would have to reapply it every time we want to upgrade to a new version of q2a but it works.
...