-
Notifications
You must be signed in to change notification settings - Fork 2
/
moodle_login.htm
82 lines (68 loc) · 2.69 KB
/
moodle_login.htm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<html>
<head>
<script>
function post_to_url(path, params, method)
{
method = method || "post"; // Set method to post by default, if not specified.
// The rest of this code assumes you are not using a library.
// It can be made less wordy if you use one.
var form = document.createElement("form");
form.setAttribute("method", method);
form.setAttribute("action", path);
//form.setAttribute("target", "_self");
form.setAttribute("enctype", "application/x-www-form-urlencoded");
for(var key in params)
{
if(params.hasOwnProperty(key))
{
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", key);
hiddenField.setAttribute("value", params[key]);
form.appendChild(hiddenField);
}
}
document.body.appendChild(form);
form.submit();
}
function showError(message)
{
document.body.innerHTML = message + "<BR/><A HREF=\"https://sites.google.com/site/tauscripts/home/moodlelogin\">Check the instructions here.</A>";
}
function doPost()
{
var username;
var password;
var userid;
// parse url parameters
var query = window.location.search.substring(1);
var args = query.split("&");
if(args.length != 3)
return showError("You must specify user, pass & id parameters in URL.");
for (var i=0;i<args.length;i++) {
var pair = args[i].split("=");
if(pair.length != 2)
return showError("You have an error in one of the url parameters.");
var name = pair[0].valueOf();
var value = pair[1].valueOf();
value = decodeURIComponent(value);
if(name == "user")
username = value;
else if (name == "pass")
password = value;
else if (name == "id")
userid = value;
}
post_to_url('https://nidp.tau.ac.il/nidp/saml2/sso?sid=1', {'Ecom_User_ID':username, 'Ecom_User_Pid':userid, 'Ecom_Password':password, 'option':'credential'}, 'post');
}
</script>
</head>
<body>
<html>
Please wait while Moodle loads...
<script>
doPost();
</script>
</html>
</body>
</html>