From 7633b869d0ca0772f73c687023e299d7ce7e4b52 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Wed, 1 Aug 2018 13:50:01 +0200 Subject: Make imports explicit. --- src/controllers/login_controller.rs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'src/controllers/login_controller.rs') diff --git a/src/controllers/login_controller.rs b/src/controllers/login_controller.rs index 564deff..090d299 100644 --- a/src/controllers/login_controller.rs +++ b/src/controllers/login_controller.rs @@ -1,8 +1,13 @@ -use rocket; -use rocket::request::Form; -use rocket::response::{Flash, Redirect}; -use models; -use utils; +use rocket::{ + request::{FlashMessage, Form}, + response::{Flash, Redirect}, + Route +}; +use models::User; +use utils::{ + DbConn, + Page +}; #[derive(BartDisplay)] #[template = "templates/login.html"] @@ -11,8 +16,8 @@ pub struct LoginTemplate; implement_responder_for!(LoginTemplate); #[get("/", format="text/html")] -pub fn new(flash: Option) -> utils::Page { - utils::Page { +pub fn new(flash: Option) -> Page { + Page { title: String::from("Log in"), flash: flash, content: LoginTemplate{} @@ -26,9 +31,9 @@ pub struct LoginForm { } #[post("/create", data="")] -pub fn create(login: Form, conn: utils::DbConn) -> Flash { +pub fn create(login: Form, conn: DbConn) -> Flash { let login = login.get(); - if let Ok(user) = models::User::by_email(&login.email, conn) { + if let Ok(user) = User::by_email(&login.email, conn) { if user.password == login.password { return Flash::success(Redirect::to("/"), format!("{} logged in successfully", user.realname.or(Some(user.username)).unwrap())); } @@ -37,6 +42,6 @@ pub fn create(login: Form, conn: utils::DbConn) -> Flash { Flash::error(Redirect::to("/login"), "Invalid email or passoword!") } -pub fn routes() -> Vec { +pub fn routes() -> Vec { routes![new, create] } -- cgit v1.2.3