Commit 3fe35770 by ichuang Committed by Justin Riley

add http basic auth to proctor panel interface

parent ca4ca008
...@@ -19,11 +19,21 @@ log = logging.getLogger('mitx.' + __name__) ...@@ -19,11 +19,21 @@ log = logging.getLogger('mitx.' + __name__)
class ProctorPanel(object): class ProctorPanel(object):
''' '''
Interface to proctor panel system, which determines if a given proctored item Interface to proctor panel system, which determines if a given proctored item
(specified by its procset_name) is released to a given student (specified by the (specified by its procset_name) is released to a given student.
user_id).
The LMS configuration should come with a dict which specifies the proctor panel
server information, eg:
PROCTOR_PANEL_INTERFACE = {
'url' : "http://192.168.42.6",
'username' : 'lms',
'password' : 'abcd',
}
''' '''
ProctorPanelServer = getattr(settings, 'PROCTOR_PANEL_SERVER_URL', 'https://proctor.mitx.mit.edu') ProctorPanelInterface = getattr(settings, 'PROCTOR_PANEL_INTERFACE', {})
ProctorPanelServer = ProctorPanelInterface.get('url', "")
def __init__(self, user_id, procset_name): def __init__(self, user_id, procset_name):
...@@ -36,7 +46,8 @@ class ProctorPanel(object): ...@@ -36,7 +46,8 @@ class ProctorPanel(object):
url = '{2}/cmd/status/{0}/{1}'.format(self.user_id, self.procset_name, self.ProctorPanelServer) url = '{2}/cmd/status/{0}/{1}'.format(self.user_id, self.procset_name, self.ProctorPanelServer)
log.info('ProctorPanel url={0}'.format(url)) log.info('ProctorPanel url={0}'.format(url))
#ret = self.ses.post(url, data={'userid' : self.user_id, 'urlname': self.procset_name}, verify=False) #ret = self.ses.post(url, data={'userid' : self.user_id, 'urlname': self.procset_name}, verify=False)
ret = self.ses.get(url, verify=False) auth = (self.ProctorPanelInterface.get('username'), self.ProctorPanelInterface.get('password'))
ret = self.ses.get(url, verify=False, auth=auth)
try: try:
retdat = json.loads(ret.content) retdat = json.loads(ret.content)
except Exception as err: except Exception as err:
...@@ -49,7 +60,6 @@ class ProctorPanel(object): ...@@ -49,7 +60,6 @@ class ProctorPanel(object):
class ProctorFields(object): class ProctorFields(object):
username = String(help="username of student", scope=Scope.user_state)
procset_name = String(help="Name of this proctored set", scope=Scope.settings) procset_name = String(help="Name of this proctored set", scope=Scope.settings)
...@@ -66,7 +76,7 @@ class ProctorModule(ProctorFields, XModule): ...@@ -66,7 +76,7 @@ class ProctorModule(ProctorFields, XModule):
runs out, exam access closes. runs out, exam access closes.
Example: Example:
<proctor procset_name="proctorset1"> <proctor procset_name="Proctored Exam 1">
<sequential url_name="exam1" /> <sequential url_name="exam1" />
</proctor> </proctor>
......
...@@ -24,8 +24,27 @@ procrel = (function(){ ...@@ -24,8 +24,27 @@ procrel = (function(){
statel.html('<font color="green">' + status + '</font>'); statel.html('<font color="green">' + status + '</font>');
} }
var do_pp_get = function(cmd, gfun){
$.ajax({ url: mkurl(cmd),
type: 'GET',
data: { "uname": "${pp.user.username}",
"name": "${pp.user.profile.name}"
},
xhrFields: {
withCredentials: true
},
username: "${pp.ProctorPanelInterface.get('username')}",
password: "${pp.ProctorPanelInterface.get('password')}",
success: gfun,
dataType: "json",
error: function(xhr, status, error) {
alert('Error: cannot connect to server' + status + "error:" + error);
}
});
}
var check_access = function(){ var check_access = function(){
$.get(mkurl('status'), function(data){ do_pp_get('status', function(data){
console.log(data); console.log(data);
if (data.enabled) { if (data.enabled) {
alert ("Access Granted!"); alert ("Access Granted!");
...@@ -46,31 +65,15 @@ procrel = (function(){ ...@@ -46,31 +65,15 @@ procrel = (function(){
var make_request = function(){ var make_request = function(){
check_count = 0; check_count = 0;
do_pp_get('request', function(result, status, xhr){
$.ajax({ url: mkurl('request'),
type: 'GET',
data: { "uname": "${pp.user.username}",
"name": "${pp.user.profile.name}"
},
success: function(result, status, xhr){
//setstat(result.status);
setstat(result.status); setstat(result.status);
//alert(result);
// location.reload();
periodic_check(); periodic_check();
}, });
//dataType: "text",
dataType: "json",
// crossDomain: true,
error: function(xhr, status, error) {
alert('Error: cannot connect to server' + status + "error:" + error);
}
});
} }
el.click(make_request); el.click(make_request);
return { "check": check_access, "make": make_request, "mkurl": mkurl }; return { "check": check_access, "make": make_request, "mkurl": mkurl, "do_pp_get": do_pp_get };
}() ); }() );
</script> </script>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment