refactor(handlers/render): Use users from database for all functions
Converse now sets the user ID as the session identity parameter in actix_web's identity middleware after a successful login and uses the ID to determine identity when creating threads & posts and when validating edit permissions.
This commit is contained in:
parent
6d69f5001e
commit
40fb4ebbb9
2 changed files with 54 additions and 57 deletions
|
|
@ -87,7 +87,7 @@ impl Handler<IndexPage> for Renderer {
|
|||
|
||||
/// Message used to render a thread.
|
||||
pub struct ThreadPage {
|
||||
pub current_user: Option<String>,
|
||||
pub current_user: i32,
|
||||
pub thread: Thread,
|
||||
pub posts: Vec<SimplePost>,
|
||||
}
|
||||
|
|
@ -122,9 +122,7 @@ fn prepare_thread(comrak: &ComrakOptions, page: ThreadPage) -> RenderableThreadP
|
|||
let user = page.current_user;
|
||||
|
||||
let posts = page.posts.into_iter().map(|post| {
|
||||
let editable = user.clone()
|
||||
.map(|c| post.author_email.eq(&c))
|
||||
.unwrap_or_else(|| false);
|
||||
let editable = user != 1 && post.user_id == user;
|
||||
|
||||
RenderablePost {
|
||||
id: post.id,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue