Processing Moodle Signup and Login form my website Singup and Login Page.

Processing Moodle Signup and Login form my website Singup and Login Page.

John Cargodən -
Number of replies: 9

Hi,

I have website where there is login and signup form. Now, I wanted to interlink my signup and login form with moodle database too.

i.e, I have my separate database table for `user`, and after installing moodle in my server, there is separate `mdl_user` table. Luckily, required column name matches with my website `user` table.

But I am not able to process singup and login for moodle. What i want are :-

1. When anyone register to my website, I will insert all user details to my `user` table and `mdl_user` table too.

2. When anyone changes / reset his password / email, I will update `mdl_user` and my `user` table too.

3. I need all session and cookies name , that are set when user is successfully verified and is logged in.

 

Problem that i am currently facing :-

1. I am not sure, what encryption type moodle uses to store `password` in `mdl_user` table. I am using `PHPass` from openwall. This is important for me, as if anytime user login to moodle directly without my website login form. He should be logged in with no-error. Therefore i need to know, how moodle encrypts the password and stores it in `mdl_user` table.

2. What are all session name, cookies name that are set when user is successfully verified.

 

If there are any other problem too, which i am not aware of at the moment, Please guide me. I will do all recommended steps to integrate my site login & signup with moodle database sql-query.

 

Thanks

Orta qiymət: -
In reply to John Cargo

Re: Processing Moodle Signup and Login form my website Singup and Login Page.

John Gifforddən -

Hi John

I think Moodle uses MD5 encryption on the password, I've certainly pasted an MD5 password direct into the mdl_user table when I reset my password and it worked.

Just suggestions, but if you've got the user details logging into your website and they are identical to what Moodle uses then what about including an extra step in the php file that creates the user for your website, easier than trying to hack Moodle, believe me! You might need to re-encrypt the password they register with to MD5 for Moodle, but essentially

e.g.
$query=mysql_query("insert into user (<fields>) VALUES (<user details>)"); //add user to the website

$query2=mysql_query("insert into mdl_user (<fields>) VALUES (<user details>)"); //add user to moodle

assuming you're using php and mysql that is. Then you redirect the login page for moodle to an alternate login page, your website login page. That can be done through the site admin settings in Moodle.
It might not be single-sign on, but it should add the user simultaneously to both the mdl_user and user tables when they register.
If you want more flash then setup some session variables for the username and password that match Moodle's session variables you could have an effective single sign-on as the user would login to your website which would create the session variables and then because the variables are set already the user would be automatically logged into Moodle ???

Updating e-mail addresses in moodle - what about a scheduled job/cron job? It processes a php file that connects to both database tables compares mdl_user to user and updates one to the other where there is a difference, depends where they change their e-mail address of course. That cron job can then be run every so often (5 minutes, 30 minutes, on the hour etc.) even overnight if you've got a lot of users and it should mean that your e-mail addresses are up-to-date, and if they're not just wait for the next cron job execution, or manually run the cron job yourself (might be a problem if it's an overnight thing and it's checking 1000s of users).

It might not be particularly elegant and I'm sure there's better ways to handle it. But that would be my suggestion.

 

In reply to John Gifford

Re: Processing Moodle Signup and Login form my website Singup and Login Page.

John Cargodən -

Thanks John Gifford for `md5` tips.

 

Do you know, what are `Session names & cookie name` set after successful registration or Login. So, that i can setup those session too. Once authentication is done.

 

Thanks

In reply to John Cargo

Re: Processing Moodle Signup and Login form my website Singup and Login Page.

Darko Miletićdən -

Your approach is wrong. One should never do integration in that way. The right way would be to store users in separate store and link both systems to that. Moodle already fully supports SSO with CAS or Shibboleth and user account sync.

http://docs.moodle.org/26/en/CAS_server_(SSO)

http://docs.moodle.org/26/en/Shibboleth

If this does not satisfy your needs a custom development would be in order but it should be handled through custom authentication plugin, not directly drilling in the database.

In reply to Darko Miletić

Re: Processing Moodle Signup and Login form my website Singup and Login Page.

John Cargodən -

Can you please tell me, What is wrong in my Approach. Options that you have listed may be good for few scenario. But may not be Good for all. 

In my Scenario, I see it as - `few column of mdl_user` table being copied first in `user` table. And Session, Cookies of my moodle installation are set from my web-application. So that If in any time, User opens any page of moodle, he gets message of "logged in" , instead of "login".

 

Please tell me actions or event that is going wrong in my approach.

 

Thanks

In reply to John Cargo

Re: Processing Moodle Signup and Login form my website Singup and Login Page.

Darko Miletićdən -

Approach is wrong because you attempt to do everything outside of moodle by directly validating data through direct access to tables. That is never good approach even though it might work. As soon as Moodle core gets updated you will have to update your code to handle that update etc. (for example Moodle no longer uses md5 for password hashes etc.) Moodle should do moodle stuff and your app should handle its own stuff.

If you want to do it the recommended Moodle way, this is how I would do it:

Build a web service on your side that is able to provide user profile information from your system.

Build a Moodle authentication plugin that has integrated client for that web service.

When user log's in into your system you do a AJAX call to Moodle with some special parameters etc. pointing to the login page. (<moodle>/login/index.php). Implement in your authentication plugin loginpage_hook and do the check of the passed parameters somehow. If parameters are OK and user account exists in moodle login the user using authentication API. If user account does not exist call your web service to get user data, create user account and log it in.

With this you have clear separation on what is done by each system and they remain separate as they should. If anything changes in Moodle you just update authentication plugin. 

 

In reply to Darko Miletić

Re: Processing Moodle Signup and Login form my website Singup and Login Page.

John Cargodən -

Thanks for your great Suggestion. Will study it later. 

For now, Do you know, what are all session and cookie name set in moodle after successful login.

 

Thanks

In reply to John Cargo

Re: Processing Moodle Signup and Login form my website Singup and Login Page.

Darko Miletićdən -

No. I never tried to do that thing outside of moodle code. The user login is performed in Moodle by complete_user_login function located in lib/moodlelib.php . You can study that one to check what is being done and where. 

In reply to Darko Miletić

Re: Processing Moodle Signup and Login form my website Singup and Login Page.

John Gifforddən -

Thanks Darko you learn something new every day.

I did admit though it was only a suggestion...

In reply to John Gifford

Re: Processing Moodle Signup and Login form my website Singup and Login Page.

Darko Miletićdən -

No harm done. This is a place for asking and getting answers. And I'm not angry or anything just sometimes to direct in my writings gülürəm And we all learn new things every day. If not it would be rather dull enterprise working with Moodle.