From c865c09649b45d0438507f6d9a44aa22a5b195dd Mon Sep 17 00:00:00 2001
From: 0xf8 <0xf8.dev@proton.me>
Date: Wed, 21 Jun 2023 18:08:46 -0400
Subject: [PATCH] early support for web ui
---
src/server/admin/mod.rs | 12 ++++++++++++
src/server/mod.rs | 6 ++++--
src/server/profile/skin.rs | 3 ---
src/util/structs/account.rs | 10 ++++++++++
4 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/src/server/admin/mod.rs b/src/server/admin/mod.rs
index 390834e..adefd5f 100644
--- a/src/server/admin/mod.rs
+++ b/src/server/admin/mod.rs
@@ -9,3 +9,15 @@
* You should have received a copy of the GNU General Public License along with this program. If not, see .
*/
+pub use log::{info, log, warn};
+pub use tide::{Middleware, prelude::*, Request, Response, Result, utils::After};
+
+pub use yggdrasil::*;
+
+pub fn nest(db: Database) -> tide::Server {
+ info!("Loading nest");
+
+ let mut nest = tide::with_state(db.to_owned());
+
+ nest
+}
\ No newline at end of file
diff --git a/src/server/mod.rs b/src/server/mod.rs
index 14b69ff..de1c117 100644
--- a/src/server/mod.rs
+++ b/src/server/mod.rs
@@ -19,6 +19,7 @@ pub mod authlib;
pub mod profile;
pub mod session;
pub mod aliases;
+pub mod admin;
pub async fn start(db: &Database) -> anyhow::Result<()> {
let mut app = tide::with_state(db.to_owned());
@@ -53,13 +54,14 @@ pub async fn start(db: &Database) -> anyhow::Result<()> {
});
// Routes
+ app.at("/").nest(aliases::nest(db.to_owned()));
+
app.at("/auth/").nest(auth::nest(db.to_owned()));
app.at("/session/").nest(session::nest(db.to_owned()));
app.at("/authlib/").nest(authlib::nest(db.to_owned()));
- app.at("/").nest(aliases::nest(db.to_owned()));
-
+ app.at("/admin/").nest(admin::nest(db.to_owned()));
// Listen
app.listen(format!("{}:{}", &db.config.address, &db.config.port)).await?;
diff --git a/src/server/profile/skin.rs b/src/server/profile/skin.rs
index 918153c..ea82c08 100644
--- a/src/server/profile/skin.rs
+++ b/src/server/profile/skin.rs
@@ -15,9 +15,6 @@ use tide::{Request, Result};
use yggdrasil::Database;
pub async fn delete_skin(req: Request) -> Result {
- // let authorization = req.header("authorization");
- // if (authorization.is_none()) { return Err(YggdrasilError::new_base().into()) }
-
Err(tide::Error::new(501, anyhow!("Not implemented yet")).into())
}
diff --git a/src/util/structs/account.rs b/src/util/structs/account.rs
index d231ee0..d798de1 100644
--- a/src/util/structs/account.rs
+++ b/src/util/structs/account.rs
@@ -75,6 +75,16 @@ impl Account {
Ok(())
}
+ pub async fn set_password(&self, db: &Database, password: String) -> Result<()> {
+ let password_hash = bcrypt::hash(password, 12)?;
+
+ sqlx::query!("UPDATE accounts SET password_hash = $1 WHERE id = $2", password_hash, self.id)
+ .execute(&db.pool)
+ .await?;
+
+ Ok(())
+ }
+
pub async fn new(db: &Database, email: String, language: String, country: String, password: String) -> Result {
let password_hash = bcrypt::hash(password, 12)?;