Commit c9c38bc3 authored by Robert Czechowski's avatar Robert Czechowski
Browse files

Submit grades in task submissions

parent 0daaca81
......@@ -226,7 +226,7 @@ pub fn load_submission<T: MedalConnection>(conn: &T, task_id: u32, session_token
}
}
pub fn save_submission<T: MedalConnection>(conn: &T, task_id: u32, session_token: String, csrf_token: String, data: String) -> MedalResult<String> {
pub fn save_submission<T: MedalConnection>(conn: &T, task_id: u32, session_token: String, csrf_token: String, data: String, grade: u32) -> MedalResult<String> {
let session = conn.get_session(session_token).ok_or(MedalError::AccessDenied)?.ensure_alive().ok_or(MedalError::AccessDenied)?; // TODO SessionTimeout
if session.csrf_token != csrf_token {
......@@ -237,9 +237,9 @@ pub fn save_submission<T: MedalConnection>(conn: &T, task_id: u32, session_token
id: None,
session_user: session.id,
task: task_id,
grade: 0,
grade: grade,
validated: false,
nonvalidated_grade: 0,
nonvalidated_grade: grade,
needs_validation: true,
subtask_identifier: None,
value: data,
......
......@@ -408,10 +408,12 @@ fn submission(req: &mut Request) -> IronResult<Response> {
fn submission_post(req: &mut Request) -> IronResult<Response> {
let task_id = req.expect_int::<u32>("taskid")?;
let session_token = req.expect_session_token()?;
let (csrf_token, data) = {
let (csrf_token, data, grade) = {
let formdata = iexpect!(req.get_ref::<UrlEncodedBody>().ok());
(iexpect!(formdata.get("csrf"),(status::BadRequest, mime!(Text/Html), format!("400 Bad Request")))[0].to_owned(),
iexpect!(formdata.get("data"),(status::BadRequest, mime!(Text/Html), format!("400 Bad Request")))[0].to_owned())
iexpect!(formdata.get("data"),(status::BadRequest, mime!(Text/Html), format!("400 Bad Request")))[0].to_owned(),
iexpect!(formdata.get("grade").unwrap_or(&vec!["0".to_owned()])[0].parse::<u32>().ok(),(status::BadRequest, mime!(Text/Html), format!("400 Bad Request"))),
)
};
println!("{}",data);
println!("{}",task_id);
......@@ -419,7 +421,7 @@ fn submission_post(req: &mut Request) -> IronResult<Response> {
let result = {
let mutex = req.get::<Write<SharedDatabaseConnection>>().unwrap();
let conn = mutex.lock().unwrap_or_else(|e| e.into_inner());
functions::save_submission(&*conn, task_id, session_token, csrf_token, data)
functions::save_submission(&*conn, task_id, session_token, csrf_token, data, grade)
};
match result {
......
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