Quantcast
Channel: Authentication
Viewing all articles
Browse latest Browse all 8256

Re: customize login page for specific course

$
0
0
by Andranik Sharabchian.  

Hi Yoni,

You can't have login page for the specific course, because for accessing the course you must be authenticated in Moodle. You can only automatically redirect to the specific course after logging in Moodle. You can do this by this way.

1. Copy your .../moodle/login/index.php to index2.php in the same place.

2. Change this section of your code in index2.php

/// Prepare redirection
if (user_not_fully_set_up($USER)) {
$urltogo = $CFG->wwwroot.'/user/edit.php';
// We don't delete $SESSION->wantsurl yet, so we get there later
} else if (isset($SESSION->wantsurl) and (strpos($SESSION->wantsurl, $CFG->wwwroot) === 0)) {
$urltogo = $SESSION->wantsurl;    /// Because it's an address in this site
unset($SESSION->wantsurl);
} else {
// no wantsurl stored or external - go to homepage
$urltogo = $CFG->wwwroot.'/';
unset($SESSION->wantsurl);
}

by this section

/// Prepare redirection

if (user_not_fully_set_up($USER)) {
$urltogo = $CFG->wwwroot.'/user/edit.php';
// We don't delete $SESSION->wantsurl yet, so we get there later

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

/// Because it's an address in this site
unset($SESSION->wantsurl);
} else {
// no wantsurl stored or external - go to homepage
$urltogo = $CFG->wwwroot.$_POST['courseurl'];
unset($SESSION->wantsurl);
}

3. And finally write this code for your alternative loginpage.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script language="javascript">

function gotocourse(){
document.getElementById("courseurl").value = "/course/view.php?id=yourcourseid";
document.getElementById("loginForm").submit();

return true;

}

</script>

</head>

<body>
<form action="http://yourmoodle.com/moodle/login/index2.php" method="post" id="loginForm" target="_self">

<input type="hidden" name="username" id="username" size="15" value="your_user_name" />
<input type="hidden" name="password" id="password" size="15" value="your_user_password" />
<input type="hidden" name="rememberusername" id="rememberusername" value="1" checked="checked" />

<input type="button" name="direct login" value="login" onClick="gotocourse()"> 

<input type="hidden" name ="courseurl" id="courseurl"/>

</form>

</body>

</html>

P. S. HTML code isn't tested. I hope this can help you.


Viewing all articles
Browse latest Browse all 8256

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>