Login using REST webservice

Login using REST webservice

by Rajapandian S -
Number of replies: 0

Hi,

I had created manual webservice called login_check. Which is used to check the given/passed username and password is correct/wrong.

I passed the credentials from the core php file. If the credentials is valid, then the user have to logged in to the moodle site.

Now the values are passed into the function login_check(in moodle server) by REST url from core PHP file to moodle server.

User authenticate is successful and I got return success message but session is not maintained in the moodle server.

After user validate I opened login form in moodle server in the new tab of the browser, it is still not logged in and shows me login form. If my validate is correct it has to open the login page with two confirm button.

I dont know what I did wrong. 


public static function login_check($userdata) {

        global $DB,$CFG;        

        $params = self::validate_parameters(self::login_check_parameters(), array('userdata'=>$userdata));

        $dbauth = get_auth_plugin('webservice');

        $user_valid = $dbauth->user_login_webservice($userdata['username'], $userdata['password']);

        if($user_valid){

              $userss = authenticate_user_login($userdata['username'], $userdata['password']);

              $user1 = get_complete_user_data('id', $userss->id);

              complete_user_login($user1);

              \core\session\manager::apply_concurrent_login_limit($user1->id, session_id());

              if (isset($SESSION->wantsurl) and (strpos($SESSION->wantsurl, $CFG->wwwroot) == 0)) {

                     // the URL is set and within Moodle's environment

                    $urltogo = $SESSION->wantsurl;

                     unset($SESSION->wantsurl);

               } else {   // no wantsurl stored or external link. Go to homepage.

                      $urltogo = $CFG->wwwroot . '/';

                      unset($SESSION->wantsurl); 

               }

              if (isloggedin()) {

                           return 'Login Success';

                }

             return 'Login failed';

   }else{

         return 'Login failed';

   }

}

For the above code I always get 'Login Success' message. For the user(send from core PHP) auth method is manual. In the user table, fields like "lastlogin,lastaccess,currentlogin" are updated everytime when I send request for core PHP.


Please help me guys.

Average of ratings: -