feat: change setting

This commit is contained in:
Kilerd Chan 2019-04-19 15:27:04 +08:00
parent c7be84d987
commit 23298d586a
3 changed files with 23 additions and 12 deletions

View File

@ -81,7 +81,8 @@ fn main() -> std::io::Result<()> {
.service(routers::admin::article_save) .service(routers::admin::article_save)
.service(routers::admin::article_edit) .service(routers::admin::article_edit)
.service(routers::admin::article_deletion) .service(routers::admin::article_deletion)
.service(routers::admin::change_password), .service(routers::admin::change_password)
.service(routers::admin::change_setting),
) )
.service(routers::rss::rss_page) .service(routers::rss::rss_page)
.service(routers::article::get_article_by_url) .service(routers::article::get_article_by_url)

View File

@ -4,10 +4,10 @@ use diesel::pg::PgConnection;
use diesel::prelude::*; use diesel::prelude::*;
use diesel::result::Error; use diesel::result::Error;
use diesel::{AsChangeset, Insertable, Queryable}; use diesel::{AsChangeset, Insertable, Queryable};
use serde::Serialize; use serde::{Deserialize, Serialize};
use std::collections::HashMap; use std::collections::HashMap;
#[derive(Queryable, Debug, Serialize, Insertable, AsChangeset)] #[derive(Queryable, Debug, Serialize, Deserialize, Insertable, AsChangeset)]
#[table_name = "setting"] #[table_name = "setting"]
pub struct Setting { pub struct Setting {
pub name: String, pub name: String,

View File

@ -225,12 +225,22 @@ pub fn change_password(
id.forget(); id.forget();
RubbleResponder::Redirect("/admin/panel".into()) RubbleResponder::Redirect("/admin/panel".into())
} }
//
//#[post("/setting", data = "<setting_form>")] #[post("/setting")]
//pub fn change_setting(_admin: Admin, conn: DbConn, setting_form: Form<Setting>) -> Flash<Redirect> { pub fn change_setting(
// use crate::schema::{setting}; id: Identity,
// setting: web::Form<Setting>,
// let new_setting = Setting { name: setting_form.name.clone(), value: setting_form.value.clone() }; conn: web::Data<Pool>,
// let _fetched_setting: QueryResult<Setting> = diesel::update(setting::table.find(&setting_form.name)).set(&new_setting).get_result(&*conn); ) -> impl Responder {
// Flash::new(Redirect::to("/admin"), "success", "setting changed") if id.identity().is_none() {
//} return RubbleResponder::Redirect("/admin/login".into());
}
let connection = conn.get().unwrap();
let mut admin = User::find_by_username(&*connection, &id.identity().unwrap())
.expect("cannot found this user");
Setting::update(&connection, setting.name.clone(), &setting);
RubbleResponder::Redirect("/admin/panel".into())
}