summaryrefslogtreecommitdiffstats
path: root/src/user/settings.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/user/settings.rs')
-rw-r--r--src/user/settings.rs36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/user/settings.rs b/src/user/settings.rs
new file mode 100644
index 0000000..55e658c
--- /dev/null
+++ b/src/user/settings.rs
@@ -0,0 +1,36 @@
+use actix::{Handler, Message};
+use diesel::MysqlConnection;
+use diesel::{ExpressionMethods, QueryDsl, RunQueryDsl};
+
+use crate::error::ServiceError;
+use crate::model::DbExecutor;
+use crate::schema::passwords::{columns as password_columns, dsl::passwords};
+
+pub struct UpdatePasswordRequest {
+ pub user: u64,
+ pub hash: String,
+}
+
+impl UpdatePasswordRequest {
+ pub fn new(user: u64, hash: String) -> Self {
+ Self { user, hash }
+ }
+}
+
+impl Message for UpdatePasswordRequest {
+ type Result = Result<(), ServiceError>;
+}
+
+impl Handler<UpdatePasswordRequest> for DbExecutor {
+ type Result = Result<(), ServiceError>;
+
+ fn handle(&mut self, req: UpdatePasswordRequest, _: &mut Self::Context) -> Self::Result {
+ let conn: &MysqlConnection = &self.0.get().unwrap();
+
+ diesel::update(passwords.filter(password_columns::id.eq(req.user)))
+ .set(password_columns::hash.eq(req.hash))
+ .execute(conn)?;
+
+ Ok(())
+ }
+}