Test for user system and comments
This commit is contained in:
@@ -6,7 +6,7 @@ mod posts;
|
||||
mod subscribers;
|
||||
|
||||
use crate::{
|
||||
authentication::{AuthenticatedUser, Role},
|
||||
authentication::AuthenticatedUser,
|
||||
routes::{AppError, error_chain_fmt},
|
||||
session_state::TypedSession,
|
||||
templates::{HtmlTemplate, MessageTemplate},
|
||||
@@ -81,11 +81,10 @@ pub async fn require_admin(
|
||||
request: Request,
|
||||
next: Next,
|
||||
) -> Result<Response, AppError> {
|
||||
if let Role::Admin = session
|
||||
.get_role()
|
||||
if session
|
||||
.has_admin_permissions()
|
||||
.await
|
||||
.context("Error retrieving user role in session.")?
|
||||
.ok_or(anyhow::anyhow!("Could not find user role in session."))?
|
||||
{
|
||||
Ok(next.run(request).await)
|
||||
} else {
|
||||
|
||||
@@ -62,7 +62,10 @@ impl TryFrom<CreateUserForm> for NewUser {
|
||||
anyhow::bail!("Password mismatch.");
|
||||
}
|
||||
|
||||
let role = value.admin.map(|_| Role::Admin).unwrap_or(Role::Writer);
|
||||
let role = match value.admin {
|
||||
Some(true) => Role::Admin,
|
||||
_ => Role::Writer,
|
||||
};
|
||||
let password_hash = crate::authentication::compute_pasword_hash(value.password)
|
||||
.context("Failed to hash password.")?;
|
||||
Ok(Self {
|
||||
|
||||
Reference in New Issue
Block a user