54 lines
2.0 KiB
Rust
54 lines
2.0 KiB
Rust
/*
|
|
* 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 anyhow::{bail, Result};
|
|
use log::info;
|
|
|
|
use structs::{account::Account, profile::Profile};
|
|
use yggdrasil::*;
|
|
|
|
use crate::dbtool::Args;
|
|
|
|
pub struct AddProfile {}
|
|
|
|
impl AddProfile {
|
|
pub async fn exec(args: Args, db: &Database) -> Result<()> {
|
|
if args.arguments.len() < 2 { bail!("Not enough arguments. add-profile <email> <name>") }
|
|
|
|
// Get args
|
|
let email = args.arguments.get(0).unwrap().to_lowercase();
|
|
let name = args.arguments.get(1).unwrap().to_string();
|
|
|
|
// Get account
|
|
let Some(account) = Account::from_email(db, email.to_owned()).await else { bail!("Account(email=\"{email}\") doesn't exist") };
|
|
|
|
// Attributes
|
|
let attributes = Input::attributes().await?;
|
|
|
|
info!("Owner ID: {}", account.id);
|
|
|
|
// Create new profile
|
|
let profile = Profile::new(db, account.to_owned(), name, attributes).await?;
|
|
|
|
info!("New profile Name: \"{}\"", profile.name);
|
|
info!("New profile ID: {}", profile.id);
|
|
info!("New profile UUID: {}", profile.uuid);
|
|
|
|
if account.selected_profile.is_none() {
|
|
info!("Setting new profile to be account's selected profile");
|
|
account.set_selected_profile(db, &profile).await?;
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
}
|
|
|