Commit 75114683 authored by Robert Czechowski's avatar Robert Czechowski
Browse files

Merge branch 'restyle-login'

parents a0a01807 7d66fda8
Pipeline #386 passed with stages
in 15 minutes and 30 seconds
......@@ -423,7 +423,10 @@ pub fn start_contest<T: MedalConnection>(conn: &T, contest_id: i32, session_toke
}
}
pub fn login<T: MedalConnection>(conn: &T, login_data: (String, String)) -> Result<String, MedalValue> {
pub fn login<T: MedalConnection>(conn: &T, login_data: (String, String),
(self_url, oauth_providers): (Option<String>, Option<Vec<OauthProvider>>))
-> Result<String, MedalValue>
{
let (username, password) = login_data;
match conn.login(None, &username, &password) {
......@@ -432,13 +435,27 @@ pub fn login<T: MedalConnection>(conn: &T, login_data: (String, String)) -> Resu
let mut data = json_val::Map::new();
data.insert("reason".to_string(), to_json(&"Login fehlgeschlagen. Bitte erneut versuchen.".to_string()));
data.insert("username".to_string(), to_json(&username));
data.insert("parent".to_string(), to_json(&"base"));
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));
Err(("login".to_owned(), data))
}
}
}
pub fn login_with_code<T: MedalConnection>(
conn: &T, code: &str)
conn: &T, code: &str, (self_url, oauth_providers): (Option<String>, Option<Vec<OauthProvider>>))
-> Result<Result<String, String>, (String, json_val::Map<String, json_val::Value>)> {
match conn.login_with_code(None, &code) {
Ok(session_token) => Ok(Ok(session_token)),
......@@ -448,6 +465,20 @@ pub fn login_with_code<T: MedalConnection>(
let mut data = json_val::Map::new();
data.insert("reason".to_string(), to_json(&"Kein gültiger Code. Bitte erneut versuchen.".to_string()));
data.insert("code".to_string(), to_json(&code));
data.insert("parent".to_string(), to_json(&"base"));
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));
Err(("login".to_owned(), data))
}
},
......
......@@ -450,6 +450,7 @@ fn login<C>(req: &mut Request) -> IronResult<Response>
data.insert("self_url".to_string(), to_json(&self_url));
data.insert("oauth_links".to_string(), to_json(&oauth_links));
data.insert("parent".to_string(), to_json(&"base"));
let mut resp = Response::new();
resp.set_mut(Template::new("login", data)).set_mut(status::Ok);
......@@ -463,9 +464,15 @@ fn login_post<C>(req: &mut Request) -> IronResult<Response>
(iexpect!(formdata.get("username"))[0].to_owned(), iexpect!(formdata.get("password"))[0].to_owned())
};
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())
};
// TODO: Submit current session to login
let loginresult = with_conn![core::login, C, req, logindata];
let loginresult = with_conn![core::login, C, req, logindata, (self_url, oauth_providers)];
match loginresult {
// Login successful
......@@ -489,9 +496,15 @@ fn login_code_post<C>(req: &mut Request) -> IronResult<Response>
iexpect!(formdata.get("code"))[0].to_owned()
};
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())
};
// TODO: Submit current session to login
let loginresult = with_conn![core::login_with_code, C, req, &code];
let loginresult = with_conn![core::login_with_code, C, req, &code, (self_url, oauth_providers)];
match loginresult {
// Login successful
......
......@@ -73,7 +73,7 @@
</div>
</div>
{{/each}}
{{/if}}
{{/if}}
{{/if}}
</div>
</div>
......
../default/login.hbs
\ No newline at end of file
{{#*inline "page"}}
<div class="columns" >
<div class="column">
<h1 class="title is-3">Login</h1>
<p style="margin-bottom:50px;">
{{ reason }}
</p>
</div>
</div>
<!-- - <div class="columns">
<div class="column">
<h2 class="title is-4">Login mit Benutzername und Passwort (nicht PMS-Account)</h2>
</div>
</div>
<form action="/login" method="post" class="columns" style="margin-bottom:50px;">
<div class="column is-one-fifth">
<input class="input" type="text" name="username" autofocus placeholder="Benutzername">
</div>
<div class="column is-one-fifth">
<input class="input" type="password" name="password" placeholder="Passwort">
</div>
<div class="column">
<input class="button is-success" type="submit" value="↪ &nbsp; Login" onclick="login();">
</div>
</form> -->
<div class="columns">
<div class="column">
<h2 class="title is-4">Login mit Gruppencode oder Logincode</h2>
</div>
</div>
<form action="/clogin" method="post" autocomplete="off" class="columns" style="margin-bottom:50px;">
<div class="column is-two-fifths">
<input class="input" type="text" name="code" placeholder="Gruppencode oder Logincode" autofocus>
</div>
<div class="column">
<input class="button is-success" type="submit" value="↪ &nbsp; Login">
</div>
</form>
{{#if self_url}}
{{#each oauth_links}}
<div class="columns">
<div class="column">
<h2 class="title is-4">Login mit PMS-Account</h2>
</div>
</div>
<div class="columns">
<div class="column">
<a class="button is-info" href="{{ this.2 }}{{ ../self_url }}/oauth/{{ this.0 }}">{{ this.1 }}</a>
</div>
</div>
{{/each}}
{{/if}}
{{/inline}}
{{~> (parent)~}}
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