Authentication

This commit is contained in:
Bat
2018-04-23 10:52:44 +01:00
parent f8372f6383
commit 5f4cb6c065
6 changed files with 129 additions and 7 deletions
+7 -4
View File
@@ -2,16 +2,19 @@ use rocket::request::Form;
use rocket::response::Redirect;
use rocket_contrib::Template;
use std::collections::HashMap;
use bcrypt::{hash, DEFAULT_COST};
use db_conn::DbConn;
use models::user::*;
use models::instance::Instance;
#[get("/me")]
fn me(user: User) -> String {
format!("Logged in as {}", user.username.to_string())
}
#[get("/@/<name>")]
fn details(name: String) {
fn details(name: String) -> String {
format!("Hello, @{}", name)
}
#[get("/users/new")]
@@ -41,7 +44,7 @@ fn create(conn: DbConn, data: Form<NewUserForm>) -> Redirect {
is_admin: !inst.has_admin(&*conn),
summary: String::from(""),
email: Some(form.email.to_string()),
hashed_password: Some(hash(form.password.as_str(), DEFAULT_COST).unwrap()),
hashed_password: Some(User::hash_pass(form.password.to_string())),
instance_id: inst.id
});
}