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 {
(row.get(0), row.get(1), row.get(2))
}) {
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!
let session_token: String = thread_rng().sample_iter(&Alphanumeric).take(10).collect();
......@@ -370,10 +370,8 @@ impl MedalConnection for Connection {
let mut taskindex: ::std::collections::BTreeMap<u32, usize> = ::std::collections::BTreeMap::new();
let n_tasks = tasknames.len();
let mut index = 0;
for (i, _) in &tasknames {
for (index, (i, _)) in tasknames.iter().enumerate() {
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
......@@ -456,10 +454,8 @@ impl MedalConnection for Connection {
let mut taskindex: ::std::collections::BTreeMap<u32, usize> = ::std::collections::BTreeMap::new();
let n_tasks = tasknames.len();
let mut index = 0;
for (i, _) in &tasknames {
for (index, (i, _)) in tasknames.iter().enumerate() {
taskindex.insert(*i, index);
index = index + 1
}
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
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 {
// Contest over
......@@ -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 {
id: m.id,
firstname: m.firstname.clone().unwrap_or("".to_string()),
lastname: m.lastname.clone().unwrap_or("".to_string()),
firstname: m.firstname.clone().unwrap_or_else(|| "".to_string()),
lastname: m.lastname.clone().unwrap_or_else(|| "".to_string()),
grade: m.grade,
logincode: m.logincode.clone().unwrap_or("".to_string()),
logincode: m.logincode.clone().unwrap_or_else(|| "".to_string()),
}}).collect();
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
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=") {
let status: &str = &query[7..];
if ["NothingChanged","DataChanged","PasswordChanged","PasswordMissmatch"].contains(&status) {
data.insert((status).to_string(), to_json(&true));
}
}});
}
}
},
Some(user_id) => {
// TODO: Add test to check if this access restriction works
......@@ -640,7 +642,7 @@ impl SetPassword for SessionUser {
let hash = hash_password(password, &salt).ok()?;
self.password = Some(hash);
self.salt = Some(salt.into());
self.salt = Some(salt);
Some(())
}
}
......@@ -116,19 +116,15 @@ fn read_contest(p: &path::PathBuf) -> Option<Contest> {
fn get_all_contest_info(task_dir: &str) -> Vec<Contest> {
fn walk_me_recursively(p: &path::PathBuf, contests: &mut Vec<Contest>) {
match fs::read_dir(p) {
Ok(paths) => for path in paths {
if let Ok(paths) = fs::read_dir(p) {
for path in paths {
let p = path.unwrap().path();
walk_me_recursively(&p, contests);
},
_ => (),
}
}
if p.file_name().unwrap().to_string_lossy().to_string().ends_with(".yaml") {
match read_contest(p) {
Some(contest) => contests.push(contest),
_ => (),
}
read_contest(p).map(|contest| contests.push(contest));
};
};
......
......@@ -95,7 +95,7 @@ impl CookieDistributor {
impl AroundMiddleware for CookieDistributor {
fn around(self, handler: Box<Handler>) -> Box<Handler> {
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();
req.session().set(SessionToken { token: session_token }).unwrap();
}
......@@ -296,7 +296,7 @@ fn contest_post(req: &mut Request) -> IronResult<Response> {
};
// 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))))))
}
......@@ -475,8 +475,8 @@ fn group_post(req: &mut Request) -> IronResult<Response> {
let group_id = req.expect_int::<u32>("groupid")?;
let session_token = req.expect_session_token()?;
//TODO: use changegroupresult
let _changegroupresult = with_conn![functions::modify_group, req, group_id, session_token].aug(req)?;
//TODO: use result?
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))))))
}
......
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