I want to write a authentication plugin to programmatically login a certain user according to a username&uniquetoken mapping database table. My steps are as below:
- When a user access Moodle site in a special browser, I can get the uniquetoken of the user without Moodle's context;
- In the pre_login_page hook of my custom authentication plugin, I query the username from the database table where username=uniquetoken , if have valid result, then complete_user_login($user), else 3 as below:
- The login form page is displayed for the anonymous user, he input his credential, if valid, I want to save the uniquetoken from the special browser into the database table of the username-uniquetoken mapping. At this point, which hook is right? pre_user_login_hook or user_authenticated_hook? And can HTTP requests and DB queries be executed in these 2 hooks of one of them?