Best way to allow access to multiple unknown users without site guest access

Re: Best way to allow access to multiple unknown users without site guest access

by Dominique Bauer -
Number of replies: 0
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers
Hello Tine,

Here is the code to skip the login page, while doing the login for students in the background:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>
<script>
var role= localStorage.getItem("role"); 
$(document).ready(function() {
    if ($(location).attr('href') == "https://yourdomainname/login/index.php" ||  $(location).attr('href') == "https://yourdomainname/login" ||  $(location).attr('href') == "https://yourdomainname/login/index.php?") {
        if (role== "administrator") {
            $("#username").val("yourgenericusername");
            $("#password").val("yourgenericpassword");
        } else {
            $("body").css("display","none");
            localStorage.setItem("role", "student");
            $("#username").val("yourgenericusername");
            $("#password").val("yourgenericpassword");
            $("button#loginbtn").trigger("click");
        }
    }
});
</script>

To access the site as an administrator, place a label for example in an inconspicuous place on the front page, containing the following code. Make sure to prepare this label first, otherwise you may not be able to easily access the site other than as a student.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>
<script>
localStorage.setItem("role", "student");
function admin0() {
    localStorage.setItem("role", "administrator");
    url = "https://yourdomainname/login/index.php";
    $(location).attr("href", url); 
} 
</script>
<p onclick="admin0()" style="color:#aaa;">Administrator access</p>

This may be too fast for some students who are used to having difficulty loging in. With this script, they are instantly logged in without even realizing it. smile

Average of ratings: Useful (1)