Sorry about that.
I need to set up an external webservice function that logs the user into the system.
Currently this is what I've done and it works but is there a better way to do this?
/**
* Returns description of method parameters
*
* @return external_function_parameters
* @since Moodle 2.2
*/
public static function autologin_parameters() {
return new external_function_parameters(
array('username' => new external_value(PARAM_RAW, 'user name'))
);
}
/**
* Logs the user into into the system
*
* @return external_function_parameters
* @since Moodle 2.2
*/
public static function autologin($username){
require_once('../../config.php');
global $CFG;
?>
<form id="loginform" action="<?php echo $CFG->wwwroot.'/login/index.php' ?>" method="post" style="display:none">
<input type="hidden" name="username" value="<?php echo $username ?>"> <br>
<input type="hidden" name="password" value="pass1234"> <br>
</form>
<script type="text/javascript">
document.getElementById('loginform').submit(); // SUBMIT FORM
</script>
<?php
}
/**
* Returns description of method result value
*
* @return external_description
* @since Moodle 2.2
*/
public static function autologin_returns() {
return new external_value(PARAM_RAW, 'The username of the user to be logged in');
}
What I've done is added a form into the function and submitted the form using javascript and then the user is logged in and redirected into moodle. The return is pretty irrelevant as the user gets redirected into the system.
I get my desired results but I'm sure this isn't the most effective/best way of doing this, or is it?