feat: add setting modification form in panel
This commit is contained in:
parent
bb57e57f01
commit
64cf647f4a
@ -45,7 +45,8 @@ fn main() {
|
||||
admin::article_edit,
|
||||
admin::save_article,
|
||||
admin::article_creation,
|
||||
admin::change_password
|
||||
admin::change_password,
|
||||
admin::change_setting
|
||||
])
|
||||
.attach(Template::fairing())
|
||||
.launch();
|
||||
|
@ -10,6 +10,7 @@ use request::ArticleEditForm;
|
||||
use chrono::prelude::*;
|
||||
use schema::users;
|
||||
use rocket::request::FlashMessage;
|
||||
use schema::setting;
|
||||
|
||||
#[derive(Queryable, Debug, Serialize, Insertable, AsChangeset)]
|
||||
pub struct Article {
|
||||
@ -103,12 +104,15 @@ impl User {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Queryable, Debug, Serialize)]
|
||||
#[derive_FromForm]
|
||||
#[derive(Queryable, Debug, Serialize, Insertable, AsChangeset)]
|
||||
#[table_name = "setting"]
|
||||
pub struct Setting {
|
||||
pub name: String,
|
||||
pub value: Option<String>,
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct SerializeFlashMessage <'a> {
|
||||
pub name: &'a str,
|
||||
|
@ -20,7 +20,7 @@ use chrono::Utc;
|
||||
use request::NewPasswordForm;
|
||||
use rocket::request::FlashMessage;
|
||||
use models::SerializeFlashMessage;
|
||||
|
||||
use models::Setting;
|
||||
|
||||
#[get("/login")]
|
||||
fn admin_login() -> Template {
|
||||
@ -123,3 +123,12 @@ fn change_password(admin: Admin, conn: DbConn, password_form: Form<NewPasswordFo
|
||||
let _result: QueryResult<User> = diesel::update(users::table.find(admin_user.id)).set(&admin_user).get_result(&*conn);
|
||||
Flash::new(Redirect::moved("/admin"), "success", "password is changed successfully")
|
||||
}
|
||||
|
||||
#[post("/setting", data = "<setting_form>")]
|
||||
fn change_setting(admin: Admin, conn: DbConn, setting_form: Form<Setting>) -> Flash<Redirect> {
|
||||
use schema::{setting, setting::dsl::*};
|
||||
|
||||
let new_setting = Setting { name: setting_form.get().name.clone(), value: setting_form.get().value.clone() };
|
||||
let fetched_setting: QueryResult<Setting> = diesel::update(setting::table.find(&setting_form.get().name)).set(&new_setting).get_result(&*conn);
|
||||
Flash::new(Redirect::to("/admin"), "success", "setting changed")
|
||||
}
|
@ -25,3 +25,12 @@
|
||||
|
||||
<button>change</button>
|
||||
</form>
|
||||
|
||||
<h2>Change setting</h2>
|
||||
|
||||
<form action="/admin/setting" method="post">
|
||||
|
||||
<input type="text" name="name" placeholder="setting name" required>
|
||||
<input type="text" name="value" placeholder="value" required>
|
||||
<button>change</button>
|
||||
</form>
|
Loading…
Reference in New Issue
Block a user