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

Redirect to profile page on index page (thus also on login) if account is incomplete

parent 8404cbfc
Pipeline #962 failed with stages
in 2 minutes and 44 seconds
......@@ -58,6 +58,7 @@ pub enum MedalError {
PasswordHashingError,
UnmatchedPasswords,
NotFound,
AccountIncomplete,
OauthError(String),
}
......@@ -121,19 +122,23 @@ fn grade_to_string(grade: i32) -> String {
}
pub fn index<T: MedalConnection>(conn: &T, session_token: Option<String>, login_info: LoginInfo)
-> (String, json_val::Map<String, json_val::Value>) {
-> MedalValueResult {
let mut data = json_val::Map::new();
if let Some(token) = session_token {
if let Some(session) = conn.get_session(&token) {
fill_user_data(&session, &mut data);
if session.logincode.is_some() && session.firstname.is_none() {
return Err(MedalError::AccountIncomplete);
}
}
}
fill_oauth_data(login_info, &mut data);
data.insert("parent".to_string(), to_json(&"base"));
("index".to_owned(), data)
Ok(("index".to_owned(), data))
}
pub fn show_login<T: MedalConnection>(conn: &T, session_token: Option<String>, login_info: LoginInfo)
......
......@@ -293,6 +293,11 @@ impl<'c, 'a, 'b> From<AugMedalError<'c, 'a, 'b>> for IronError {
core::MedalError::NotFound => IronError { error: Box::new(SessionError { message:
"Not found".to_string() }),
response: Response::with(status::NotFound) },
core::MedalError::AccountIncomplete => IronError { error: Box::new(SessionError { message:
"Account incomplete".to_string() }),
response: Response::with((status::Found,
Redirect(iron::Url::parse(&format!("{}?status=firstlogin",
&url_for!(req, "profile"))).unwrap()))) },
core::MedalError::OauthError(errstr) => {
IronError { error: Box::new(SessionError { message: format!("Access denied (Error {})", errstr) }),
response: Response::with(status::Unauthorized) }
......@@ -322,7 +327,7 @@ fn greet_personal<C>(req: &mut Request) -> IronResult<Response>
// hier ggf. Daten aus dem Request holen
let config = req.get::<Read<SharedConfiguration>>().unwrap();
let (template, mut data) = with_conn![core::index, C, req, session_token, login_info(&config)];
let (template, mut data) = with_conn![core::index, C, req, session_token, login_info(&config)].aug(req)?;
data.insert("config".to_string(), to_json(&config.template_params));
......
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