Commit ad4919ad authored by Daniel Brüning's avatar Daniel Brüning
Browse files

replaced som Strings by &str

parent 4f828663
Pipeline #155 passed with stage
in 6 minutes and 59 seconds
......@@ -173,7 +173,7 @@ fn generate_subtaskstars(tg: &Taskgroup, grade: &Grade, ast: Option<u32>) -> Vec
subtaskinfos
}
pub fn show_contest<T: MedalConnection>(conn: &T, contest_id: u32, session_token: String) -> MedalValueResult {
pub fn show_contest<T: MedalConnection>(conn: &T, contest_id: u32, session_token: &str) -> MedalValueResult {
let c = conn.get_contest_by_id_complete(contest_id);
let grades = conn.get_contest_user_grades(&session_token, contest_id);
......@@ -249,7 +249,7 @@ pub fn show_contest<T: MedalConnection>(conn: &T, contest_id: u32, session_token
}
}
pub fn show_contest_results<T: MedalConnection>(conn: &T, contest_id: u32, session_token: String) -> MedalValueResult {
pub fn show_contest_results<T: MedalConnection>(conn: &T, contest_id: u32, session_token: &str) -> MedalValueResult {
let session = conn.get_session(&session_token)
.ok_or(MedalError::AccessDenied)?
.ensure_alive()
......@@ -303,7 +303,7 @@ pub fn show_contest_results<T: MedalConnection>(conn: &T, contest_id: u32, sessi
}
//TODO: use csrf_token
pub fn start_contest<T: MedalConnection>(conn: &T, contest_id: u32, session_token: String, _csrf_token: String)
pub fn start_contest<T: MedalConnection>(conn: &T, contest_id: u32, session_token: &str, _csrf_token: &str)
-> MedalResult<()> {
//TODO: use data or remove?
let _data = json_val::Map::new();
......@@ -331,7 +331,7 @@ pub fn login<T: MedalConnection>(conn: &T, login_data: (String, String)) -> Resu
}
pub fn login_with_code<T: MedalConnection>(
conn: &T, code: String)
conn: &T, code: &str)
-> Result<Result<String, String>, (String, json_val::Map<String, json_val::Value>)> {
match conn.login_with_code(None, &code) {
Ok(session_token) => Ok(Ok(session_token)),
......@@ -351,7 +351,7 @@ pub fn logout<T: MedalConnection>(conn: &T, session_token: Option<String>) {
session_token.map(|token| conn.logout(&token));
}
pub fn load_submission<T: MedalConnection>(conn: &T, task_id: u32, session_token: String, subtask: Option<String>)
pub fn load_submission<T: MedalConnection>(conn: &T, task_id: u32, session_token: &str, subtask: Option<String>)
-> MedalResult<String> {
let session = conn.get_session(&session_token)
.ok_or(MedalError::AccessDenied)?
......@@ -367,7 +367,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,
pub fn save_submission<T: MedalConnection>(conn: &T, task_id: u32, session_token: &str, csrf_token: &str,
data: String, grade: u8, subtask: Option<String>)
-> MedalResult<String>
{
......@@ -396,7 +396,7 @@ pub fn save_submission<T: MedalConnection>(conn: &T, task_id: u32, session_token
Ok("{}".to_string())
}
pub fn show_task<T: MedalConnection>(conn: &T, task_id: u32, session_token: String) -> MedalValueResult {
pub fn show_task<T: MedalConnection>(conn: &T, task_id: u32, session_token: &str) -> MedalValueResult {
let session = conn.get_session_or_new(&session_token).ensure_alive().ok_or(MedalError::AccessDenied)?; // TODO SessionTimeout
let (t, tg, c) = conn.get_task_by_id_complete(task_id);
......@@ -473,7 +473,7 @@ pub struct GroupInfo {
pub code: String,
}
pub fn show_groups<T: MedalConnection>(conn: &T, session_token: String) -> MedalValueResult {
pub fn show_groups<T: MedalConnection>(conn: &T, session_token: &str) -> MedalValueResult {
let session = conn.get_session_or_new(&session_token).ensure_logged_in().ok_or(MedalError::NotLoggedIn)?;
// let groupvec = conn.get_group(session_token);
......@@ -503,7 +503,7 @@ pub struct MemberInfo {
pub logincode: String,
}
pub fn show_group<T: MedalConnection>(conn: &T, group_id: u32, session_token: String) -> MedalValueResult {
pub fn show_group<T: MedalConnection>(conn: &T, group_id: u32, session_token: &str) -> MedalValueResult {
let session = conn.get_session_or_new(&session_token).ensure_logged_in().ok_or(MedalError::NotLoggedIn)?;
let group = conn.get_group_complete(group_id).unwrap(); // TODO handle error
......@@ -534,11 +534,11 @@ pub fn show_group<T: MedalConnection>(conn: &T, group_id: u32, session_token: St
Ok(("group".to_string(), data))
}
pub fn modify_group<T: MedalConnection>(_conn: &T, _group_id: u32, _session_token: String) -> MedalResult<()> {
pub fn modify_group<T: MedalConnection>(_conn: &T, _group_id: u32, _session_token: &str) -> MedalResult<()> {
unimplemented!()
}
pub fn add_group<T: MedalConnection>(conn: &T, session_token: String, csrf_token: String, name: String, tag: String)
pub fn add_group<T: MedalConnection>(conn: &T, session_token: &str, csrf_token: &str, name: String, tag: String)
-> MedalResult<u32> {
let session = conn.get_session(&session_token)
.ok_or(MedalError::AccessDenied)?
......@@ -568,7 +568,7 @@ pub fn add_group<T: MedalConnection>(conn: &T, session_token: String, csrf_token
}
#[allow(dead_code)]
pub fn show_groups_results<T: MedalConnection>(conn: &T, contest_id: u32, session_token: String) -> MedalValueResult {
pub fn show_groups_results<T: MedalConnection>(conn: &T, contest_id: u32, session_token: &str) -> MedalValueResult {
let session = conn.get_session_or_new(&session_token).ensure_logged_in().ok_or(MedalError::NotLoggedIn)?;
//TODO: use g
let _g = conn.get_contest_groups_grades(session.id, contest_id);
......@@ -578,7 +578,7 @@ pub fn show_groups_results<T: MedalConnection>(conn: &T, contest_id: u32, sessio
Ok(("groupresults".into(), data))
}
pub fn show_profile<T: MedalConnection>(conn: &T, session_token: String, user_id: Option<u32>,
pub fn show_profile<T: MedalConnection>(conn: &T, session_token: &str, user_id: Option<u32>,
query_string: Option<String>)
-> MedalValueResult
{
......@@ -671,7 +671,7 @@ impl std::convert::Into<String> for ProfileStatus {
fn into(self) -> String { format!("{:?}", self) }
}
pub fn edit_profile<T: MedalConnection>(conn: &T, session_token: String, user_id: Option<u32>, csrf_token: String,
pub fn edit_profile<T: MedalConnection>(conn: &T, session_token: &str, user_id: Option<u32>, csrf_token: &str,
firstname: String, lastname: String, street: Option<String>,
zip: Option<String>, city: Option<String>, password: Option<String>,
password_repeat: Option<String>, grade: u8)
......
......@@ -318,7 +318,7 @@ fn contest(req: &mut Request) -> IronResult<Response> {
let contest_id = req.expect_int::<u32>("contestid")?;
let session_token = req.require_session_token()?;
let (template, data) = with_conn![functions::show_contest, req, contest_id, session_token].aug(req)?;
let (template, data) = with_conn![functions::show_contest, req, contest_id, &session_token].aug(req)?;
let mut resp = Response::new();
resp.set_mut(Template::new(&template, data)).set_mut(status::Ok);
......@@ -329,7 +329,7 @@ fn contestresults(req: &mut Request) -> IronResult<Response> {
let contest_id = req.expect_int::<u32>("contestid")?;
let session_token = req.require_session_token()?;
let (template, data) = with_conn![functions::show_contest_results, req, contest_id, session_token].aug(req)?;
let (template, data) = with_conn![functions::show_contest_results, req, contest_id, &session_token].aug(req)?;
let mut resp = Response::new();
resp.set_mut(Template::new(&template, data)).set_mut(status::Ok);
......@@ -346,7 +346,7 @@ fn contest_post(req: &mut Request) -> IronResult<Response> {
};
// TODO: Was mit dem Result?
with_conn![functions::start_contest, req, contest_id, session_token, csrf_token].aug(req)?;
with_conn![functions::start_contest, req, contest_id, &session_token, &csrf_token].aug(req)?;
Ok(Response::with((status::Found, Redirect(url_for!(req, "contest", "contestid" => format!("{}",contest_id))))))
}
......@@ -403,7 +403,7 @@ fn login_code_post(req: &mut Request) -> IronResult<Response> {
// TODO: Submit current session to login
let loginresult = with_conn![functions::login_with_code, req, code];
let loginresult = with_conn![functions::login_with_code, req, &code];
println!("aa");
match loginresult {
......@@ -445,7 +445,7 @@ fn submission(req: &mut Request) -> IronResult<Response> {
println!("{}", task_id);
let result = with_conn![functions::load_submission, req, task_id, session_token, subtask];
let result = with_conn![functions::load_submission, req, task_id, &session_token, subtask];
match result {
Ok(data) => Ok(Response::with((status::Ok, mime!(Application / Json), format!("{}", data)))),
......@@ -468,7 +468,7 @@ fn submission_post(req: &mut Request) -> IronResult<Response> {
println!("{}", task_id);
println!("{}", grade);
let result = with_conn![functions::save_submission, req, task_id, session_token, csrf_token, data, grade, subtask];
let result = with_conn![functions::save_submission, req, task_id, &session_token, &csrf_token, data, grade, subtask];
match result {
Ok(_) => Ok(Response::with((status::Ok, mime!(Application / Json), format!("{{}}")))),
......@@ -482,7 +482,7 @@ fn task(req: &mut Request) -> IronResult<Response> {
println!("{}", task_id);
let (template, data) = with_conn![functions::show_task, req, task_id, session_token].aug(req)?;
let (template, data) = with_conn![functions::show_task, req, task_id, &session_token].aug(req)?;
let mut resp = Response::new();
resp.set_mut(Template::new(&template, data)).set_mut(status::Ok);
......@@ -492,7 +492,7 @@ fn task(req: &mut Request) -> IronResult<Response> {
fn groups(req: &mut Request) -> IronResult<Response> {
let session_token = req.require_session_token()?;
let (template, data) = with_conn![functions::show_groups, req, session_token].aug(req)?;
let (template, data) = with_conn![functions::show_groups, req, &session_token].aug(req)?;
let mut resp = Response::new();
resp.set_mut(Template::new(&template, data)).set_mut(status::Ok);
......@@ -503,7 +503,7 @@ fn group(req: &mut Request) -> IronResult<Response> {
let group_id = req.expect_int::<u32>("groupid")?;
let session_token = req.require_session_token()?;
let (template, data) = with_conn![functions::show_group, req, group_id, session_token].aug(req)?;
let (template, data) = with_conn![functions::show_group, req, group_id, &session_token].aug(req)?;
let mut resp = Response::new();
resp.set_mut(Template::new(&template, data)).set_mut(status::Ok);
......@@ -515,7 +515,7 @@ fn group_post(req: &mut Request) -> IronResult<Response> {
let session_token = req.expect_session_token()?;
//TODO: use result?
with_conn![functions::modify_group, req, group_id, session_token].aug(req)?;
with_conn![functions::modify_group, req, group_id, &session_token].aug(req)?;
Ok(Response::with((status::Found, Redirect(url_for!(req, "group", "groupid" => format!("{}",group_id))))))
}
......@@ -532,7 +532,7 @@ fn new_group(req: &mut Request) -> IronResult<Response> {
println!("{}", csrf);
println!("{}", name);
let group_id = with_conn![functions::add_group, req, session_token, csrf, name, tag].aug(req)?;
let group_id = with_conn![functions::add_group, req, &session_token, &csrf, name, tag].aug(req)?;
Ok(Response::with((status::Found, Redirect(url_for!(req, "group", "groupid" => format!("{}",group_id))))))
}
......@@ -541,7 +541,7 @@ fn profile(req: &mut Request) -> IronResult<Response> {
let session_token = req.require_session_token()?;
let query_string = req.url.query().map(|s| s.to_string());
let (template, data) = with_conn![functions::show_profile, req, session_token, None, query_string].aug(req)?;
let (template, data) = with_conn![functions::show_profile, req, &session_token, None, query_string].aug(req)?;
let mut resp = Response::new();
resp.set_mut(Template::new(&template, data)).set_mut(status::Ok);
......@@ -565,9 +565,9 @@ fn profile_post(req: &mut Request) -> IronResult<Response> {
let profilechangeresult = with_conn![functions::edit_profile,
req,
session_token,
&session_token,
None,
csrf_token,
&csrf_token,
firstname,
lastname,
street,
......@@ -589,7 +589,7 @@ fn user(req: &mut Request) -> IronResult<Response> {
let query_string = req.url.query().map(|s| s.to_string());
let (template, data) =
with_conn![functions::show_profile, req, session_token, Some(user_id), query_string].aug(req)?;
with_conn![functions::show_profile, req, &session_token, Some(user_id), query_string].aug(req)?;
let mut resp = Response::new();
resp.set_mut(Template::new(&template, data)).set_mut(status::Ok);
......@@ -614,9 +614,9 @@ fn user_post(req: &mut Request) -> IronResult<Response> {
let profilechangeresult = with_conn![functions::edit_profile,
req,
session_token,
&session_token,
Some(user_id),
csrf_token,
&csrf_token,
firstname,
lastname,
street,
......
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