Commit 908dfdc7 authored by Robert Czechowski's avatar Robert Czechowski

Ask users on OAuth login to fill in their user data (especially grade). Fixes...

Ask users on OAuth login to fill in their user data (especially grade). Fixes #96. Also some formatting
parent 6ca15cc5
......@@ -1279,23 +1279,22 @@ pub fn admin_delete_participation<T: MedalConnection>(conn: &T, user_id: i32, co
pub fn admin_show_contests<T: MedalConnection>(conn: &T, session_token: &str) -> MedalValueResult {
let _session = conn.get_session(&session_token)
.ensure_logged_in()
.ok_or(MedalError::NotLoggedIn)?
.ensure_admin()
.ok_or(MedalError::AccessDenied)?;
.ensure_logged_in()
.ok_or(MedalError::NotLoggedIn)?
.ensure_admin()
.ok_or(MedalError::AccessDenied)?;
let mut data = json_val::Map::new();
// TODO: This returns the contests ordered by 'positionalnumber'
// Should this ordering be changed?
let contests: Vec<_> = conn.get_contest_list().into_iter().map(|contest| (contest.id, contest.name)).collect();
data.insert("contests".to_string(), to_json(&contests));
Ok(("admin_contests".to_string(), data))
}
pub fn admin_contest_export<T: MedalConnection>(conn: &T, contest_id: i32, session_token: &str) -> MedalResult<String> {
conn.get_session(&session_token)
.ensure_logged_in()
......@@ -1307,14 +1306,17 @@ pub fn admin_contest_export<T: MedalConnection>(conn: &T, contest_id: i32, sessi
let taskgroup_ids: Vec<(i32, String)> =
contest.taskgroups.into_iter().map(|tg| (tg.id.unwrap(), tg.name)).collect();
let filename = format!("contest_{}__{}__{}.csv", contest_id, self::time::strftime("%F_%H-%M-%S", &self::time::now()).unwrap(), helpers::make_filename_secret());
let filename = format!("contest_{}__{}__{}.csv",
contest_id,
self::time::strftime("%F_%H-%M-%S", &self::time::now()).unwrap(),
helpers::make_filename_secret());
conn.export_contest_results_to_file(contest_id, &taskgroup_ids, &format!("./export/{}", filename));
Ok(filename)
}
#[derive(PartialEq)]
#[derive(PartialEq, Clone, Copy)]
pub enum UserType {
User,
Teacher,
......
......@@ -19,18 +19,16 @@ use rand::{distributions::Alphanumeric, thread_rng, Rng};
use core::MedalError;
use db_objects::SessionUser;
pub fn make_ambiguous_code(len: usize) -> String {
thread_rng().sample_iter(&Alphanumeric).take(len).collect()
}
pub fn make_ambiguous_code(len: usize) -> String { thread_rng().sample_iter(&Alphanumeric).take(len).collect() }
pub fn make_unambiguous_code(len: usize) -> String {
thread_rng().sample_iter(&Alphanumeric)
.filter(|x| {
let x = *x;
!(x == 'l' || x == 'I' || x == '1' || x == 'O' || x == 'o' || x == '0')
})
.take(len)
.collect()
.filter(|x| {
let x = *x;
!(x == 'l' || x == 'I' || x == '1' || x == 'O' || x == 'o' || x == '0')
})
.take(len)
.collect()
}
pub fn make_unambiguous_code_prefix(len: usize, prefix: &str) -> String {
......@@ -47,13 +45,9 @@ pub fn make_salt() -> String { make_ambiguous_code(10) }
pub fn make_filename_secret() -> String { make_ambiguous_code(10) }
pub fn make_group_code() -> String {
make_unambiguous_code_prefix(6, "g")
}
pub fn make_group_code() -> String { make_unambiguous_code_prefix(6, "g") }
pub fn make_login_code() -> String {
make_unambiguous_code_prefix(8, "u")
}
pub fn make_login_code() -> String { make_unambiguous_code_prefix(8, "u") }
pub fn hash_password(password: &str, salt: &str) -> Result<String, MedalError> {
let password_and_salt = [password, salt].concat();
......
......@@ -230,7 +230,8 @@ fn main() {
if let Some(url) = config.database_url.clone() {
#[cfg(feature = "debug")]
print!("Using database {} … ", &url);
#[cfg(not(feature = "debug"))]{
#[cfg(not(feature = "debug"))]
{
let (begin_middle, end) = url.split_at(url.find('@').unwrap_or(0));
let (begin, _middle) = begin_middle.split_at(begin_middle.rfind(':').unwrap_or(0));
print!("Using database {}:***{} … ", begin, end);
......
......@@ -1125,6 +1125,7 @@ fn oauth<C>(req: &mut Request) -> IronResult<Response>
},
firstname: user_data.firstName,
lastname: user_data.lastName };
let user_type = user_data.foreign_type;
let oauthloginresult = {
// hier ggf. Daten aus dem Request holen
......@@ -1142,7 +1143,16 @@ fn oauth<C>(req: &mut Request) -> IronResult<Response>
// Login successful
Ok(sessionkey) => {
req.session().set(SessionToken { token: sessionkey }).unwrap();
Ok(Response::with((status::Found, Redirect(url_for!(req, "greet")))))
if user_type == UserType::User {
Ok(Response::with((status::Found,
Redirect(iron::Url::parse(&format!("{}?status=firstlogin",
&url_for!(req, "profile"))).unwrap()))))
} else {
Ok(Response::with((status::Found, Redirect(url_for!(req, "greet")))))
}
// TODO: Make Response depend on a) has user logged in before? How long ago
// -> Ask for data if longer than 1 Month ago
}
// Login failed
Err((template, data)) => {
......
......@@ -31,15 +31,15 @@
<p>Benutzername: {{profile_username}}</p>
{{/if}}
{{#if firstlogin }}
<p>
Dieser Logincode erlaubt dir, dich erneut einzuloggen (anstelle eines Benutzernamen und eines Passworts).
Bitte schreibe ihn dir auf!
Wenn du deinen Logincode vergessen hast, kann deine Lehrerin oder dein Lehrer ihn dir sagen.
</p><p>&nbsp;</p>
{{/if}}
{{#if profile_logincode}}
{{#if firstlogin }}
<p>
Dieser Logincode erlaubt dir, dich erneut einzuloggen (anstelle eines Benutzernamen und eines Passworts).
Bitte schreibe ihn dir auf!
Wenn du deinen Logincode vergessen hast, kann deine Lehrerin oder dein Lehrer ihn dir sagen.
</p><p>&nbsp;</p>
{{/if}}
{{#if ownprofile}}
<h4 class="subtitle is-5">Logincode: <strong>{{profile_logincode}}</strong></h4>
......
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