Make it possible to choose an avatar
This commit is contained in:
parent
95ba99a6be
commit
e2e7d10929
@ -491,6 +491,13 @@ impl User {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_avatar(&self, conn: &PgConnection, id: i32) {
|
||||||
|
diesel::update(self)
|
||||||
|
.set(users::avatar_id.eq(id))
|
||||||
|
.execute(conn)
|
||||||
|
.expect("Couldn't update user avatar");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'r> FromRequest<'a, 'r> for User {
|
impl<'a, 'r> FromRequest<'a, 'r> for User {
|
||||||
|
@ -68,6 +68,7 @@ fn main() {
|
|||||||
routes::medias::upload,
|
routes::medias::upload,
|
||||||
routes::medias::details,
|
routes::medias::details,
|
||||||
routes::medias::delete,
|
routes::medias::delete,
|
||||||
|
routes::medias::set_avatar,
|
||||||
routes::medias::static_files,
|
routes::medias::static_files,
|
||||||
|
|
||||||
routes::notifications::paginated_notifications,
|
routes::notifications::paginated_notifications,
|
||||||
|
@ -104,8 +104,14 @@ fn delete(id: i32, _user: User, conn: DbConn) -> Redirect {
|
|||||||
Redirect::to(uri!(list))
|
Redirect::to(uri!(list))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[get("/medias/<id>/avatar")]
|
||||||
|
fn set_avatar(id: i32, user: User, conn: DbConn) -> Redirect {
|
||||||
|
let media = Media::get(&*conn, id).expect("Media to delete not found");
|
||||||
|
user.set_avatar(&*conn, media.id);
|
||||||
|
Redirect::to(uri!(details: id = id))
|
||||||
|
}
|
||||||
|
|
||||||
#[get("/static/media/<file..>", rank = 1)]
|
#[get("/static/media/<file..>", rank = 1)]
|
||||||
fn static_files(file: PathBuf) -> Option<NamedFile> {
|
fn static_files(file: PathBuf) -> Option<NamedFile> {
|
||||||
NamedFile::open(Path::new("media/").join(file)).ok()
|
NamedFile::open(Path::new("media/").join(file)).ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user