Commit 4203b9c0 authored by Robert Czechowski's avatar Robert Czechowski
Browse files

Add feature 'signup' so that the sign up page can be enabled / disabled

parent 8944e398
Pipeline #810 passed with stage
in 5 minutes and 58 seconds
......@@ -17,7 +17,8 @@ server = ["rusqlite", "postgres"]
desktop = ["rusqlite", "webbrowser"]
watch = ["handlebars-iron/watch"]
strict = [] # Treat warnings as a build error
debug = []
debug = ["signup"]
signup = []
[dependencies]
time = "0.1.40"
......
......@@ -14,7 +14,9 @@
use time;
use db_conn::{MedalConnection, SignupResult};
use db_conn::MedalConnection;
#[cfg(feature = "signup")]
use db_conn::SignupResult;
use db_objects::OptionSession;
use db_objects::SessionUser;
use db_objects::{Contest, Grade, Group, Participation, Submission, Taskgroup};
......@@ -53,6 +55,7 @@ pub enum MedalError {
DatabaseError,
PasswordHashingError,
UnmatchedPasswords,
NotFound,
}
type MedalValue = (String, json_val::Map<String, json_val::Value>);
......@@ -533,6 +536,7 @@ pub fn logout<T: MedalConnection>(conn: &T, session_token: Option<String>) {
session_token.map(|token| conn.logout(&token));
}
#[cfg(feature = "signup")]
pub fn signup<T: MedalConnection>(conn: &T, session_token:Option<String>, signup_data: (String, String, String)) -> MedalResult<SignupResult> {
let (username, email, password) = signup_data;
......@@ -547,6 +551,7 @@ pub fn signup<T: MedalConnection>(conn: &T, session_token:Option<String>, signup
Ok(result)
}
#[cfg(feature = "signup")]
pub fn signupdata (query_string: Option<String>) -> json_val::Map<String, json_val::Value> {
let mut data = json_val::Map::new();
if let Some(query) = query_string {
......
......@@ -41,6 +41,7 @@ use db_conn::MedalConnection;
use iron::typemap::Key;
pub use serde_json::value as json_val;
#[cfg(feature = "signup")]
use db_conn::SignupResult;
static TASK_DIR: &str = "tasks";
......@@ -252,7 +253,7 @@ impl<'c, 'a, 'b> From<AugMedalError<'c, 'a, 'b>> for IronError {
fn from(AugMedalError(me, req): AugMedalError<'c, 'a, 'b>) -> Self {
match me {
core::MedalError::NotLoggedIn => {
IronError { error: Box::new(SessionError { message:
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("/"))))) }
......@@ -280,6 +281,10 @@ impl<'c, 'a, 'b> From<AugMedalError<'c, 'a, 'b>> for IronError {
"The two passwords did not match.".to_string() }),
response: Response::with(status::Forbidden) }
}
core::MedalError::NotFound => {
IronError { error: Box::new(SessionError { message: "Not found".to_string() }),
response: Response::with(status::NotFound) }
}
}
}
}
......@@ -594,6 +599,7 @@ fn logout<C>(req: &mut Request) -> IronResult<Response>
Ok(Response::with((status::Found, Redirect(url_for!(req, "greet")))))
}
#[cfg(feature = "signup")]
fn signup<C>(req: &mut Request) -> IronResult<Response>
where C: MedalConnection + std::marker::Send + 'static {
let query_string = req.url.query().map(|s| s.to_string());
......@@ -604,6 +610,7 @@ fn signup<C>(req: &mut Request) -> IronResult<Response>
Ok(resp)
}
#[cfg(feature = "signup")]
fn signup_post<C>(req: &mut Request) -> IronResult<Response>
where C: MedalConnection + std::marker::Send + 'static {
let session_token = req.get_session_token();
......@@ -627,6 +634,19 @@ fn signup_post<C>(req: &mut Request) -> IronResult<Response>
}
}
#[cfg(not(feature = "signup"))]
fn signup<C>(req: &mut Request) -> IronResult<Response>
where C: MedalConnection + std::marker::Send + 'static {
Err(core::MedalError::NotFound).aug(req).map_err(|x| x.into())
}
#[cfg(not(feature = "signup"))]
fn signup_post<C>(req: &mut Request) -> IronResult<Response>
where C: MedalConnection + std::marker::Send + 'static {
Err(core::MedalError::NotFound).aug(req).map_err(|x| x.into())
}
fn submission<C>(req: &mut Request) -> IronResult<Response>
where C: MedalConnection + std::marker::Send + 'static {
let task_id = req.expect_int::<i32>("taskid")?;
......
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