feat: add logger
This commit is contained in:
parent
65b5272281
commit
f1b39b1ea8
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1601,6 +1601,7 @@ dependencies = [
|
||||
"futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"http 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"openssl 0.10.22 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"pretty_env_logger 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"pulldown-cmark 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -30,3 +30,4 @@ time = "0.1.42"
|
||||
rss = "1.7.0"
|
||||
diesel_derives = "1.4.0"
|
||||
openssl = "0.10.22"
|
||||
log = "0.4.6"
|
||||
|
@ -29,6 +29,9 @@ COPY --from=builder /app/rubble/target/x86_64-unknown-linux-musl/release/rubble
|
||||
EXPOSE 8000
|
||||
|
||||
ENV DATABASE_URL postgres://root@postgres/rubble
|
||||
ENV LOG info
|
||||
|
||||
WORKDIR /application
|
||||
|
||||
RUN export RUST_LOG=rubble=$LOG
|
||||
CMD ["./rubble"]
|
@ -5,6 +5,8 @@ extern crate diesel;
|
||||
extern crate diesel_derives;
|
||||
#[macro_use]
|
||||
extern crate diesel_migrations;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
use actix_web::{
|
||||
middleware::{
|
||||
|
@ -68,9 +68,11 @@ pub fn admin_authentication(
|
||||
Ok(login_user) => {
|
||||
if login_user.authenticated(&user.password) {
|
||||
id.remember(login_user.username);
|
||||
info!("admin login");
|
||||
RubbleResponder::Redirect("/admin/panel".into())
|
||||
} else {
|
||||
// TODO flash message or throw unauthorized
|
||||
warn!("try logining admin with wrong password '{}'", user.password);
|
||||
RubbleResponder::Redirect("/admin/login".into())
|
||||
}
|
||||
}
|
||||
@ -138,13 +140,21 @@ pub fn article_save(
|
||||
return RubbleResponder::Redirect("/admin/login".into());
|
||||
}
|
||||
|
||||
let article_title = article.title.clone();
|
||||
|
||||
let admin = User::find_by_username(&data.postgres(), &id.identity().unwrap())
|
||||
.expect("cannot found this user");
|
||||
let res = if let Some(article_id) = article.id {
|
||||
info!("updating article #{} {}", article_id, article_title);
|
||||
Article::update(&data.postgres(), article_id, &article.into_inner().into())
|
||||
} else {
|
||||
info!("creating new article {}", article_title);
|
||||
Article::create(&data.postgres(), &article.into_inner().into())
|
||||
};
|
||||
|
||||
if res.is_err() {
|
||||
error!("error on updating/creating article {}", article_title);
|
||||
}
|
||||
RubbleResponder::Redirect("/admin/panel".into())
|
||||
}
|
||||
|
||||
@ -161,7 +171,9 @@ pub fn article_deletion(
|
||||
let admin = User::find_by_username(&data.postgres(), &id.identity().unwrap())
|
||||
.expect("cannot found this user");
|
||||
|
||||
Article::delete(&data.postgres(), article_id.into_inner());
|
||||
let i = article_id.into_inner();
|
||||
Article::delete(&data.postgres(), i);
|
||||
info!("deleting article {}", i);
|
||||
RubbleResponder::Redirect("/admin/panel".into())
|
||||
}
|
||||
|
||||
@ -180,6 +192,7 @@ pub fn change_password(
|
||||
admin.password = User::password_generate(&password.password).to_string();
|
||||
User::update(&data.postgres(), admin.id, &admin);
|
||||
id.forget();
|
||||
info!("updating password");
|
||||
RubbleResponder::Redirect("/admin/panel".into())
|
||||
}
|
||||
|
||||
@ -197,7 +210,7 @@ pub fn change_setting(
|
||||
.expect("cannot found this user");
|
||||
|
||||
Setting::update(&data.postgres(), setting.name.clone(), &setting);
|
||||
|
||||
info!("updating setting {:?} to {:?}", setting.name, setting.value);
|
||||
RubbleResponder::Redirect("/admin/panel".into())
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user