Commit 8559ffc7 authored by Robert Czechowski's avatar Robert Czechowski
Browse files

Fix all Clippy warnings except for manually selected exclusions

parent 056112bb
...@@ -199,7 +199,7 @@ impl MedalConnection for Connection { ...@@ -199,7 +199,7 @@ impl MedalConnection for Connection {
(row.get(0), row.get(1), row.get(2)) (row.get(0), row.get(1), row.get(2))
}) { }) {
Ok((id, password_hash, salt)) => { //password_hash ist das, was in der Datenbank steht Ok((id, password_hash, salt)) => { //password_hash ist das, was in der Datenbank steht
if verify_password(&password, &salt.expect("salt from database empty"), &password_hash.expect("password from database empty")) == true { // TODO: fail more pleasantly if verify_password(&password, &salt.expect("salt from database empty"), &password_hash.expect("password from database empty")) { // TODO: fail more pleasantly
// Login okay, update session now! // Login okay, update session now!
let session_token: String = thread_rng().sample_iter(&Alphanumeric).take(10).collect(); let session_token: String = thread_rng().sample_iter(&Alphanumeric).take(10).collect();
...@@ -370,10 +370,8 @@ impl MedalConnection for Connection { ...@@ -370,10 +370,8 @@ impl MedalConnection for Connection {
let mut taskindex: ::std::collections::BTreeMap<u32, usize> = ::std::collections::BTreeMap::new(); let mut taskindex: ::std::collections::BTreeMap<u32, usize> = ::std::collections::BTreeMap::new();
let n_tasks = tasknames.len(); let n_tasks = tasknames.len();
let mut index = 0; for (index, (i, _)) in tasknames.iter().enumerate() {
for (i, _) in &tasknames {
taskindex.insert(*i, index); taskindex.insert(*i, index);
index = index + 1
} }
let mut stmt = self.prepare("SELECT grade.taskgroup, grade.user, grade.grade, grade.validated, usergroup.id, usergroup.name, usergroup.groupcode, usergroup.tag, student.id, student.username, student.logincode, student.firstname, student.lastname let mut stmt = self.prepare("SELECT grade.taskgroup, grade.user, grade.grade, grade.validated, usergroup.id, usergroup.name, usergroup.groupcode, usergroup.tag, student.id, student.username, student.logincode, student.firstname, student.lastname
...@@ -456,10 +454,8 @@ impl MedalConnection for Connection { ...@@ -456,10 +454,8 @@ impl MedalConnection for Connection {
let mut taskindex: ::std::collections::BTreeMap<u32, usize> = ::std::collections::BTreeMap::new(); let mut taskindex: ::std::collections::BTreeMap<u32, usize> = ::std::collections::BTreeMap::new();
let n_tasks = tasknames.len(); let n_tasks = tasknames.len();
let mut index = 0; for (index, (i, _)) in tasknames.iter().enumerate() {
for (i, _) in &tasknames {
taskindex.insert(*i, index); taskindex.insert(*i, index);
index = index + 1
} }
let mut stmt = self.prepare("SELECT grade.taskgroup, grade.user, grade.grade, grade.validated let mut stmt = self.prepare("SELECT grade.taskgroup, grade.user, grade.grade, grade.validated
......
...@@ -154,7 +154,7 @@ pub fn show_contest<T: MedalConnection>(conn: &T, contest_id: u32, session_token ...@@ -154,7 +154,7 @@ pub fn show_contest<T: MedalConnection>(conn: &T, contest_id: u32, session_token
data.insert("participation_start_date".to_string(), to_json(&format!("{}",passed_secs))); data.insert("participation_start_date".to_string(), to_json(&format!("{}",passed_secs)));
let left_secs = (ci.duration as i64) * 60 - passed_secs; let left_secs = i64::from(ci.duration) * 60 - passed_secs;
if left_secs < 0 { if left_secs < 0 {
// Contest over // Contest over
...@@ -398,10 +398,10 @@ pub fn show_group<T: MedalConnection>(conn: &T, group_id: u32, session_token: St ...@@ -398,10 +398,10 @@ pub fn show_group<T: MedalConnection>(conn: &T, group_id: u32, session_token: St
let v : Vec<MemberInfo> = group.members.iter().map(|m| { MemberInfo { let v : Vec<MemberInfo> = group.members.iter().map(|m| { MemberInfo {
id: m.id, id: m.id,
firstname: m.firstname.clone().unwrap_or("".to_string()), firstname: m.firstname.clone().unwrap_or_else(|| "".to_string()),
lastname: m.lastname.clone().unwrap_or("".to_string()), lastname: m.lastname.clone().unwrap_or_else(|| "".to_string()),
grade: m.grade, grade: m.grade,
logincode: m.logincode.clone().unwrap_or("".to_string()), logincode: m.logincode.clone().unwrap_or_else(|| "".to_string()),
}}).collect(); }}).collect();
data.insert("group".to_string(), to_json(&gi)); data.insert("group".to_string(), to_json(&gi));
...@@ -470,13 +470,15 @@ pub fn show_profile<T: MedalConnection>(conn: &T, session_token: String, user_id ...@@ -470,13 +470,15 @@ pub fn show_profile<T: MedalConnection>(conn: &T, session_token: String, user_id
data.insert("csrftoken".to_string(), to_json(&session.csrf_token)); data.insert("csrftoken".to_string(), to_json(&session.csrf_token));
query_string.map(|query| {
if let Some(query) = query_string {
if query.starts_with("status=") { if query.starts_with("status=") {
let status: &str = &query[7..]; let status: &str = &query[7..];
if ["NothingChanged","DataChanged","PasswordChanged","PasswordMissmatch"].contains(&status) { if ["NothingChanged","DataChanged","PasswordChanged","PasswordMissmatch"].contains(&status) {
data.insert((status).to_string(), to_json(&true)); data.insert((status).to_string(), to_json(&true));
} }
}}); }
}
}, },
Some(user_id) => { Some(user_id) => {
// TODO: Add test to check if this access restriction works // TODO: Add test to check if this access restriction works
...@@ -640,7 +642,7 @@ impl SetPassword for SessionUser { ...@@ -640,7 +642,7 @@ impl SetPassword for SessionUser {
let hash = hash_password(password, &salt).ok()?; let hash = hash_password(password, &salt).ok()?;
self.password = Some(hash); self.password = Some(hash);
self.salt = Some(salt.into()); self.salt = Some(salt);
Some(()) Some(())
} }
} }
...@@ -116,19 +116,15 @@ fn read_contest(p: &path::PathBuf) -> Option<Contest> { ...@@ -116,19 +116,15 @@ fn read_contest(p: &path::PathBuf) -> Option<Contest> {
fn get_all_contest_info(task_dir: &str) -> Vec<Contest> { fn get_all_contest_info(task_dir: &str) -> Vec<Contest> {
fn walk_me_recursively(p: &path::PathBuf, contests: &mut Vec<Contest>) { fn walk_me_recursively(p: &path::PathBuf, contests: &mut Vec<Contest>) {
match fs::read_dir(p) { if let Ok(paths) = fs::read_dir(p) {
Ok(paths) => for path in paths { for path in paths {
let p = path.unwrap().path(); let p = path.unwrap().path();
walk_me_recursively(&p, contests); walk_me_recursively(&p, contests);
}, }
_ => (),
} }
if p.file_name().unwrap().to_string_lossy().to_string().ends_with(".yaml") { if p.file_name().unwrap().to_string_lossy().to_string().ends_with(".yaml") {
match read_contest(p) { read_contest(p).map(|contest| contests.push(contest));
Some(contest) => contests.push(contest),
_ => (),
}
}; };
}; };
......
...@@ -95,7 +95,7 @@ impl CookieDistributor { ...@@ -95,7 +95,7 @@ impl CookieDistributor {
impl AroundMiddleware for CookieDistributor { impl AroundMiddleware for CookieDistributor {
fn around(self, handler: Box<Handler>) -> Box<Handler> { fn around(self, handler: Box<Handler>) -> Box<Handler> {
Box::new(move |req: &mut Request| -> IronResult<Response> { Box::new(move |req: &mut Request| -> IronResult<Response> {
if !req.session().get::<SessionToken>().expect("blub...").is_some() { if req.session().get::<SessionToken>().expect("blub...").is_none() {
let session_token: String = thread_rng().sample_iter(&Alphanumeric).take(10).collect(); let session_token: String = thread_rng().sample_iter(&Alphanumeric).take(10).collect();
req.session().set(SessionToken { token: session_token }).unwrap(); req.session().set(SessionToken { token: session_token }).unwrap();
} }
...@@ -296,7 +296,7 @@ fn contest_post(req: &mut Request) -> IronResult<Response> { ...@@ -296,7 +296,7 @@ fn contest_post(req: &mut Request) -> IronResult<Response> {
}; };
// TODO: Was mit dem Result? // TODO: Was mit dem Result?
let _startcontestresult = 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)))))) Ok(Response::with((status::Found, Redirect(url_for!(req, "contest", "contestid" => format!("{}",contest_id))))))
} }
...@@ -475,8 +475,8 @@ fn group_post(req: &mut Request) -> IronResult<Response> { ...@@ -475,8 +475,8 @@ fn group_post(req: &mut Request) -> IronResult<Response> {
let group_id = req.expect_int::<u32>("groupid")?; let group_id = req.expect_int::<u32>("groupid")?;
let session_token = req.expect_session_token()?; let session_token = req.expect_session_token()?;
//TODO: use changegroupresult //TODO: use result?
let _changegroupresult = 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)))))) Ok(Response::with((status::Found, Redirect(url_for!(req, "group", "groupid" => format!("{}",group_id))))))
} }
......
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