Commit 333b7ba1 authored by Robert Czechowski's avatar Robert Czechowski
Browse files

Add teacher page and link to teacher page for teachers

parent faa9099d
Pipeline #630 passed with stage
in 10 minutes
...@@ -1030,6 +1030,18 @@ pub fn edit_profile<T: MedalConnection>(conn: &T, session_token: &str, user_id: ...@@ -1030,6 +1030,18 @@ pub fn edit_profile<T: MedalConnection>(conn: &T, session_token: &str, user_id:
Ok(result) Ok(result)
} }
pub fn teacher_infos<T: MedalConnection>(conn: &T, session_token: &str) -> MedalValueResult {
let session = conn.get_session(&session_token).ensure_logged_in().ok_or(MedalError::NotLoggedIn)?;
if !session.is_teacher {
return Err(MedalError::AccessDenied);
}
let mut data = json_val::Map::new();
fill_user_data(&session, &mut data);
Ok(("teacher".to_string(), data))
}
pub fn admin_index<T: MedalConnection>(conn: &T, session_token: &str) -> MedalValueResult { pub fn admin_index<T: MedalConnection>(conn: &T, session_token: &str) -> MedalValueResult {
let session = conn.get_session(&session_token).ensure_logged_in().ok_or(MedalError::NotLoggedIn)?; let session = conn.get_session(&session_token).ensure_logged_in().ok_or(MedalError::NotLoggedIn)?;
if session.id != 1 { if session.id != 1 {
......
...@@ -871,6 +871,17 @@ fn user_post<C>(req: &mut Request) -> IronResult<Response> ...@@ -871,6 +871,17 @@ fn user_post<C>(req: &mut Request) -> IronResult<Response>
//old: Ok(Response::with((status::Found, Redirect(url_for!(req, "user", "userid" => format!("{}",user_id)))))) //old: Ok(Response::with((status::Found, Redirect(url_for!(req, "user", "userid" => format!("{}",user_id))))))
} }
fn teacherinfos<C>(req: &mut Request) -> IronResult<Response>
where C: MedalConnection + std::marker::Send + 'static {
let session_token = req.expect_session_token()?;
let (template, data) = with_conn![core::teacher_infos, C, req, &session_token].aug(req)?;
let mut resp = Response::new();
resp.set_mut(Template::new(&template, data)).set_mut(status::Ok);
Ok(resp)
}
fn admin<C>(req: &mut Request) -> IronResult<Response> fn admin<C>(req: &mut Request) -> IronResult<Response>
where C: MedalConnection + std::marker::Send + 'static { where C: MedalConnection + std::marker::Send + 'static {
let session_token = req.expect_session_token()?; let session_token = req.expect_session_token()?;
...@@ -1200,6 +1211,7 @@ pub fn start_server<C>(conn: C, config: Config) -> iron::error::HttpResult<iron: ...@@ -1200,6 +1211,7 @@ pub fn start_server<C>(conn: C, config: Config) -> iron::error::HttpResult<iron:
user: get "/user/:userid" => user::<C>, user: get "/user/:userid" => user::<C>,
user_post: post "/user/:userid" => user_post::<C>, user_post: post "/user/:userid" => user_post::<C>,
task: get "/task/:taskid" => task::<C>, task: get "/task/:taskid" => task::<C>,
teacher: get "/teacher" => teacherinfos::<C>,
admin: get "/admin" => admin::<C>, admin: get "/admin" => admin::<C>,
admin_users: post "/admin/user/" => admin_users::<C>, admin_users: post "/admin/user/" => admin_users::<C>,
admin_user: get "/admin/user/:userid" => admin_user::<C>, admin_user: get "/admin/user/:userid" => admin_user::<C>,
......
<iframe src="/tasks/teacher/index.html"></iframe>
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
&nbsp; &nbsp;
{{#if logged_in}} {{#if logged_in}}
{{#if firstlogin }}{{else}} {{#if firstlogin }}{{else}}
<div class="columns alogin"> <div class="columns alogin" style="margin-bottom: 0px;">
<div class="column is-three-fifths"> <div class="column is-three-fifths">
Eingeloggt als <em>{{ username }}</em> Eingeloggt als <em>{{ username }}</em>
{{#if firstname}}{{#if lastname}} {{#if firstname}}{{#if lastname}}
...@@ -42,17 +42,18 @@ ...@@ -42,17 +42,18 @@
{{/if}}{{/if}} {{/if}}{{/if}}
{{#if teacher}} {{#if teacher}}
[Lehrer] [Lehrer]
{{/if}} {{/if}}
<br> </div>
<div class="column"><a href="/logout" class="button is-small is-danger" type="submit">&nbsp; Logout</a></div>
</div>
<div class="columns alogin">
<div class="column">
<a href="/profile" class="button is-info is-small">👤 &nbsp; Profil</a> <a href="/profile" class="button is-info is-small">👤 &nbsp; Profil</a>
{{#if teacher}} {{#if teacher}}
<a href="/group/" class="button is-warning is-small">&nbsp; Gruppenverwaltung</a> <a href="/group/" class="button is-warning is-small">&nbsp; Gruppenverwaltung</a>
<a href="/teacher" class="button is-primary is-small">👨‍🏫 &nbsp; Lehrer-Informationen</a>
{{/if}} {{/if}}
</div> </div>
<div class="column"><a href="/logout" class="button is-small is-danger" type="submit">&nbsp; Logout</a></div>
</div>
<div class="columns alogin">
<div class="column"></div>
</div> </div>
{{/if}} {{/if}}
{{else}} {{else}}
......
{{#*inline "page"}}
<div class="columns">
<div class="column is-8 is-offset-2">
<h3 class="title is-4">Lehrer-Informationen</h3>
<iframe src="/tasks/teacher/index.html" style="height: calc(100vh - 550px); min-height:200px;"></iframe>
</div>
</div>
{{/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