aboutsummaryrefslogtreecommitdiffstats
path: root/src/controllers
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2018-07-31 16:49:42 +0200
committerHarald Eilertsen <haraldei@anduin.net>2018-07-31 16:49:42 +0200
commit7f5e8887e9b1a90d1ed3dd31f053dadec4c75d94 (patch)
tree0a6464a7434a6c43ffb285d300cf9a999fc6d226 /src/controllers
parent6a5f1bd90e46c2bea7be73b512d5202954900cad (diff)
downloadrocket-blog-7f5e8887e9b1a90d1ed3dd31f053dadec4c75d94.tar.gz
rocket-blog-7f5e8887e9b1a90d1ed3dd31f053dadec4c75d94.tar.bz2
rocket-blog-7f5e8887e9b1a90d1ed3dd31f053dadec4c75d94.zip
Add view to list all users
Diffstat (limited to 'src/controllers')
-rw-r--r--src/controllers/users_controller.rs31
1 files changed, 20 insertions, 11 deletions
diff --git a/src/controllers/users_controller.rs b/src/controllers/users_controller.rs
index 9708a1b..9bfb5e1 100644
--- a/src/controllers/users_controller.rs
+++ b/src/controllers/users_controller.rs
@@ -4,23 +4,32 @@ use rocket::response::{Flash, Redirect};
use utils;
#[derive(BartDisplay)]
-#[template = "templates/new_user.html"]
-pub struct NewUserTemplate {
- user: ::models::NewUser
+#[template = "templates/users.html"]
+pub struct UsersTemplate {
+ users: Vec<::models::User>
}
-implement_responder_for!(NewUserTemplate);
+implement_responder_for!(UsersTemplate);
-impl NewUserTemplate {
- pub fn realname(&self) -> String {
- self.user.realname.as_ref().unwrap_or(&String::new()).clone()
+#[get("/", format = "text/html")]
+fn index(conn: utils::DbConn) -> utils::Page<UsersTemplate> {
+ utils::Page {
+ title: String::from("Users"),
+ flash: None,
+ content: UsersTemplate {
+ users: ::models::User::all(conn).unwrap()
+ }
}
+}
- pub fn email(&self) -> String {
- self.user.email.as_ref().unwrap_or(&String::new()).clone()
- }
+#[derive(BartDisplay)]
+#[template = "templates/new_user.html"]
+pub struct NewUserTemplate {
+ user: ::models::NewUser
}
+implement_responder_for!(NewUserTemplate);
+
#[get("/new", format = "text/html")]
fn new() -> utils::Page<NewUserTemplate> {
utils::Page {
@@ -41,5 +50,5 @@ fn create(user: Form<::models::NewUser>, conn: utils::DbConn) -> Flash<Redirect>
}
pub fn routes() -> Vec<rocket::Route> {
- routes![new, create]
+ routes![index, new, create]
}