Commit 27bb9a56 authored by Robert Czechowski's avatar Robert Czechowski

Show Oauth-Login buttons on contest page also

parent 47218be4
Pipeline #396 passed with stages
in 17 minutes and 42 seconds
......@@ -136,7 +136,11 @@ pub enum ContestVisibility {
Current,
}
pub fn show_contests<T: MedalConnection>(conn: &T, session_token: &str, visibility: ContestVisibility) -> MedalValue {
pub fn show_contests<T: MedalConnection>(conn: &T, session_token: &str,
(self_url, oauth_providers): (Option<String>, Option<Vec<OauthProvider>>),
visibility: ContestVisibility)
-> MedalValue
{
let mut data = json_val::Map::new();
let session = conn.get_session_or_new(&session_token);
......@@ -146,6 +150,18 @@ pub fn show_contests<T: MedalConnection>(conn: &T, session_token: &str, visibili
data.insert("can_start".to_string(), to_json(&true));
}
let mut oauth_links: Vec<(String, String, String)> = Vec::new();
if let Some(oauth_providers) = oauth_providers {
for oauth_provider in oauth_providers {
oauth_links.push((oauth_provider.provider_id.to_owned(),
oauth_provider.login_link_text.to_owned(),
oauth_provider.url.to_owned()));
}
}
data.insert("self_url".to_string(), to_json(&self_url));
data.insert("oauth_links".to_string(), to_json(&oauth_links));
let v: Vec<ContestInfo> = conn.get_contest_list()
.iter()
.map(|c| ContestInfo { id: c.id.unwrap(),
......
......@@ -355,7 +355,19 @@ fn debug_create_session<C>(req: &mut Request) -> IronResult<Response>
fn contests<C>(req: &mut Request) -> IronResult<Response>
where C: MedalConnection + std::marker::Send + 'static {
let session_token = req.require_session_token()?;
let (template, data) = with_conn![core::show_contests, C, req, &session_token, core::ContestVisibility::All];
let (self_url, oauth_providers) = {
let mutex = req.get::<Write<SharedConfiguration>>().unwrap();
let config = mutex.lock().unwrap_or_else(|e| e.into_inner());
(config.self_url.clone(), config.oauth_providers.clone())
};
let (template, data) = with_conn![core::show_contests,
C,
req,
&session_token,
(self_url, oauth_providers),
core::ContestVisibility::All];
let mut resp = Response::new();
resp.set_mut(Template::new(&template, data)).set_mut(status::Ok);
......@@ -365,7 +377,19 @@ fn contests<C>(req: &mut Request) -> IronResult<Response>
fn opencontests<C>(req: &mut Request) -> IronResult<Response>
where C: MedalConnection + std::marker::Send + 'static {
let session_token = req.require_session_token()?;
let (template, data) = with_conn![core::show_contests, C, req, &session_token, core::ContestVisibility::Open];
let (self_url, oauth_providers) = {
let mutex = req.get::<Write<SharedConfiguration>>().unwrap();
let config = mutex.lock().unwrap_or_else(|e| e.into_inner());
(config.self_url.clone(), config.oauth_providers.clone())
};
let (template, data) = with_conn![core::show_contests,
C,
req,
&session_token,
(self_url, oauth_providers),
core::ContestVisibility::Open];
let mut resp = Response::new();
resp.set_mut(Template::new(&template, data)).set_mut(status::Ok);
......@@ -375,7 +399,19 @@ fn opencontests<C>(req: &mut Request) -> IronResult<Response>
fn currentcontests<C>(req: &mut Request) -> IronResult<Response>
where C: MedalConnection + std::marker::Send + 'static {
let session_token = req.require_session_token()?;
let (template, data) = with_conn![core::show_contests, C, req, &session_token, core::ContestVisibility::Current];
let (self_url, oauth_providers) = {
let mutex = req.get::<Write<SharedConfiguration>>().unwrap();
let config = mutex.lock().unwrap_or_else(|e| e.into_inner());
(config.self_url.clone(), config.oauth_providers.clone())
};
let (template, data) = with_conn![core::show_contests,
C,
req,
&session_token,
(self_url, oauth_providers),
core::ContestVisibility::Current];
let mut resp = Response::new();
resp.set_mut(Template::new(&template, data)).set_mut(status::Ok);
......
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