Compare commits

..

No commits in common. "c865c09649b45d0438507f6d9a44aa22a5b195dd" and "70998811732ff46fab19b7d34a350224a8b5bc2e" have entirely different histories.

6 changed files with 5 additions and 84 deletions

View File

@ -17,7 +17,6 @@ use yggdrasil::*;
mod dump;
mod search;
mod passwd;
mod add_account;
mod add_profile;
mod del_account;
@ -55,10 +54,6 @@ pub async fn start(db: &Database) -> Result<()> {
"search" => search::Search::exec(args, &db).await?,
"setpasswd" |
"set-passwd" |
"passwd" => passwd::Passwd::exec(args, &db).await?,
"addaccount" |
"add-account" => add_account::AddAccount::exec(args, &db).await?,

View File

@ -1,53 +0,0 @@
/*
* Yggdrasil: Minecraft authentication server
* Copyright (C) 2023 0xf8.dev@proton.me
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use std::str::FromStr;
use anyhow::{bail, Result};
use log::{info, warn};
use yggdrasil::*;
use yggdrasil::structs::account::Account;
use yggdrasil::structs::profile::Profile;
use yggdrasil::structs::token::Token;
use crate::dbtool::Args;
pub struct Passwd {}
impl Passwd {
pub async fn exec(args: Args, db: &Database) -> Result<()> {
if args.arguments.len() < 1 { bail!("Not enough arguments. passwd <account-id>") }
// Get id
let id = i64::from_str(args.arguments.get(0).unwrap())?;
// Get account
let Some(account) = Account::from_id(db, id).await else {
bail!("Account(id = {id}) doesn't exist")
};
// Get password
let password = Input::password().await?;
info!("Password: ...{{{}}}", password.len());
// Change password
account.set_password(db, password).await?;
// Invalidate old tokens
Token::delete_all_from(db, account).await?;
info!("Changed successfully!");
Ok(())
}
}

View File

@ -9,15 +9,3 @@
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
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<Database> {
info!("Loading nest");
let mut nest = tide::with_state(db.to_owned());
nest
}

View File

@ -19,7 +19,6 @@ 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());
@ -54,14 +53,13 @@ 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("/admin/").nest(admin::nest(db.to_owned()));
app.at("/").nest(aliases::nest(db.to_owned()));
// Listen
app.listen(format!("{}:{}", &db.config.address, &db.config.port)).await?;

View File

@ -15,6 +15,9 @@ use tide::{Request, Result};
use yggdrasil::Database;
pub async fn delete_skin(req: Request<Database>) -> 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())
}

View File

@ -75,16 +75,6 @@ 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<Account> {
let password_hash = bcrypt::hash(password, 12)?;