Commit 6d9fe052 authored by Robert Czechowski's avatar Robert Czechowski
Browse files

Add MedalError AccessDenied, Add helper type aliases for results

parent 3ae7dff5
......@@ -70,9 +70,14 @@ pub struct ContestInfo {
#[derive(Clone)]
pub enum MedalError {
NotLoggedIn
NotLoggedIn,
AccessDenied,
}
type MedalValue = (String, json_val::Map<String, json_val::Value>);
type MedalResult<T> = Result<T, MedalError>;
type MedalValueResult = MedalResult<MedalValue>;
pub fn show_contests<T: MedalConnection>(conn: &T) -> (String, json_val::Map<String, json_val::Value>) {
let mut data = json_val::Map::new();
......@@ -276,7 +281,7 @@ pub struct GroupInfo {
pub code: String,
}
pub fn show_groups<T: MedalConnection>(conn: &T, session_token: String) -> (String, json_val::Map<String, json_val::Value>) {
pub fn show_groups<T: MedalConnection>(conn: &T, session_token: String) -> Result<(String, json_val::Map<String, json_val::Value>), MedalError> {
let session = conn.get_session(session_token).unwrap(); // TODO handle error
// let groupvec = conn.get_group(session_token);
......@@ -292,7 +297,7 @@ pub fn show_groups<T: MedalConnection>(conn: &T, session_token: String) -> (Str
data.insert("group".to_string(), to_json(&v));
data.insert("csrftoken".to_string(), to_json(&session.csrf_token));
("groups".to_string(), data)
Ok(("groups".to_string(), data))
}
#[derive(Serialize, Deserialize)]
......
......@@ -186,7 +186,10 @@ impl<'c, 'a, 'b> From<AugMedalError<'c, 'a, 'b>> for IronError {
match me {
functions::MedalError::NotLoggedIn => IronError {
error: Box::new(SessionError { message: "Not Logged in, redirecting to login page".to_string() }),
response: Response::with((status::Found, RedirectRaw(format!("/login?{}", req.url.path().join("/"))))) }
response: Response::with((status::Found, RedirectRaw(format!("/login?{}", req.url.path().join("/"))))) },
functions::MedalError::AccessDenied => IronError {
error: Box::new(SessionError { message: "Access denied".to_string() }),
response: Response::with(status::Forbidden) }
}
}
}
......@@ -467,7 +470,7 @@ fn groups(req: &mut Request) -> IronResult<Response> {
let conn = mutex.lock().unwrap_or_else(|e| e.into_inner());
// Antwort erstellen und zurücksenden
functions::show_groups(&*conn, session_token)
functions::show_groups(&*conn, session_token).map_err(|me| {AugMedalError(me, req)})?
/*let mut data = json_val::Map::new();
data.insert("reason".to_string(), to_json(&"Not implemented".to_string()));
("groups", data)*/
......
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