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

romoved all warnings

parent 1fb52bff
Pipeline #57 passed with stage
in 3 minutes and 53 seconds
......@@ -14,7 +14,7 @@ use self::time::Duration;
use std::path::{Path};
use self::bcrypt::{DEFAULT_COST, hash, verify, BcryptError};
use self::bcrypt::{verify};
use ::functions; // todo: remove (usertype in db)
......@@ -190,7 +190,8 @@ impl MedalConnection for Connection {
}
}
fn login(&self, session: Option<&str>, username: &str, password: &str) -> Result<String,()> {
//TODO: use session
fn login(&self, _session: Option<&str>, username: &str, password: &str) -> Result<String,()> {
match self.query_row(
"SELECT id, password, salt FROM session_user WHERE username = ?1",
&[&username],
......@@ -215,7 +216,9 @@ impl MedalConnection for Connection {
_ => {Err(()) }
}
}
fn login_with_code(&self, session: Option<&str>, logincode: &str) -> Result<String,()> {
//TODO: use session
fn login_with_code(&self, _session: Option<&str>, logincode: &str) -> Result<String,()> {
match self.query_row(
"SELECT id FROM session_user WHERE logincode = ?1",
&[&logincode],
......@@ -237,7 +240,8 @@ impl MedalConnection for Connection {
}
}
fn login_foreign(&self, session: Option<&str>, foreign_id: u32, foreign_type: functions::UserType, firstname: &str, lastname: &str) -> Result<String,()> {
//TODO: use session
fn login_foreign(&self, _session: Option<&str>, foreign_id: u32, foreign_type: functions::UserType, firstname: &str, lastname: &str) -> Result<String,()> {
let session_token: String = thread_rng().sample_iter(&Alphanumeric).take(10).collect();
let csrf_token: String = thread_rng().sample_iter(&Alphanumeric).take(10).collect();
let now = time::get_time();
......@@ -260,7 +264,8 @@ impl MedalConnection for Connection {
}
}
fn create_user_with_groupcode(&self, session: Option<&str>, groupcode: &str) -> Result<String,()> {
//TODO: use session
fn create_user_with_groupcode(&self, _session: Option<&str>, groupcode: &str) -> Result<String,()> {
match self.query_row(
"SELECT id FROM usergroup WHERE groupcode = ?1",
&[&groupcode],
......
......@@ -10,7 +10,7 @@ use db_conn::{MedalConnection};
use db_objects::{Submission, Group, SessionUser};
use self::bcrypt::{DEFAULT_COST, hash, verify, BcryptError};
use self::bcrypt::{hash};
#[derive(Serialize, Deserialize)]
pub struct SubTaskInfo {
......@@ -35,6 +35,7 @@ pub struct ContestInfo {
pub tasks: Vec<TaskInfo>,
}
#[allow(dead_code)] //CsrfCheckFailed, SessionTimeout, DatabaseError and UnmatchedPasswords are used in webfw_iron.rs.
#[derive(Clone)]
pub enum MedalError {
NotLoggedIn,
......@@ -103,10 +104,9 @@ pub fn show_contest<T: MedalConnection>(conn: &T, contest_id: u32, session_token
let mut tasks = Vec::new();
for (task, grade) in c.taskgroups.into_iter().zip(grades) {
let mut not_print_yet = true;
let mut blackstars :usize = 0;
let mut stasks = Vec::new();
for st in task.tasks {
blackstars = 0;
let mut blackstars :usize = 0;
if not_print_yet && st.stars >= grade.grade.unwrap_or(0) {
blackstars = grade.grade.unwrap_or(0) as usize;
not_print_yet = false;
......@@ -185,7 +185,8 @@ pub fn show_contest_results<T: MedalConnection>(conn: &T, contest_id: u32, sessi
for (group, groupdata) in resultdata {
let mut groupresults: Vec<(String, Vec<String>)> = Vec::new();
for (user, userdata) in groupdata {
//TODO: use user
for (_user, userdata) in groupdata {
let mut userresults: Vec<String> = Vec::new();
userresults.push(String::new());
......@@ -227,8 +228,10 @@ pub fn show_contest_results<T: MedalConnection>(conn: &T, contest_id: u32, sessi
Ok(("contestresults".to_owned(), data))
}
pub fn start_contest<T: MedalConnection>(conn: &T, contest_id: u32, session_token: String, csrf_token:String) -> MedalResult<()> {
let data = json_val::Map::new();
//TODO: use csrf_token
pub fn start_contest<T: MedalConnection>(conn: &T, contest_id: u32, session_token: String, _csrf_token:String) -> MedalResult<()> {
//TODO: use data
let _data = json_val::Map::new();
match conn.new_participation(&session_token, contest_id) {
Ok(_) => Ok(()),
......@@ -407,7 +410,7 @@ 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: String) -> MedalResult<()> {
unimplemented!()
}
......@@ -437,10 +440,11 @@ pub fn add_group<T: MedalConnection>(conn: &T, session_token: String, csrf_token
Ok(group.id.unwrap())
}
#[allow(dead_code)]
pub fn show_groups_results<T: MedalConnection>(conn: &T, contest_id: u32, session_token: String) -> MedalValueResult {
let session = conn.get_session_or_new(&session_token).ensure_logged_in().ok_or(MedalError::NotLoggedIn)?;
let g = conn.get_contest_groups_grades(session.id, contest_id);
//TODO: use g
let _g = conn.get_contest_groups_grades(session.id, contest_id);
let data = json_val::Map::new();
......@@ -469,7 +473,7 @@ pub fn show_profile<T: MedalConnection>(conn: &T, session_token: String, user_id
query_string.map(|query| {
if query.starts_with("status=") {
let status: &str = &query[7..];
if ["nothing_changed","data_changed","password_changed","password_missmatch"].contains(&status) {
if ["NothingChanged","DataChanged","PasswordChanged","PasswordMissmatch"].contains(&status) {
data.insert((status).to_string(), to_json(&true));
}
}});
......@@ -506,16 +510,16 @@ fn hash_password(password: &str, salt: &str) -> Result<String, MedalError> {
let password_and_salt = [password, salt].concat().to_string();
match hash(password_and_salt, 5) {
Ok(result) => Ok(result),
Err(e) => Err(MedalError::PasswordHashingError)
Err(_) => Err(MedalError::PasswordHashingError)
}
}
#[derive(Debug)]
pub enum ProfileStatus {
nothing_changed,
data_changed,
password_changed,
password_missmatch,
NothingChanged,
DataChanged,
PasswordChanged,
PasswordMissmatch,
}
impl std::convert::Into<String> for ProfileStatus {
fn into(self) -> String {
......@@ -535,10 +539,10 @@ pub fn edit_profile<T: MedalConnection>(conn: &T, session_token: String, user_id
&& session.grade == grade
&& password == ""
&& password_repeat == "" {
return Ok(ProfileStatus::nothing_changed);
return Ok(ProfileStatus::NothingChanged);
}
let mut result = ProfileStatus::data_changed;
let mut result = ProfileStatus::DataChanged;
let mut password_salt = None;
......@@ -548,9 +552,9 @@ pub fn edit_profile<T: MedalConnection>(conn: &T, session_token: String, user_id
let hash = hash_password(&password, &salt)?;
password_salt = Some((hash, salt));
result = ProfileStatus::password_changed;
result = ProfileStatus::PasswordChanged;
} else {
result = ProfileStatus::password_missmatch;
result = ProfileStatus::PasswordMissmatch;
}
}
......
......@@ -166,7 +166,6 @@ fn add_admin_user(conn: &mut Connection, resetpw: bool) {
print!("Request to reset admin password. Set credentials 'admin':");
user
}
_ => return
};
use rand::{thread_rng, Rng, distributions::Alphanumeric};
......
......@@ -141,7 +141,7 @@ impl<'a, 'b> RequestSession for Request<'a, 'b> {
use rand::{thread_rng, Rng};
let new_session_key: String = thread_rng().gen_ascii_chars().take(28).collect();
let new_session_key: String = thread_rng().sample_iter(&Alphanumeric).take(28).collect();
self.session().set(SessionToken { token: new_session_key }).unwrap();
Err(IronError { error: Box::new(SessionError { message: "No valid session found, redirecting to cookie page".to_string() }),
response: Response::with((status::Found, RedirectRaw(format!("/cookie?{}", self.url.path().join("/"))))) })
......@@ -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)?;
let _startcontestresult = 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,7 +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()?;
let changegroupresult = with_conn![functions::modify_group, req, group_id, session_token].aug(req)?;
//TODO: use changegroupresult
let _changegroupresult = 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))))))
}
......@@ -522,7 +523,8 @@ fn profile_post(req: &mut Request) -> IronResult<Response> {
)
};
let profilechangeresult = with_conn![functions::edit_profile, req, session_token, None, csrf_token, firstname, lastname, pwd, pwd_repeat, grade].aug(req)?;
//TODO: use profilechangeresult
let _profilechangeresult = with_conn![functions::edit_profile, req, session_token, None, csrf_token, firstname, lastname, pwd, pwd_repeat, grade].aug(req)?;
Ok(Response::with((status::Found, Redirect(url_for!(req, "profile")))))
}
......@@ -555,7 +557,8 @@ fn user_post(req: &mut Request) -> IronResult<Response> {
};
let profilechangeresult = with_conn![functions::edit_profile, req, session_token, Some(user_id), csrf_token, firstname, lastname, pwd, pwd_repeat, grade].aug(req)?;
//TODO: use profilechangeresult
let _profilechangeresult = with_conn![functions::edit_profile, req, session_token, Some(user_id), csrf_token, firstname, lastname, pwd, pwd_repeat, grade].aug(req)?;
Ok(Response::with((status::Found, Redirect(url_for!(req, "user", "userid" => format!("{}",user_id))))))
}
......@@ -725,7 +728,7 @@ pub fn get_handlebars_engine() -> impl AfterMiddleware {
fn cookie_warning(req: &mut Request) -> IronResult<Response> {
match req.get_session_token() {
Some(session_token) => {
Some(_session_token) => {
// TODO: Set session!
// TODO:
Ok(Response::with((status::Found, RedirectRaw(format!("/{}",req.url.query().unwrap_or(""))))))
......
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